Upload
michael-gordon
View
1.417
Download
1
Embed Size (px)
DESCRIPTION
Citation preview
CS111 Lab Basics, Output, and Comments
Instructor: Michael Gordon
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; }
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 - ;
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.
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.
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.
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
*/