Professional Documents
Culture Documents
Chapter Summary:
C++ is also a high-level programming language; it is based on the C language but incorporates object-orientated
principles.
Variables are of different data types, including: integer (int), character (char), floating point, Boolean and string.
Assigning a value to a variable is called variable initial- ization or initializing a variable.
Four types of control structures are used in high level programming languages: Selection, Top Down, Invocation,
Repetition.
Java uses methods for the invocation control structure, and C++ uses methods and functions.
Java uses the System.out statement to output data. In C++ the cout statement is used with the << redirect symbols.
The Java Scanner class is used to gather input. In C++, the cin statement is used to gather input.
C++ and Java use the if, if-else, if-else-if and switch statements for selection control structures.
In C++ and Java, the switch statement is used only with scalar variables, such as integers and characters. String
variables cannot be used with the switch statement.
C++ and Java use the for, while and do-while loops for repetition.
To become a good programmer, you must: practice, practice, practice some more.
Code unto others as you would have them code unto you.
Key Terms:
Concatenation (517)
Declaration (513)
Endless Loop (549)
Function (520)
Hungarian Notation (518)
Insertion Point (525)
Nesting (537)
Parameters (521)
Post-conditional Loop (550)
Pre-conditional Loop (548)
Reserved Words (513)
Scope (521)
Variable Initialization (518)
Test Yourself.
1.) Describe when to use integers variables in Java or C++. Explain the situation, provide a suggested
variable name and support your recommendation.
Integer variables are used for +ve and ve whole numbers. Some examples are: Storing inventory
counts, miles driven, points scored in a sporting event and so on. Variable name for these examples
could be: iCount, iMilesDriven, and iPoints. Placing the i in front of the variable name improves
readability of the source code because a person debugging the program can assume that any
variable starting with i contains an integer value. Here is an example of declaring an integer
variable: int iMilesDriven;
2.) Describe when to use floating-point variables in Java or C++. Explain the situation, provide a suggested
variable name and support your recommendation.
3.) Describe when to use character variables in Java or C++. Explain the situation, provide a suggested
variable name and support your recommendation.
4.) Describe when to use string variables in Java or C++. Explain the situation, provide a suggested
variable name and support your recommendation.
5.) Write a Java or C++ program that displays truth tables for the and (&&) logical operator and the or (||)
logical operator. (Refer to Chapter 14 to review logical operators if needed.)
6.) Write a Java or C++ program that uses the: addition, subtraction, multiplication and modulus
mathematical operators. (Refer to Chapter 14 to review logical operators if needed.)
7.) Write a Java or C++ program that displays five names, using the: for, while, and do-while statements.
8.) Write a Java or C++ program that uses an if-else-if statement to determine your final grade in this
course.
9.) Repeat exercise 8 but with a switch statement.
10.) Describe when you would use: do-while, for and while statements.