output Flashcards
1) Syntax
cout «_space;Expression; OR
cout «_space;Expression «_space;Expression … «_space;Expression;
2) Each Expression MUST be preceeded by a “
3) Expression Types:
5 types Identifier name Literal string or char Output manipulator Mathematical Expressions Value-returning functions
Type #1 - Identifier name
(outputs the value of the indentifier)
Example:
int num1 = 25;
cout «_space;num1;
Type #2 - Literal string or char
(outputs the value between the quotes) Example: cout << '%'; cout << "B a L l"; cout << "\n";
Type #3 - Output manipulator
a. endl (end-line) - it causes a carriage return (or use "\n") Example: cout << endl; b. setprecision c. fixed
Type #4 - Mathematical Expressions
Example:
cout «_space;5 + 8;
cout «_space;num1/10;
Type #5 - Value-returning functions
Example:
cout «_space;cos(10.9);
cout «_space;sqrt(32.4);
In order to modify the output you see on the screen,
you MUST change either the type 1, 2, 3, 4, or 5.
Output the following. Make sure the cursor is on
the next line after the output.
1) Good evening class!
//1
cout «_space;“Good evening class!”;
cout «_space;endl;
cout «_space;endl;
Output the following. Make sure the cursor is on
the next line after the output.
2) Your grade was a:
//2 float grade = 100; cout << "Your grade was a: "; cout << grade; cout << endl; cout << endl;
Output the following. Make sure the cursor is on
the next line after the output.
3) + =
//3 int n1 = 0; int n2 = 0; int sum = 0;
//assign values n1 = 45; n2 = 55; sum = n1 + n2;
cout
Output the following. Make sure the cursor is on
the next line after the output.
4) = ( + ) /
//4 float avg = 0; const int TOTAL_NUM_VALUES = 2;
//assign values avg = (n1 + n2) / TOTAL_NUM_VALUES;
cout «_space;avg;
cout