Practical 01 - Simple Program
Practical 01 - Simple Program
3. For the program in question 2 above, what is the purpose of the ‘endl’?
1
5. For the program in question 4 above, can we change the order of the statements as follows and get the same
results?
(a) age = current_year - birth_year; (b) cin >> birth_year;
current_year = 2019; current_year = 2019;
cin >> birth_year; age = current_year - birth_year;
1. Refer to steps 1 to 9 in Practical 00.docx, run the following program and observe the output.
#include <iostream>
using namespace std;
int main(void)
{
cout << "Hello!\nHow are you?\n";
return 0;
}
2. Refer to steps 10 and 11 in Practical 00.docx, run the following program and observe the output.
#include <iostream>
using namespace std;
int main(void)
{
int current_year, birth_year;
current_year = 2019;
birth_year = 2000;
int age;
age = current_year - birth_year;
3. Modify the program in question 2 to ask the user to enter the current year and birth year.
4. Write a program that asks the user to enter three numbers, computes the sum of the three numbers, and displays
the result. The output format should be as follows:
Enter first number: 3
Enter second number: 12
Enter third number: 44
The sum of
3, 12, and 44
is 59.
include iostream ;
int Main() ;
{
cout >> (The program finally runs!\n)
return
}
2
Part C (Self-Review / Revision)
1. What are the different computer programs in IDE used to develop and run a program?
2. What is the name of the function where program execution starts?
3. What is the name of the object to call when your program wants to display results?
4. What is the name of the object to call when your program wants to get input data from the program user?
5. What is the purpose of the line #include <iostream> in a program?
6. What is a variable?
7. What are two ways to store a value in a variable?
1. Write a program that inputs a number (n) and then computes and displays the square (n * n) of the number.
2. Write a program that asks a user to enter two numbers (a and b) and then computes and displays the product
(a * b) of the two numbers.
3. Write a program that calculates the area and perimeter of a rectangle from a user-supplied length and width.
Note: area is l * w and perimeter is 2 * (l + w) where l is the length and w is the width of the rectangle.