Previous Page TOC Next Page



- Project 2 -
Analyzing Visual C++ Programs


In this lesson, you learned about the fundamental format of all C++ programs. You saw the following:

Project 2 Listing. Introduction to Visual C++ programs.


1:  // Filename: PROJECT2.CPP

2:  // Introduces the format of Visual C++ programs and demonstrates

3:  // how to write Visual C++ comments, the #include preprocessor

4:  // directive, and the cout command that outputs data to the

5:  // screen.

6:

7:  #include <iostream.h>

8:

9:  void main()

10:  {

11:    cout << "I have a ";

12:    cout << "Sleekster";       // Continues the output line

13:    cout << " automobile.";    

14:    cout << endl << endl;      // Prints 2 blank lines

15:

16:    cout << "I want to sell my car for $4800 (cheap!)." << endl;

17:    cout << "I have had the car for " << 5 << " years." << endl;

18:    cout << "It's really a grade-" << 'A' << " deal!"

19:         << endl << endl;

20:

21:    return;  // End the program

22:  }

Description

1: A Visual C++ comment that includes the program's filename.

2: A comment that begins the introduction of the program's description.

3: The program's description continues.

4: The program's description continues.

5: The program's description continues.

6: Extra blanks make your program more readable.

7: The cout command needs information in the IOSTREAM.H header file.

8: Extra blanks make your program more readable.

9: All functions have names and the first function in all Visual C++ programs is main().

10: All functions begin with a left brace.

11: The screen output begins.

12: The car's model name prints. No new line occurs.

13: Finish the output.

14: Move the cursor down two lines.

15: Extra blanks make your program more readable.

16: Another message prints.

17: cout prints all kinds of data. Strings and an integer output here.

18: This cout outputs strings and a character literal.

19: Statements can be more than one line.

20: Extra blanks make your program more readable.

21: The final return; in main() always returns control back to Visual C++'s QuickWin window

22: A closing brace always terminates the main() function.



7: The compiler inserts a helpful file here.

10: void means that main() does not return a value to the operating system.

14: endl sends a new line command to the screen.


Output