0% found this document useful (0 votes)
46 views10 pages

#Include Iostream

The documents contain C++ programs that: 1) Calculate distance traveled in free fall given time in seconds. 2) Calculate volume of a globe given its radius. 3) Calculate new annual and monthly salary after an 11.5% compensation pay increase. 4) Calculate body mass index (BMI) given weight and height.

Uploaded by

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

#Include Iostream

The documents contain C++ programs that: 1) Calculate distance traveled in free fall given time in seconds. 2) Calculate volume of a globe given its radius. 3) Calculate new annual and monthly salary after an 11.5% compensation pay increase. 4) Calculate body mass index (BMI) given weight and height.

Uploaded by

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

1. Develop a C++ program that allows the user to enter a time in seconds.

The output must


show how far an object in freefall for that length of time. There is no friction or resistance
in air. The acceleration of 32 feet / second and this is to be defined as a constant variable.
Equation to be used is distance = 0.5 * acceleration * time2

#include <iostream>
using namespace std;
const float g = 9.8;
int main(){
float distance,time;
cout<<"Time taken by object in free fall : ";
cin>>time;
distance = 0.5*g*time*time;
cout<<"The distance is : "<<distance<< "m";
return 0;
}
Output:

2. Ananya bought a model globe for a project work and that was medium sized. She found the
radius of the globe. But she would like to know the volume of that globe. Can you help her in
finding the Volume of the globe using the formula: (4.0/3.0) * π* r^3, where π = 3.14 is a
constant value.
#include <iostream>
#include <cmath>
using namespace std;
const double pie=3.14;
int main(){
double radii;
cout<<"What is the area of globe you want to give"<<endl;
cin>>radii;
double vol;
vol=(4.0/3.0)*pie*pow(radii,3);
cout<<"Volume of the globe is : "<<vol;
return 0;
}
Output:
3. ABC Corporation decides to give 11.5% for its workers as a compensation pay for a period of
six months. Develop a program to read employee’s previous annual salary. Output the new
annual salary, new monthly salary and old monthly salary. Also specify the exact amount
received as compensation pay. Use a variable declaration with the modifier const to express the
pay increase.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const float comp_pay_rate = 0.115;
float comp_pay, total_comp_pay, pre_aslry, new_aslry;
float pre_mslry, new_mslry;
cout << "Enter old annual salary: - ";
cin >> pre_aslry;
pre_mslry = pre_aslry / 12.0;
comp_pay = comp_pay_rate * pre_aslry;
total_comp_pay = comp_pay / 2.0;
new_aslry = pre_aslry + total_comp_pay;
new_mslry = new_aslry / 12.0;
cout << fixed << setprecision(2);
cout << "New Annual salary: - " << new_aslry << endl;
cout << "New Montly salary: - " << new_mslry << endl;
cout << "Old Monthly salary: - " << pre_mslry << endl;
cout << "Total Compensation pay(6 months): - " << total_comp_pay;
return 0;
}
Output:

4. Ganesh aims to become a police officer and so applies for the job of Inspector. When he
appeared for physical test, he failed in the test due to overweight. Now Ganesh decides to do
intense training to reduce weight. The trainer asks his BMI for deciding the level of training
required. Help him to calculate the BMI using the formula: BMI = weight / height 2
#include<iostream>
#include<cmath>
using namespace std;
int main(){
float weight , height;
cout<<"What is your weight sir (kg)"<<endl;
cin>>weight;
cout<<"what is your height sir (m)"<<endl;
cin>>height;
float bmi;
bmi=weight/(pow(height,2));
cout<<"your bmi is : "<<bmi;

return 0;
}
Output

