Output
-
Upload
michael-gordon -
Category
Technology
-
view
1.417 -
download
1
description
Transcript of Output
![Page 1: Output](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/1.jpg)
CS111 Lab Basics, Output, and Comments
Instructor: Michael Gordon
![Page 2: Output](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081907/54bee76b4a79598e4b8b46a1/html5/thumbnails/7.jpg)
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
*/