This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Unit 03 Operators, Operations, and Overloading Unit Objectives Understand the generalized concept of an operator in C++ Expand the number of operators we know how to use. Understanding expressions with mixed data types and how to convert data types. Learn how to write a program Incrementally Introduction The fact is that after just two lessons, each of you has the fundamental skills to write some useful - even long - programs. So in this lesson I want to take advantage of your skills and take your abilities up two notches. First I want to discuss some of things we have briefly mentioned previously more formally: operators . We learned a few arithmetic and comparison operators in units 1 and 2. We are going to learn more generally what it means to operate on data and this will lead to the introduction of some new operators and ways to use them. Then we are going to write a more complicated program together incrementally . Incremental Programming is the key to tackling any program bigger than the ones we have already seen, but we will get to that later in the unit. Task 1 - What is an Operator? We have also been using the Assignment Operator (=) without calling it that. All computer languages (that I know of) have an assignment operator. That is reasonable because we always want to assign different values to variables. The statement int iCount = 0; declares the variable named iCount to be an integer and assigns it the value 0. Let's look at other assignment statements. For example, we could have written two statements. int iCount; iCount = 0; We can combine the assignment and arithmetic operators and use them in a single command. First the + creates a new integer by adding iCount and 1. Then the assignment operator assigns the value of the created integer to the variable iTotal. int iCount = 0; int iTotal; iTotal = iCount + 1; To define it formally, an operator is something that performs an operation on one or more data types that results in the creation of another data type . These can then be operated on by other operators either creating new data types or storing the values with a variable. Consider some examples you have already seen. Example Description 3 + 5 The '+' operator adds the two integers and creates an 8. fRadius = 3 + 5 Here the '=' operator sets the value of fRadius to the newly created data value 8....
View Full Document
- Spring '07