Skeletons in Your Closet - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Skeletons in Your Closet

Description:

This is called 'commenting', and the computer ignores this when compiling. ... cout 'Tori Spelling scares me'; cout 'Hello' ' world!' endl; ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 14
Provided by: jeffch8
Category:

less

Transcript and Presenter's Notes

Title: Skeletons in Your Closet


1
Skeletons in Your Closet
2
Overview
  • Documenting Your Programs
  • The Application Skeleton
  • Printing to the screen
  • Getting input from the user
  • Your first C Program
  • Knowing when to compile

3
The Skeleton
  • include ltiostreamgt
  • using namespace std
  • void main ( )
  • // Go ahead and memorize this.
  • // It has to be there!
  • // Note this should go in a .cpp file

4
Documenting Your Programs
  • This is called commenting, and the computer
    ignores this when compiling.
  • Theres 2 ways to do it in C!
  • // This is for a single line comment.
  • / This is for a paragraph of comments
  • and can go on and on. It doesnt matter
  • until you see the /

5
Printing to the Screen
  • Use cout to do this (pronounced see-out)
  • cout can print out just about anything
  • Variables of most data types
  • Multiple things at once
  • Special characters like \n (newline), \a
    (alert), etc..
  • Print multiple things with additional ltlts
  • Print out endl to drop to next line
  • Example
  • cout ltlt Tori Spelling scares me
  • cout ltlt Hello ltlt world! ltlt endl

6
Getting Input from the User
  • Use cin (pronounced see-in)
  • Read into variables (later)
  • Example
  • // Declare a variable
  • int myInt
  • // Load it with information from the keyboard
  • cin gtgt myInt
  • // Print it out
  • cout ltlt myInt is ltlt myInt ltlt endl

7
Your First C Program
  • include ltiostreamgt
  • using namespace std
  • void main ( )
  • cout ltlt Hello World ltlt endl
  • // Note yes, this should be put into a .cpp file

8
Rules about Syntax
  • Where do the s go?
  • Semicolons come after single statements
  • Similar to a period at the end of a sentence
  • Where do the and go?
  • Creates a block of text for multiple single
    statements
  • tells the computer to begin a section
  • tells the computer to end a section
  • Can be nested (or inside of each other)
  • Lets go back to our first c program

9
Your First C Program
include ltiostreamgt using namespace std void
main ( ) cout ltlt Hello World ltlt endl
Begin the main
End the main
End a single statement
10
Compiling Your Program
  • Youll use one of two things
  • The command-line g (on Unix)
  • Your IDE (like Visual C)
  • When you compile, youll have one of two things
    happen
  • It compiles
  • It doesnt
  • If it doesnt compile, you have syntax errors

11
Knowing When to Compile
  • As a rule, the less comfortable you are, the more
    you should compile
  • This isolates the errors
  • As a rule, compile
  • After you type in the skeleton
  • After every 5 or 10 lines of new code
  • Dont become dependent on the compiler!

12
Summary
  • KNOW the skeleton
  • Basis of every program you write
  • Know the s and s
  • Document your programs thoroughly
  • Cin reads from the keyboard
  • Cout prints to the screen
  • Compile often to isolate errors

13
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com