#Include Iostream
#Include Iostream
#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
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
}
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:
#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.
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.
return 0;
}
Output