
cout << cout << "Hello! PIC10A students."; |
| Hello! PIC10A students. |
cout << "Hello! " << "PIC10A
students. " << "Welcome to UCLA."; |
cout << "Hello! "; |
| Hello! PIC10A students. Welcome to UCLA. |
int appleNum = 5; |
I ate 5 apples this morning. |
appleNum is substituted by its value (5).int speed = 45, time = 2; |
I drove 90 miles. |
speed*time is evaluated. The value is then
printed. cout special characters using "escape
sequences"| Sequence |
Meaning |
|---|---|
\n |
New line |
\t |
tab |
\a |
alert(sounds the alert noise), typically a bell |
\\ |
Backslash (allows you to place a backslash in a
quoted expression) |
\" |
Double quote(mostly used to place a double quote
inside a quoted string) |
\' |
Double quote(mostly used to place a single quote inside single quotes) |
int num1 = 10, num2 = 20; |
| The first number is 10. The second number is 20. |
cout << "Backslash \\ is used in
escape sequences.\n"; |
Backslash \ is used in escape sequences. |
cout<<"\"PIC10A is cool,\" Mary
said.\n"; |
"PIC10A is cool," Mary said. |
endl represnets "end line""\n";cout << "Hello World!\n"; |
cout << "Hello World!" << endl; |
cout<<"1/11 is "<< 1./11.
<< endl; |
| 1/11 is 0.0909091 |
#include<iostream> |
1/11 is 0.09 |
cout.precision(3) in the
program, what is the output?

cin >> variable; or cin >>
variable1>> variable2...;stands for "console input"/* PIC
10A Sample Program |
// your comment |
// and the end of the line is a
comment| /* your comment line 1 your comment line2 your comment line 3 */ |
/* and */ are
commentsdouble x = 3.568902;scientific notation, example double
a = 2.3e-5;(it means 2.3 times 10-5, or 0.000023)char
ch = 'k';different from strings. ("Hello world" is a string,
"A" is a string, because they are enclosed in double quotes)true or falseexample: bool billPaid = false;+,-,*, /. ( ) is first* or /.+ or -int
, type double, or one number of each type.totalWork in below?int workDays = 5;
double hours = 7.5;
????? totalWork
= workDays*hours;
2) What is the return type if a float is added to a double?int a = 7, b = 3;
cout << a/b <<endl;
cout << 8%3 << endl; is 2| shorthand |
meaning |
|---|---|
a+=1; |
a = a+1; |
b-=3.5; |
b = b-3.5; |
c*=2; |
c = c*2; |
d/=3.1415; |
d = d/3.1415; |
e++ ( or ++e) |
e = e+1; |
f-- ( or --f) |
f = f-1; |
x++ and ++x
| Code |
#include<iostream> |
#include<iostream> |
|---|---|---|
| Output |
5 |
6 |
| Reason |
The code means:int b = a; |
The code means:a = a+1; |