Programming in c++ Program Input and the Software Design Process Dale/eems/Headington
1 Program Input and the Software Design Process
Programming in C++ Chapter 4 Topics Input Statements to Read Values for a Program using >> and functions get, ignore, getline s Prompting for Interactive Input/Output Noninteractive Input/Output % Using Data Files for Input and Output s Input Failure Software Design Methodologies s Object-Oriented Design Principles Functional Decomposition Methodology
2 Chapter 4 Topics ❖Input Statements to Read Values for a Program using >>, and functions get, ignore, getline ❖Prompting for Interactive Input/Output ❖Noninteractive Input/Output ❖Using Data Files for Input and Output ❖Input Failure ❖Software Design Methodologies ❖Object-Oriented Design Principles ❖Functional Decomposition Methodology
Programming in C++ No l/o is built into C++ s a library provides input stream and output stream Keyboard executing Screen program istream ostream
3 No I/O is built into C++ ❖ a library provides input stream and output stream Keyboard executing Screen program istream ostream
Programming in C++ Keyboard and Screen I/o include input data output data executing Keyboard Screen program cIn cout (of type istream) (of type ostream)
4 Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data output data
Programming in C++ is header file &The header file iostream contains the definition of two data types: istream and ostream for a library that defines 3 objects an istream object named cin(keyboard an ostream object named cout(screen) an ostream object named cerr(screen)
5 is header file ❖The header file iostream contains the definition of two data types:istream and ostream ❖for a library that defines 3 objects an istream object named cin (keyboard) an ostream object named cout (screen) an ostream object named cerr (screen)
Programming in C++ Giving a Value to a Variable In your program you can assign(give) a value to the variable by using the assignment operator ageOf。g=12; or by another method, such as cout > ageOf。g;
6 Giving a Value to a Variable In your program you can assign (give) a value to the variable by using the assignment operator = ageOfDog = 12; or by another method, such as cout > ageOfDog;
Programming in C++ Extraction Operator(>> so variable cin is predefined to denote an input stream from the standard input device( the keyboard) s the extraction operator > called get from" takes 2 operands. The left operand is a stream expression, such as cin--the right operand is a variable of simple type %operator > attempts to extract the next item from the input stream and store its value in the right operand variable
7 Extraction Operator ( >> ) ❖ variable cin is predefined to denote an input stream from the standard input device ( the keyboard ) ❖ the extraction operator >> called “get from” takes 2 operands. The left operand is a stream expression, such as cin--the right operand is a variable of simple type. ❖ operator >> attempts to extract the next item from the input stream and store its value in the right operand variable
Programming in C++ Extraction Operator >>(cont “ skips over (actually reads but does not store anywhere) leading white space characters as it reads your data from the input stream(either keyboard or disk file)
8 Extraction Operator >>(cont.) “skips over” (actually reads but does not store anywhere) leading white space characters as it reads your data from the input stream (either keyboard or disk file)
Programming in C++ Extraction Operator(cont) > is a binary operator > is called the input or extraction operator > is left associative EXPRESSION HAS VALUE cIn > age cIn STATEMENT cin > age > weight 9
9 Extraction Operator(cont.) >> is a binary operator >> is called the input or extraction operator >> is left associative EXPRESSION HAS VALUE cin >> age cin STATEMENT cin >> age >> weight ;
Programming in C++ Input Statements SYNTAX cin > Variable>> Variable.; These examples yield the same result cin > length cin > width cin > length > width 10
10 SYNTAX These examples yield the same result. cin >> length ; cin >> width ; cin >> length >> width ; Input Statements cin >> Variable >> Variable . . . ;