Lab Report4
Lab Report4
PROGRAM
#include <iostream>
#include<cmath>
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
float time_to_complete_ground_A;
float time_to_complete_ground_B;
float velocity_for_ground_A;
float velocity_for_ground_B;
float cirumference_ground_A;
float cirumference_ground_B;
cirumference_ground_A=2*3.144*(diameter_groundA/2);
cirumference_ground_B=2*3.144*( diameter_groundB/2);
cout<<"time_to_complete_ground_A:\n ";
cin>>time_to_complete_ground_A;
cout<<"time_to_complete_ground_B:\n";
cin>>time_to_complete_ground_B;
velocity_for_ground_A=cirumference_ground_A/time_to_complete_ground_
A;
velocity_for_ground_B=cirumference_ground_A/time_to_complete_ground_
B;
if(velocity_for_ground_A>velocity_for_ground_B)
else
}
OUTPUT
PROGRAM # 2
Write a program in C++ that asks the user to enter three angles of a triangle. The program displays
whether the triangle is right-angle, acute-angle or obtuse-angle.
PROGRAM
#include <iostream>
int main()
float angle_1,angle_2,angle_3;
cout<<"Angle 1 is ";
cin>>angle_1;
cout<<"Angle 2 is ";
cin>>angle_2;
cout<<"Angle 3 is ";
cin>>angle_3;
if (angle_1+angle_2+angle_3==180)
if (angle_1==90||angle_2==90||angle_3==90)
else if (angle_1>90||angle_2>90||angle_3>90)
cout<<"Triangle is Obtuse";
else
cout<<"Triangle is Acute";
else
cout<<"INVAILD";
return 0;
}
OUTPUT
PROGRAM#3
Write a program in C++ that asks the user to enter date of birth and month of birth. The program should
display the zodiac star.
PROGRAM
#include <iostream>
#include<cmath>
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
cin>>date;
if((date!=0&&date<=31)&&(month!=0&&month<=12))
if((month==12&&date>=22)||(month==1&&date<=20))
else if ((month==1&&date>=21)||(month==2&&date>=19))
else if ((month==2&&date<=20)||(month==3&&date>=20))
else if((month==3&&date>=21)||(month==4&&date>=19))
{
cout<<"You born in ARIES";
else if ((month==4&&date>=20)||(month==5&&date>=20))
else if ((month==5&&date<=21)||(month==6&&date>=21))
else if((month==6&&date<=22)||(month==7&&date>=23))
else if((month==7&&date<=24)||(month==8&&date>=23))
else if((month==8&&date>=24)||(month==9&&date>=22))
{
cout<<"You born in VIRGO";
else if((month==9&&date>=23)||(month==10&&date<=22))
else if((month==11&&date<=23)||(month==12&&date<=20))
else
else
return 0;
}
OUTPUT
PROGRAM # 4
Write a program in C++ that asks the user to enter any character. The program should whether the
entered character is a vowel or a consonant.
PROGRAM
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
char ch;
else
else
return 0;
PROGRAM#5
The “INDUS CAFE” is the
Internet cafe located at
Jamshoro. It provides
Internet services to
clients 24 hours a week.
They charge the Internet
services as given in the
table below. Write down a computer program in C++ for the accountant which asks him to enter the
starting and ending time of the Internet services used by the client and displays the amount that is to be
charged on the client for the service.
PROGRAM
#include <iostream>
#include<cmath>
double amount = 0;
if (durationMinutes < 0)
durationHours--;
durationMinutes += 60;
amount += 20;
if (durationHours > 1)
amount += 15;
if (durationHours > 2) {
amount += (durationHours - 2) * 10;
if (durationMinutes > 0)
amount += 10;
cout << "\nDuration: " << durationHours << " hours " << durationMinutes << " minutes" <<endl;
return 0;
OUTPUT
PROGRAM#6
WAPDA has categorized their customers as domestic and commercial. Each of the customers is charged
electricity according to the table given below: Customer Type Charges for first 150 units Charges for
150+ units Domestic Rs. 5 per unit Rs. 8 per unit Commercial Rs. 8 per unit Rs. 15 per unit Write a
program in C++ that asks for the customer type, the number of units burnt and generates the electric bill
with the total amount in rupees.
PROGRAM
#include <iostream>
string customerType;
int unitsBurnt;
double totalAmount = 0;
if (customerType == "Domestic")
totalAmount = unitsBurnt * 5;
else
else if
(customerType == "Commercial")
totalAmount = unitsBurnt * 8;
else
}
else
return 1;
return 0;
OUTPUT
Program #7
“DINERS” is a well-known garments shop located at Gul Center Hyderabad. They stock different varieties
of Shirts, T-Shirts, Dress Pants, Jeans, Belts and Ties. The rates of each product are shown in table below
along with the discount offers due to Eid.
PROGRAM
#include <iostream>
int main()
int type;
cout << "Enter customer type (1 for Registered, 2 for Normal): ";
double totalAmount = 0;
if (type == 1)
(dressPantPrice * (1 - regDressPantDiscount) *
dressPantQty) +
} else if (type == 2)
(dressPantPrice * (1 - normDressPantDiscount) *
dressPantQty) +
else
return 1;
cout << "The total amount to pay is: Rs. " << totalAmount << endl;
return 0;
}
OUTPUT
PROGRAM#8
Write a program in C++ that asks the user to enter the year and displays whether it is a leap year or not
PROGRAM
#include <iostream>#
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int year;
cin>>year;
if(year%4==0)
return 0;
OUTPUT
PROGRAM #9
Write a program in C++ that prompts the user to input three numbers. The program should then output
the numbers in ascending order.
PROGRAM
#include <iostream>
num1 = num2;
num2 = temp;
num2 = num3;
num3 = temp;
num1 = num2;
num2 = temp;
cout << "\nNumbers in ascending order: " << num1 << ", " << num2 << ", " << num3 << endl;
return 0;
}
OUTPUT
PROGRAM #10
In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths
of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a
triangle and then outputs a message indicating whether the triangle is a right triangle.
PROGRAM
#include <iostream>
#include <cmath>
int main()
double a, b, c;
cin >> a;
cin >> c;
else
return 0;
}
PROGRAM #11
A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program
that prompts the user to enter the total number of cookies, the number of cookies in a box, and the
number of cookie boxes in a container. The program then outputs the number of boxes and the number
of containers to ship the cookies. Note that each box must contain the specified number of cookies, and
each container must contain the specified number of boxes. If the last box of cookies contains less than
the number of specified cookies, you can discard it and output the number of leftover cookies. Similarly,
if the last container contains less than the number of specified boxes, you can discard it and output the
number of leftover boxes.
PROGRAM
#include <iostream>
#include<cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
return 0;
PROGRAM #12
Fahrenheit or Fahrenheit to Celsius. Use the following formulas: 𝐷𝑒𝑔𝑟𝑒𝑒𝑠_𝐶 = 5(𝐷𝑒𝑔𝑟𝑒𝑒𝑠_𝐹 −
Write a program that allows the user to convert a temperature given in degrees from either Celsius to
32)/9 𝐷𝑒𝑔𝑟𝑒𝑒𝑠_𝐹 = (9(𝐷𝑒𝑔𝑟𝑒𝑒𝑠_𝐶)/5) + 32) Prompt the user to enter a temperature and either a
C or c for Celsius or an F or f for Fahrenheit. Convert the temperature to Fahrenheit if Celsius is entered
or to Celsius if Fahrenheit is entered. Display the result in a readable format. If anything, other than C, c,
F, or f is entered, print error message and stop.
PROGRAM
#include <iostream>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
float temp,celuise,farhinet;
char C,F,type;
cin>>temp;
cin>>type;
if(type==C)
farhinet=(9*(temp)/5)+32;
else
celuise=5*(temp-32)/9;
return 0;
}
OUTPUT