0% found this document useful (0 votes)
76 views3 pages

Write A Program That Produces The Following Output:: Practical 1 (Answers)

The document provides code examples and exercises for a C++ programming practical. It includes programs to: 1) Calculate and output the average of three integer variables 2) Calculate and output the area and perimeter of a rectangle given length and width inputs 3) Prompt a user for a name and study hours then output a message with the input values 4) Prompt a user to enter 5 decimal test scores and calculate the average

Uploaded by

Yew Wen Khang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views3 pages

Write A Program That Produces The Following Output:: Practical 1 (Answers)

The document provides code examples and exercises for a C++ programming practical. It includes programs to: 1) Calculate and output the average of three integer variables 2) Calculate and output the area and perimeter of a rectangle given length and width inputs 3) Prompt a user for a name and study hours then output a message with the input values 4) Prompt a user to enter 5 decimal test scores and calculate the average

Uploaded by

Yew Wen Khang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical 1 (answers)

1. Write a program that produces the following output:

2. Write a program that produces the following output:

3. Compile the program and observe the output.

#include <iostream>
using namespace std;
int main()
{
int num1;
int num2;
int num3;
int average;

num1 = 125;
num2 = 28;
num3 = -25;
average = (num1 + num2 + num3) / 3;

cout << "num1 = " << num1 << endl;


cout << "num2 = " << num2 << endl;
cout << "num3 = " << num3 << endl;
cout << "average = " << average << endl;
system("pause");
return 0;
}

4. Repeat exercise 3 by declaring num1, num2 and num3, and average of type double.
Store 75.35 into num1, -35.56 into num2, and 15.76 into num3.

5. Debug the program.

#include <iostream>;
using namespace std
int main()
{
int length
int width
int area
int perimeter

cout << Enter the length:


cin >> length
cout << endl

cout << Enter the width:


cin >> width
cout << endl

area = length * width


perimeter = 2 * (length + width)

cout << Area = << area << endl


cout << "Perimeter = " << endl
syetem("pause")
return 0
}

6. Compile the program and observe the output.

#include <iostream>
#include <string>
using namespace std;

int main()
{
string name;
double studyHours;

cout << "Enter first name: ";


cin >> name;
cout << endl;

cout << "Enter study hours: ";


cin >> studyHours;
cout << endl;
cout << "Hello, " << name << "! On Saturday, you "
<< "need to study " << studyHours
<< " hours for the exam." << endl;
system("pause");
return 0;
}

7. Write a program that prompts the user to enter five test scores and then prints the
average test scores. (Assume that the test scores are decimal numbers).

You might also like