Download presentation
Presentation is loading. Please wait.
Published byPhilomena Jefferson Modified over 8 years ago
1
1 Structure of Simple C++ Program Chapter 1 09/09/13
2
Announcements Quiz Today Program 1 has been graded. 2
3
Simple C++ Programs Program Structure Standard Output 3
4
PROGRAM STRUCTURE Comments Compiler Directives Using Directive Blocks of Code 4
5
5 #include using namespace std; //Program to print out a box int main(){ cout << " --- \n"; cout << "| |\n"; cout << " --- \n"; return 0; }
6
6 Program structure Comments preprocessor directives using directives Block of code { comments statements }
7
7 Comments §Comments help people read programs, but are ignored by the compiler. §In C++ there are two types of comments. §Line comments begin with // and continue for the rest of the line. §Delimited comments begin with /* and end with */
8
8 Preprocessor Directives §Provide instructions to the compiler that are performed before the program is compiled. §Begin with a # §Example: #include The #include directive instructs the compiler to include statements from the file iostream.
9
using Directive The using directive instructs the compiler to use files defined a specified namespace. Example: using namespace std; std is the name of the Standard C++ namespace. 01/27/129
10
Block of Code A block of code is defined by a set of curly braces {…}. Example: int main(){ cout << " --- \n"; cout << "| |\n"; cout << " --- \n"; return 0; } Every C++ problem solution contains exactly one function named main(). C++ program solutions always begin execution in main () 10
11
cout Statement to Output cout << “Hello”; cout -- object where output is sent << -- insertion operator, sends the output to cout. “Hello” -- string sent to cout ; -- semicolon ends the statement. cout << 15 << endl; Can print numbers endl sends a newline character to output. Use insertion operator, <<, between items sent 11
12
cout Statement to Output cout << “Fire”; cout << “fly”; Cursor left after last output. Output is : Firefly 12
13
return Statement to End return 0; Stops the program. 0 indicates the program executed without error. 13
14
Questions Give an example of a compiler directive. What symbols are used to delimit a block of code? What is this symbol: << ?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.