Programming Assignment 2 Answers
Programming Assignment 2 Answers
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;
// 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;
// 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;
}
int main()
{
// Declaration of variables.
double 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;
// 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;
// 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;
// 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;
}