5. Demonstrates dynamic memory allocation using new to create an array of integers. It assigns
values to the dynamically allocated array, prints them, and deallocates the memory using
delete[].
#include <iostream>
using namespace std;
int main()
{
int *array = new int[5];
for (int i = 0; i < 5; i++)
{
array[i] = i * 2;
}
cout << "Array: ";
for (int i = 0; i < 5; i++)
{
cout << array[i] << " ";
}
cout << endl;
delete[] array;
cout << "Memory deallocated successfully!" << endl;
return 0;
}
Output:
6. A shop will give discount of 10% if the cost of purchased quantity is more than 1000. Ask
user for quantity Suppose, one unit will cost 100. Judge and print total cost for user.
#include <iostream>
using namespace std;
int main(){
int unit;
cout<<"Welcome to the shop.\nHow much units you want to buy: ";
cin>>unit;
float cost;
cost = unit*100;
if (cost>=1000){
cout<<"Your price is : $"<<cost-(cost*10/100)<<" after discount";
}
else{
cout<<"Your price is : $"<<cost;
}
return 0;
Output

7. A school has following rules for grading system:

a. Below 25 – F

b. 25 to 45 – E

c. 45 to 50 – D

d. 50 to 60 - C

e. 60 to 80 - B

f. Above 80 - A

Ask user to enter marks and print the corresponding grade.


include <iostream>
using namespace std;
int main(){
float marks;
cout<<"welcome to grade calculator\nPlease tell your marks\n";
cin>>marks;
switch(static_cast<int>(marks)){
case 0 ... 24:
cout<<"Grade F";
break;
case 25 ... 44:
cout<<"Grade E";
break;
case 45 ... 49:
cout<<"Grade D";
break;
case 50 ... 59:
cout<<"Grade C";
break;
case 60 ... 79:
cout<<"Grade B";
break;
default:
cout<<"Grade A";

}
return 0;
}
Output

8. As activity directory at Ocean Breeze Resort, it is your job to suggest appropriate activities to
guests based on the weather:

temp>= 80: swimming

60 <= temp < 80:tennis

40 <= temp < 60:golf


temp < 40: skiing

#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to the activity adivisior" << endl<< "What is the temprature
outside : ";
float temp;
cin >> temp;
cout << "The activity you can do in this temprature is : ";
if (temp >= 80)
cout
<< "Swimming";
else if (temp < 80 && temp >= 60)
cout
<< "tennis";
else if (temp < 60 && temp >= 40)
cout
<< "golf";
else
cout << "skiing";

return 0;
}
Output:

9. Write the program to determine the raise and new salary for an employee to compute the raise.
The input to the program includes the current annual salary for the employee and a number
indicating the performance rating (1=excellent, 2=good, and 3=poor). An employee with a rating
of 1 will receive a 6% raise, an employee with a rating of 2 will receive a 4% raise, and one with
a rating of 3 will receive a 1.5% raise.

Answer
#include <iostream>
using namespace std;
int main()
{
float salary;
int rating;
cout << "What is the employee salary now : ";
cin >> salary;
cout << "How much you will rate the employee (out of 4): ";
cin >> rating;
float newsalary;
float percent_increment;
switch (rating)
{
case 1:
percent_increment = 6;
newsalary = salary + (salary * percent_increment) / 100;
cout << "The new salary is: ";
cout << newsalary;
break;
case 2:
percent_increment = 4;
newsalary = salary + (salary * percent_increment) / 100;
cout << "The new salary is: ";
cout << newsalary;
break;
case 3:
percent_increment = 1.5;
newsalary = salary + (salary * percent_increment) / 100;
cout << "The new salary is: ";
cout << newsalary;
break;
default:
percent_increment = 0;
newsalary = salary + (salary * percent_increment) / 100;
cout << "Same as previous salary: ";
cout << newsalary;
break;
}

return 0;
}
Output:
10. Write a C++ program that will display if a students is pass or not in his exam. (50% or more
is pass). If the student is Pass than your program should display which letter the student has
obtained.

85% or more E for excellent

75% or more but less than 85% O for Outstanding

65% or more but less than 75% G for good

Less than 65% S for satisfactory

If however the student is Fail (below 50% marks) your program should display 1

whether the student should Resit or Redo depending on the following criteria.

33% or more Resit in exam

Less than 33% Redo course


#include <iostream>
using namespace std;
int main()
{
int percentage_scored;
cout << "What is your percentage : ";
cin >> percentage_scored;
if (percentage_scored <= 50)
{
if (percentage_scored >= 33)
{
cout << "You have to Reapear the exam again";
}
else
{
cout << "You have to repeat the same course again";
}
}
else
{
switch (percentage_scored)
{
case 85 ... 100:
cout << "You are Pass\n";
cout << "E";
break;
case 75 ... 84:
cout << "You are Pass\n";
cout << "O";
break;
case 65 ... 74:
cout << "You are Pass\n";
cout << "G";
break;
default:
cout << "You are Pass\n";
cout << "S";
}
}

return 0;
}
Output

You might also like