Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPS120: Introduction to Computer Science

Similar presentations


Presentation on theme: "CPS120: Introduction to Computer Science"— Presentation transcript:

1 CPS120: Introduction to Computer Science
What We Know About C++ Lecture 8 - A

2 Characteristics of a C++ Program
Comments Compiler Directives Functions Braces Statements Show MileFunc.cpp

3 A Simple C++ Program Comments //Simple C++ Program //
// Purpose: To demonstrate the // parts of a simple C++ program Compiler Directive #include <iostream.h> Main Function main ( ) Braces { Statements cout << "This is a simple program "; return 0; }

4 Comments Explain the purpose of a program
Keep notes regarding changes to source code Store details about the programmers for future reference Explain parts of the program

5 Sample Comments At the start of the program
/************************************************** ** Miles Per Gallon ** ** Programmer: Paul J. Millis ** ** Purpose: Calculate mile per gallon and price per mile ** ** given miles, gallons and gas price ** *************************************************/ Within specific lines of code float PricePerMile = 0.00; //store the price per mile float MilesPerGallon = 0.0; //stores the miler per gallon achieved

6 Compiler Directives Instructions to the compiler rather than part of the C++ language Most common directive is #include For Example: #include <iostream.h> A .h file is a header file. It serves as a link between program code and standard C++ code needed to make programs run

7 Functions A function is a block of code that carries out a specific task Every C++ program has a main function that executes when a program initiates Includes open parenthesis to designate a function Ends with a return 0; statement

8 Braces Mark the beginning and ending of blocks of related code
Every opening brace must have a closing brace

9 Statements Functions contain statements that consist of instructions or commands that make the program work

10 Semicolons There must be a semicolon after every statement
To tell the compiler that the statement is complete Function definitions and compiler directives are exempt

11 C++ and Blank Space C++ allows for great flexibility in the spacing and layout of code Use this feature to make it easier for you as a human being to read the code

12 Uppercase or Lowercase
Be careful to use the same combination of uppercase or lowercase lettering when you enter source code Commands and other reserved words are all lower case


Download ppt "CPS120: Introduction to Computer Science"

Similar presentations


Ads by Google