Download presentation
Presentation is loading. Please wait.
Published byEsther Jones Modified over 9 years ago
1
Syntax and Semantics, and the Program Development Process ROBERT REAVES
2
More About Output Control vertical spacing by using the endl manipulator in an output statement. What will the following produce? cout << “Hi There, “ << endl; cout << endl; cout << “Lois Lane.” << endl;
3
It is possible to do in one line. cout << “Hi there, “ << endl << endl << “Lois Lane.” << endl; Another: cout << “Hi there, “ << endl << endl << “Lois Lane.” << endl; This is to show we can spread a single C++ statement onto more than one line of the program. semicolon
4
Inserting Blanks Within a Line To control horizontal spacing of output, one technique is to send extra black characters to the output stream. cout << “* * * * * *” << endl; Produces: * * * * * * These are enclosed in double quotes so they print literally as they are written in the program. What about: cout << ‘*’ << ‘*’;
5
Special Characters \” allows for quotes within a string sent to the output stream. \n is a newline character, can use instead of endl. \\ allows for the use of a \ within a string sent to the output stream. What does produce? cout << ‘”’ << “’”; cout << “\”” << ‘\’’;
6
Enter Program Compile Program Compile- time Errors? Run Program Success! Logic errors? Go back to algorithm and fix design. No Yes Figure out errors.
7
Summary Syntax of the C++ language is defined by metalanguage. Identifiers are used in C++ to name things, some are called reserved words. Have predefined meanings in the language. Identifiers are restricted to those not reserved by the C++ language. Identifiers are associated with memory locations by declarations.
8
Summary Declarations may give a name to a location whose value doesn’t change, constant, and whose do change, variable. Every constant and variable has a data type. Common ones: int float char string, from the standard library
9
Summary Program output is accomplished by means of the output stream variable cout, along with the insertion operator (<<). Sends to the standard output device. endl manipulator tells the computer to terminate the current output line and go on to the next. Output should be clear, understandable, and neatly arranged.
10
Summary A C++ program is a collection of one or more function definitions. One of them must be main. Execution always begins with the main function. Functions all cooperate to produce the desired results.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.