0% found this document useful (0 votes)
9 views5 pages

Quiz Questions:: Q1 Task: Write A C++ Program To Calculate Area

Programming fundamental codes

Uploaded by

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

Quiz Questions:: Q1 Task: Write A C++ Program To Calculate Area

Programming fundamental codes

Uploaded by

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

Quiz Questions:

Q1 Task: Write a C++ Program to Calculate Area

Create a C++ program that performs the following tasks:

1. Output a Welcome Message: Display the message: "Welcome


to the Area Calculation Program!".
2. Input User Data:
○ Prompt the user to enter the length of a rectangle (as a
float).
○ Prompt the user to enter the width of the rectangle (as a
float).
3. Variables:
○ Declare appropriate variables to store the length, width,
and area of the rectangle.
4. Expressions:
○ Calculate the area of the rectangle using the formula:
Area = Length × Width.
5. Scope:
○ Use a global variable to store the total area calculated
across all user inputs (initialize it to zero).
○ After calculating the area for the current user, add it to the
global total area.
6. Output Results: Display the following:
○ Length
○ Width
○ Area of the rectangle
○ Total area calculated across all users
#include <iostream>
using namespace std;
// Global variable to store total area
float totalArea = 0.0;

int main() {
// Output welcome message
cout << "Welcome to the Area Calculation Program!" <<
endl;

float length, width, area;


// Input user length
cout << "Please enter the length of the rectangle: ";
cin >> length;
// Input user width

cout << "Please enter the width of the rectangle: ";

cin >> width;

// Calculate area

area = length * width;

// Update total area

totalArea += area;
// Output results

cout << "\nYou entered:" << endl;

cout << "Length: " << length << " units" << endl;

cout << "Width: " << width << " units" << endl;

cout << "Area of the rectangle: " << area << " square units"
<< endl;

cout << "Total area calculated: " << totalArea << " square
units" << endl;

return 0;

}
==============================================

Q 2-(if-else-if ladder): Write a program that asks


the user for their exam score and prints:
● "Excellent" if the score is 90 or above.
● "Good" if the score is between 75 and 89.
● "Needs Improvement" if the score is below 75.
#include <iostream>
using namespace std;

int main() {
int score;
cout << "Enter your exam score: ";
cin >> score;

if (score >= 90) {


cout << "Excellent" << endl;
}
else if (score >= 75 && score < 90) {
cout << "Good" << endl;
}
else {
cout << "Needs Improvement" << endl;
}

return 0;
}

You might also like