Programming Lecture 4
Programming Lecture 4
Programming
Lecture 4
VARIABLES
Dr. Badria Nabil
Assignment 2
2
#include <iostream>
using namespace std;
int main()
{
cout << "the multiplication table of 5 \n";
cout << "5*1= " << 5 * 1 << endl;
cout << "5*2= " << 5 * 2 << endl;
cout << "5*3= " << 5 * 3 << endl;
cout << "5*4= " << 5 * 4 << endl;
cout << "5*5= " << 5 * 5 << endl;
cout << "5*6= " << 5 * 6 << endl;
cout << "5*7= " << 5 * 7 << endl;
cout << "5*8= " << 5 * 8 << endl;
cout << "5*9= " << 5 * 9 << endl;
cout << "5*10= " << 5 * 10 << endl;
return 0;
}
Chaining Stream Insertion Operations
Type
Identifier
Initial value
int myAge;
boolean isAMovie;
float maxItemCost = 17.98F;
Declaring Variables
int itemsRented = 1;
float itemCost;
int i, j, k;
double interestRate;
Variable names
Valid identifier
◼ Series
of characters (letters, digits, underscores)
◼ Cannot begin with digit
20
Good Programming Practice
Place a space after each comma (,) to make programs more
readable.
Use identifiers of 31 characters or fewer to ensure portability.
Choosing meaningful identifiers helps make a program self-
documenting—a person can understand the program simply by
reading it rather than having to refer to manuals or comments.
Avoid identifiers that begin with underscores and double
underscores, because C++ compilers may use names like that
for their own purposes internally.
Always place a blank line between a declaration and
executable statements.
21
Input stream object
Obtain data for program to use - different each time
program executes
std::cin
from <iostream>
Usually connected to keyboard