01 28 11
Download
Skip this Video
Download Presentation
Basic Elements of a C ++ Program

Loading in 2 Seconds...

play fullscreen
1 / 24

Basic Elements of a C ++ Program - PowerPoint PPT Presentation


  • 86 Views
  • Uploaded on

01/28/11. Basic Elements of a C ++ Program. Quiz 1. Monday Chapter 1, Linux and vim On your own p. 24 #1-8, 13, 14, 16 odd answers in text Define Memory address Memory contents Machine language. Objectives. State the basic parts of a C++ program. Create legal C++ names.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Basic Elements of a C ++ Program' - felicia-reilly


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
quiz 1
Quiz 1
  • Monday
  • Chapter 1, Linux and vim
  • On your own
    • p. 24 #1-8, 13, 14, 16
    • odd answers in text
  • Define
    • Memory address
    • Memory contents
    • Machine language
objectives
Objectives
  • State the basic parts of a C++ program.
  • Create legal C++ names.
  • Write statements to output strings.
a sample c program1
A Sample C++ Program

#include <iostream>

  • Preprocessor directive
  • Must have to do input/output
  • cout, cin, <<, >>

using namespace std;

  • Required
  • Used to prevent name conflicts in large projects
travel cpp
travel.cpp

int main()‏

  • Beginning of first function executed
  • Only one main
  • Must be in every program

{ }

  • Brackets delimit executable statements
travel cpp1
travel.cpp

double dist, time, speed;

  • Declare variables
  • Set aside locations in memory
  • Gives the locations names
  • double tells the data\'s type
travel cpp2
travel.cpp

cout<< "Miles traveled?";

cin >>dist; //input

  • cout puts message on monitor
  • cin inputs data and stores it in variable, dist.
  • // begins a comment
travel cpp3
travel.cpp

speed = dist/time; //find speed

  • Assignment Statement
  • speed gets dist/time
  • Does computation, stores answer in "speed"
travel cpp4
travel.cpp

cout << speed << " mph\n";

  • Outputs result to monitor
  • \n is newline character

return 0;

  • Ends program
names
Names
  • Examples:
    • rate, time, distance
    • R2D2, k9, K9, _acceration_gravity
  • Contain letters, digits, underscore
  • Start with letter or underscore
names1
Names
  • Are these legal?

Yr2007, 10_year_average, Y2K, form-99, M_PI

keywords
Keywords
  • Names C++ reserves
  • Cannot as use variable names.
  • E.G. double, return, namespace
  • See appendix F
output1
Output
  • Example -- out.cpp
  • cout
    • Console output
    • Output stream
      • destination for stream of characters
    • Goes to standard output, usually monitor screen
output2
Output
  • <<
    • insertion operator
    • inserts characters in output stream
  • String
    • "September 7th is"
    • inserted into stream
output3
Output

cout << “Fire”; //Leaves cursor after “e”

cout << “fighter”;

Output :

Firefighter

output4
Output

cout << “Fire\n”; //Cursor on new line

cout << “fighter”;

Output :

Fire

fighter

  • \n is an escape sequence
output5
Output
  • Program out1.cpp
  • several \n\'s
output7
Output
  • endl
    • stream manipulator function.
    • Another way to output a newline character.
    • out2.cpp
slide24
Next
  • Algorithms
  • Data Types 2.4
  • Input 2.3
ad