1 / 10

Syntax and Semantics, and the Program Development Process

Syntax and Semantics, and the Program Development Process. Robert reaves. More About Output. Control vertical spacing by using the endl manipulator in an output statement. What will the following produce? c out << “Hi There, “ << endl ; c out << endl ; c out << “Lois Lane.” << endl ;.

mliss
Download Presentation

Syntax and Semantics, and the Program Development Process

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Syntax and Semantics, and the Program Development Process Robert reaves

  2. More About Output • Control vertical spacing by using the endlmanipulator 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? Yes Figure out errors. No Run Program Yes Logic errors? Go back to algorithm and fix design. No Success!

  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. • endlmanipulator 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.

More Related