Docsity

Creating a C++ Program: Preprocessor Directives, Syntax, and Function main, Assignments of Computer Science

Partial preview of the text

Download Creating a C++ Program: Preprocessor Directives, Syntax, and Function main and more Assignments Computer Science in PDF only on Docsity!

CSCI 152

Programming Fundamentals II

Summer 2008

Assignment

Creating a C++ Program

June 5, 2008

Creating a C++ Program

  • C++ program has two parts:
    1. Preprocessor directives
    2. The program
  • Preprocessor directives and

program statements constitute

C++ source code

  • Source code must be saved in a

file with the file extension .cpp

Program Style and Form

 The Program Part

 (^) Every C++ program has a function main  (^) Basic parts of function main are:  (^) The heading  (^) The body of the function 

The heading part has the following

form

Body and Syntax

 (^) The body of the function is enclosed between { and }  (^) Has two types of statements  (^) Declaration statements  Executable statements  (^) Errors in syntax are found in compilation int x; //Line 1 int y //Line 2: syntax error double z; //Line 3 y = w + x; //Line 4: syntax error