Programming Assignment 2 Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy