Lab2_Slides

advertisement
CS110
Programming 1
Lab
1
CS110
Data Types
Variables Types
 The name of variable can be composed of
letters, digits, and the underscore character.
 It must begin with either a letter or an
underscore
 C++ is case-sensitive
Identifier
Reserved keywords
asm, auto, bool, break, case, catch, char, class, const, const_cast,
continue, default, delete, do, double, dynamic_cast, else, enum,
explicit, export, extern, false, float, for, friend, goto, if, inline, int,
long, mutable, namespace, new, operator, private, protected,
public, register, reinterpret_cast, return, short, signed, sizeof,
static, static_cast, struct, switch, template, this, throw, true, try,
typedef, typeid, typename, union, unsigned, using, virtual, void,
volatile, wchar_t, while
Variables Declaration
A variable is a memory location to store some
value or information.
Variables Declaration
Equal
Variable Initialization
cout object:
cout is used to print message on screen
with the insertion operator <<
cout<< "Hello World"; // prints Hello world on screen
cout<< 250; // prints number 250 on screen
cout<< sum; // prints the content of variable sum on
screen
cin object:
cin can be used to input a value entered
by the user from the keyboard.
int x;
cout << "Enter a number: "; // ask user for a number
cin >> x; // read number from console and store it in
x
cout << "You entered " << x << endl;
Question!
Write a program that ask the
user to enter two integer
numbers and calculate sum of
the two numbers then print it.
Download