160 likes | 303 Views
Objective:. Students will be able to: Create simple C++ programs, compile and run them. Print information from the program. The First Program. #include < iostream > int main (void) { cout << "Hello, world .”; }. Main.
E N D
Objective: Students will be able to: Create simple C++ programs, compile and run them. Print information from the program
The First Program #include <iostream> int main (void) { cout << "Hello, world.”; }
Main • Indicates the place in the program where the program begins executing. • Keyword • Once the program starts, it executes the program line by line in sequence • The program quits afterthe last line • No limit to the number of statements in main
Cout • This line of code is an output statement • Key word • Special object that allows you to send output to the screen • << Operator that you use with cout and a string to output (print out) the string
; • All statements in C++ end in a semi-colon ;
{} • C++ uses squiggly braces to group things. • The cout statement is inside the {} of the main • Indentation of the statement visually shows that it is inside the main
Where and how to compile code? We are going to use http://www. codepad.org Steps: • Write your program in a text editor, name and save it. 2. Go to the codepad web site. 3. Click C++ on left hand side of box. 4. Paste code. 5. Check run code if it is not checked 6. Click the submit button
Assignment 1: • 1. Program and successfully run the Hello World program. • 2. Add another line to the program that prints out How are you? After the Hello World line. • To do: Write out the print out!
Assignment 2: • Between the two cout lines add another line: • cout << end1; • Run the program again • To do: Write out the output!
Answer the following question • What does the cout << endl;; do?
Create a program that prints out: Your name Your address Town, State, zip code
Next assignment: • Create a program that prints out a four word sentence that prints out the code so that one word is on each line. Write out the complete code on the next slide. Example: • The • Program • Is • Cool.
Another way to to write the same program in two lines: cout << “The” << end1; <<“program” << end1; cout << “is” <<end1; <<“cool!” << end1;