Download presentation
Presentation is loading. Please wait.
1
I Know What I Want to Do – Now What??
Ed Brunjes
2
Data Types
3
Strings Class as opposed to a data type
Collections of characters (as opposed to a single value) Has associated member functions (or methods) for special operations Requires the inclusion of the string header file Example #include <string>
4
Identifiers- Variables and Constants
Syntax – Data_type identifier; Examples – C-syntax Camel style Initialization or assignment – Use of assignment operator (=) – read “gets” Example - int counter = 0; Constants – Use of const type modifier Example - const int max_lines = 25; ________________________________
5
Interactive Input Standard Output and Input objects
Insertion and extraction operators << - Insertion operator >> - Extraction operator Use of member functions (methods) .get() Use of getline() Syntax – getline(cin, string_object)
6
Data Conversion – newer syntax
Often it is necessary to convert data from one type to another type – strings to numbers Look for “to” as a part of the utility name Examples – int stoi(string) double stod(string) string to_string(num_val) string val1 = “123”; string val2 = “10”; cout << stod(val1)*stoi(val2);
7
Older Conversion Syntax
With older compilers conversion was a 2-step process because of the use of standard C utilities – 1. Convert the string into a character array 2. Convert the character array into its number equivalent Example: string val1 = “123”; string val2 = “10”; cout << atof(val1.data()) * atoi(val2.data());
8
How to Make a Boolean Value
Boolean values – no input or output; initialization - they can only be used There are only two values and both require the use of “Boolean operators” to create Relational operators Logical operators (sometimes called logical connectors) The expression is termed an assertion 4. Example: “four is greater than 5”. True of False??
9
Use of Booleans Initialization – Boolean expression –
bool flag = FALSE; int val = 10; Boolean expression – flag = val == 10; flag = val < 10; Use of Boolean values – if(val < 10) cout << “val is less than 10” << endl; else cout << “val is not less than 10” << endl;
10
Multiple (nested) Decisions
Decision within a decision occurs if an outcome is based on the value of two or more variables. Diagram looks something like – if(condition1) if(condition2) statement1; else statement2; statement3; statement4;
11
Arithmetic Operators
12
Accumulators vs. Counters
Counters add the same value each execution Example ctr = ctr +1; Accumulators can add different values each execution Example- total = total + number;
13
Incrementors and Decrementors
Post-fixed operators - Prefixed operators -
14
Manipulating (formatting) input and output
Use of iomanip #include <iomanip> Includes definitions for – setprecision(), setw(), fixed Example – cout << setw(35) << "Expected Pay for the Period: " << fixed << setprecision(2) << tot_pay << endl;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.