0% found this document useful (0 votes)
10 views

Programming Assignment 2 Answers

The document contains 6 programming assignments in C++ that involve taking user input to determine various outputs. The assignments include programs to check if a number is even or odd, calculate a grade based on a subject mark, determine the state of water based on temperature, check humidity levels, check body temperature and fever levels, and calculate a speeding fine based on car speed. All programs use if/else statements to evaluate the user input and output the corresponding results.

Uploaded by

bodyadel9999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Programming Assignment 2 Answers

The document contains 6 programming assignments in C++ that involve taking user input to determine various outputs. The assignments include programs to check if a number is even or odd, calculate a grade based on a subject mark, determine the state of water based on temperature, check humidity levels, check body temperature and fever levels, and calculate a speeding fine based on car speed. All programs use if/else statements to evaluate the user input and output the corresponding results.

Uploaded by

bodyadel9999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Programming Assignment 2 Answers

1) Write a C++ Program that checks if the entered number is even or odd.
#include <iostream>
using namespace std;

int main()
{
// Declaration of variables.
int Number;

// Giving message to the user to enter the values.


cout << "Please enter an integer and I will tell you if it is odd or even. \n";

// The user enters an integer number.


cout << "Enter an integer number. \n";
cin >> Number;

// Checking the condition of the entered value and printing out the results.
if (Number % 2 == 0)
cout << Number << " is even." << "\n";
else
cout << Number << " is odd." << "\n";

return 0;
}
2) Write a C++ Program that Calculates Subjects Grades.
The Grades are given as follows:
95 -> 100 A+
90 -> 94 A
85 -> 89 B+
80 -> 84 B
73 -> 79 C+
65 -> 72 C
58 -> 64 D+
50 -> 57 D
Less than 50 F
#include <iostream>
using namespace std;
int main()
{
// Declaration of variables.
double Mark;

// Giving message to the user to enter the values.


cout << "Please Enter the Mark of the Subject to Calculate the Grade: ";

// The user enters the mark.


cin >> Mark;

// Checking the condition of the entered value and printing out the results.
if (Mark >= 95)
{ cout << " A+ " << "\n";}
else if (Mark >= 90)
{ cout << " A " << "\n"; }
else if (Mark >= 85)
{ cout << " B+ " << "\n";}
else if (Mark >= 80)
{ cout << " B " << "\n"; }
else if (Mark >= 73)
{ cout << " C+ " << "\n";}
else if (Mark >= 65)
{ cout << " C " << "\n"; }
else if (Mark >= 58)
{ cout << " D+ " << "\n";}
else if (Mark >= 50)
{ cout << " D " << "\n"; }
else { cout << " F " << "\n" << "Please Study This Course Again" << "\n"; }

return 0;
}

3) Write a C++ Program to check the state of water.


The states of water are given as follows:
The Temperature less than or equal zero -> Solid.
The Temperature less than or equal 100 -> Liquid.
The Temperature more than 100 -> Gas.
#include <iostream>
using namespace std;

int main()
{
// Declaration of variables.
double Temperature;

// Giving message to the user to enter the values.


cout << "Please Enter the Temperature of Water: ";

// The user enters the temperature.


cin >> Temperature;

// Checking the condition of the entered value and printing out the results.
if (Temperature <= 0)
{ cout << "Water became (Solid)" << "\n"; }
else if (Temperature <= 100)
{ cout << "Water became (Liquid)" << "\n";}
else { cout << "Water became (Gas)" << "\n"; }

return 0;
}
4) Write a C++ Program to determine the State of Humidity according to the user input
0% ---> 39% Too Dry
40% ---> 60% Optimum
61% --->100% Too Moist
Humidity > 100% Water Evaporates
#include <iostream>
using namespace std;

int main()
{
// Declaration of variables.
double Humidity;

// Giving message to the user to enter the values.


cout << "Please Enter the Percentage of Humidity: ";

// The user enters the percentage of humidity.


cin >> Humidity;

// Checking the condition of the entered value and printing out the results.
if (Humidity <= 39)
{ cout << "Too Dry" << "\n"; }
else if (Humidity <= 60)
{ cout << "Optimum" << "\n"; }
else if (Humidity <= 100)
{ cout << "Too Moist" << "\n"; }
else { cout << "Water Evaporates" << "\n"; }

return 0;
}
5) Write a C++ Program that determines State of Human Body Temperature according to the user input.
36⁰ ---> 37.2⁰ Normal Temperature.
37.3⁰ ---> 38.3⁰ Low Grade Fever.
38.4⁰ ---> 39.7⁰ Common Fever.
Temperature > 39.7⁰ High Fever.
#include <iostream>
using namespace std;

int main()
{
// Declaration of variables.
double Temperature;

// Giving message to the user to enter the values.


cout << "Please Enter the Human Body Temperature: ";

// The user enters the temperature.


cin >> Temperature;

// Checking the condition of the entered value and printing out the results.
if (Temperature <= 37.2)
{ cout << "Normal Temperature" << "\n"; }
else if (Temperature <= 38.3)
{ cout << "Low Grade Fever" << "\n"; }
else if (Temperature <= 39.7)
{ cout << "Common Fever" << "\n"; }
else { cout << "High Fever" << "\n"; }

return 0;
}
6) Write a C++ Program that determines the amount of money to be paid if the driver exceeds the allowed car
speed.
100 km/h ---> 109 km/h (0 EGP).
110 Km/h ---> 130 Km/h (200 EGP).
131 Km/h ---> 150 Km/h (400 EGP).
151 Km/h ---> 170 Km/h (600 EGP).
More than 170 Km/h (1000 EGP).
#include <iostream>
using namespace std;

int main()
{
// Declaration of variables.
double Speed;

// Giving message to the user to enter the values.


cout << "Please Enter the car speed: ";

// The user enters the speed.


cin >> Speed;

// Checking the condition of the entered value and printing out the results.
if (Speed <= 109)
{ cout << "0 EGP" << "\n"; }
else if (Speed <= 130)
{ cout << "200 EGP" << "\n"; }
else if (Speed <= 150)
{ cout << "400 EGP" << "\n"; }
else if (Speed <= 170)
{ cout << "600 EGP" << "\n"; }
else { cout << "1000" << "\n"; }

return 0;
}

You might also like