Assignment Operator ( ) : EECE 1313 - LAB 3 17 OCTOBER 2016 Name: Matric No.
Assignment Operator ( ) : EECE 1313 - LAB 3 17 OCTOBER 2016 Name: Matric No.
17 OCTOBER 2016
NAME:
MATRIC NO.:
Once you have variables declared, you will do operations. An expression is the sequence of
operands and operators to reduce in to one value. C++ provides you a lot of operators as
shown below.
Sign Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Division of modulus
1. Write a C++ program to produce the output as shown below:
after
5 | x++ | 5 | 6
5 | x-- | 5 | 4
5 | ++x | 6 | 6
5 | --x | 4 | 4
In C++, there are two conditional statements for making decisions. The two conditional
statements are if else and switch case.
if/else statement
If statement will evaluate the condition. If it is true, it will execute the statements that follow
it, otherwise, it will execute the statements in else block.
if statement without else:
if (condition) {
Statement
Statement
}
or
if statement with else:
if (condition) {
Statement
Statement
}
else {
Statement
Statement
}
2. Write a C++ program that prompts the user to input three integer values and find the
greatest value of the three values.
Put simply, loop enables your program to execute the block of code repeatedly. In C++, there
are for, while, and do while loops that are discussed below.
For loop
The code in for loop will be executed from the start value until the condition is met. The
increment will be added continuously to the start value until the condition is met. Example:
int i;
for (i = 1; i <=10; i++)
count<<"\C++ programming"; //The words C++ programming will
While Loop
The while loop executes code repeatedly if the condition is still true.
while(condition){
statement
statement
---------
Example:
int i = 1;
while (i <= 10)
{
cout << "\nC++";
i = i + 1;
}
*******
******
*****
****
***
**
*
*PLEASE SUBMIT YOUR WORK AT THE END OF THE LAB SESSION