7
CS111 Lab Basics, Output, and Comments Instructor: Michael Gordon

Output

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Output

CS111 Lab Basics, Output, and Comments

Instructor: Michael Gordon

Page 2: Output

C++ Basics

Every program you write in this class will contain these two first lines:

#include <iostream>

using namespace std;

And each “main” program will begin:

int main(){

And end with:

return 0; }

Page 3: Output

C++ Basics

The body of the main program will be

contained between { and return 0; }.

Code written between these (and any)

brackets should be indented.

Every instruction you give in C++ must end

with a semicolon - ;

Page 4: Output

Input and Output

To output text, numbers, or (later) variable

values, we use: cout<<

Output is said to be displayed to the

Console.

The reverse operation (input) is: cin>>

Input is received from the Console.

We will discuss cin more later.

Page 5: Output

Outputting Text

Any text that you want to output must be

written in quotes: “Hello world.”

Multiple sets of text must include <<

between them.

Ex: cout<<“Hello “<<“Michael!”;

Remember to include spaces!

Use <<endl for a new line character.

Page 6: Output

Comments

Comments are ignored by the compiler. They are meant only for other programmers (or yourself) reviewing your code.

Comments can do the following:

Explain what part of the program does

Provide information on the author

Serve as a note to the programmer while the program is in progress of what is left to do.

Page 7: Output

Comments

Using // will cause the compiler to ignore

the rest of the line.

Ex: //This is my comment

Or comment multiple lines like so:

/*

Comment line 1

Comment line 2

Comment line 3

*/