0% found this document useful (0 votes)
16 views29 pages

Lab Report4

The document contains a series of C++ programming lab exercises submitted by a student to their instructors. Each program addresses different programming concepts such as calculating velocities, determining triangle types, identifying zodiac signs, and calculating electricity bills. The document includes code snippets and outputs for each program, demonstrating the student's understanding of programming fundamentals.

Uploaded by

sardarmanzarali2
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)
16 views29 pages

Lab Report4

The document contains a series of C++ programming lab exercises submitted by a student to their instructors. Each program addresses different programming concepts such as calculating velocities, determining triangle types, identifying zodiac signs, and calculating electricity bills. The document includes code snippets and outputs for each program, demonstrating the student's understanding of programming fundamentals.

Uploaded by

sardarmanzarali2
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/ 29

Department of Electrical & Computer Engineering

Pak-Austria Fachhochschule: Institute of Applied Sciences and


Technology, Haripur, Pakistan

COMP-111L Programming Fundamentals Lab


Lab Report 0
Submitted by:
Sardar Manzar Ali khan
Reg #B24F0038CE003
Submitted to:
Dr.Saad Qayyum
Engr. Mr . Rafi Uallah
Date:

Nov 10, 2024


PROGRAM#1
There are two circular grounds Ground-A and Ground-B. Ground-A is having diameter of 15 meters and
Ground-B is having diameter of 20 meters. Mohsin is running in Ground-A and Neetesh is running in
Ground-B. Write a program in C++ that asks the user to input the time taken, in seconds, to complete
one compete round of the ground by both the friends and displays who is running faste r.

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 */

int main(int argc, char** argv)

const float diameter_groundA=47.12;

const float diameter_groundB=62.83;

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;

cout<<"velocity of MOHSIN is :\n"<<velocity_for_ground_A<<endl;

velocity_for_ground_B=cirumference_ground_A/time_to_complete_ground_
B;

cout<<"velocity of Neetesh is :\n"<< velocity_for_ground_B<<endl;

if(velocity_for_ground_A>velocity_for_ground_B)

cout<<"MOHSIN ran fast";

else

cout<<"Neetesh ran fast";

}
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>

using namespace std;

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)

cout<<"Triangle is Right Angle";

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>

using namespace std;

/* run this program using the console pauser or add your own getch,
system("pause") or input loop */

int main(int argc, char** argv)

unsigned int date,month;

cout<<"enter month number"<<endl;

cout<<"Please enter month number :\n";


cin>>month;

cout<<"Please enter date:\n";

cin>>date;

if((date!=0&&date<=31)&&(month!=0&&month<=12))

if((month==12&&date>=22)||(month==1&&date<=20))

cout<<"You bron in Capricon\n";

else if ((month==1&&date>=21)||(month==2&&date>=19))

cout<<"You bron in AQUARIUS\n";

else if ((month==2&&date<=20)||(month==3&&date>=20))

cout<<"You born in pisces\n";

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))

cout<<"Your born in TAURUS";

else if ((month==5&&date<=21)||(month==6&&date>=21))

cout<<"Your born in GEMINI";

else if((month==6&&date<=22)||(month==7&&date>=23))

cout<<"You born in CANCER";

else if((month==7&&date<=24)||(month==8&&date>=23))

cout<<"You born in LEO";

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))

cout<<"You born in libra";

else if((month==11&&date<=23)||(month==12&&date<=20))

cout<<"You born in SCORPIO";

else

cout<<"You born in SAGITARIUS";

else

cout<<"Your enter invaild value";

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>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)

char ch;

cout << "Enter any character: ";

cin >> ch;


if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))

if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'a' || ch == 'e' || ch == 'i' || ch ==


'o' || ch == 'u') {

cout << ch << " is a vowel.";

else

cout << ch << " is a consonant.";

else

cout << "Invalid input. Please enter an alphabet.";

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>

using namespace std;

int main(int argc, char** argv) {

int startHour, startMinute, endHour, endMinute;

int durationHours, durationMinutes;

double amount = 0;

cout << "Enter starting time: ";

cin >> startHour >> startMinute;

cout << "Enter ending time : ";

cin >> endHour >> endMinute;

durationHours = endHour - startHour;

durationMinutes = endMinute - startMinute;

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;

cout << "Amount to charge: Rs. " << amount <<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>

using namespace std;

int main(int argc, char** argv)

string customerType;

int unitsBurnt;

double totalAmount = 0;

cout << "Enter customer type (Domestic/Commercial): ";

cin >> customerType;

cout << "Enter number of units burnt: ";

cin >> unitsBurnt;

if (customerType == "Domestic")

if (unitsBurnt <= 150)


{

totalAmount = unitsBurnt * 5;

else

totalAmount = 150 * 5 + (unitsBurnt - 150) * 8;

else if

(customerType == "Commercial")

if (unitsBurnt <= 150)

totalAmount = unitsBurnt * 8;

else

totalAmount = 150 * 8 + (unitsBurnt - 150) * 15;

}
else

cout << "Invalid customer type." <<endl;

return 1;

cout << "\nCustomer Type: " << customerType <<endl;

cout << "Units Burnt: " << unitsBurnt << endl;

cout << "Total Amount: Rs. " << totalAmount <<endl;

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>

using namespace std;

int main()

const double shirtPrice = 1750;

const double tShirtPrice = 1550;

const double dressPantPrice = 2100;

const double jeansPrice = 4500;

const double beltPrice = 2150;

const double tiePrice = 1100;

const double regShirtDiscount = 0.5;

const double regTShirtDiscount = 0.5;

const double regDressPantDiscount = 0.4;

const double regJeansDiscount = 0.3;

const double regBeltDiscount = 0.4;

const double regTieDiscount = 0.4;


const double normShirtDiscount = 0.3;

const double normTShirtDiscount = 0.3;

const double normDressPantDiscount = 0.2;

const double normJeansDiscount = 0.1;

const double normBeltDiscount = 0.2;

const double normTieDiscount = 0.2;

int type;

int shirtQty, tShirtQty, dressPantQty, jeansQty, beltQty, tieQty;

cout << "Enter customer type (1 for Registered, 2 for Normal): ";

cin >> type;

cout << "Enter number of Shirts: ";

cin >> shirtQty;

cout << "Enter number of T-Shirts: ";

cin >> tShirtQty;

cout << "Enter number of Dress Pants: ";

cin >> dressPantQty;

cout << "Enter number of Jeans: ";


cin >> jeansQty;

cout << "Enter number of Belts: ";

cin >> beltQty;

cout << "Enter number of Ties: ";

cin >> tieQty;

double totalAmount = 0;

if (type == 1)

totalAmount = (shirtPrice * (1 - regShirtDiscount) * shirtQty) +

(tShirtPrice * (1 - regTShirtDiscount) * tShirtQty) +

(dressPantPrice * (1 - regDressPantDiscount) *
dressPantQty) +

(jeansPrice * (1 - regJeansDiscount) * jeansQty) +

(beltPrice * (1 - regBeltDiscount) * beltQty) +

(tiePrice * (1 - regTieDiscount) * tieQty);

} else if (type == 2)

totalAmount = (shirtPrice * (1 - normShirtDiscount) * shirtQty) +


(tShirtPrice * (1 - normTShirtDiscount) * tShirtQty) +

(dressPantPrice * (1 - normDressPantDiscount) *
dressPantQty) +

(jeansPrice * (1 - normJeansDiscount) * jeansQty) +

(beltPrice * (1 - normBeltDiscount) * beltQty) +

(tiePrice * (1 - normTieDiscount) * tieQty);

else

cout << "Invalid customer type!" << endl;

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>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)

int year;

cout<<"please enter year :";

cin>>year;

if(year%4==0)

cout<<"you enter leap year";


else

cout<<"not leap year";

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>

using namespace std;

int main(int argc, char** argv)

int num1, num2, num3;

cout << "Enter first number: ";

cin >> num1;

cout << "Enter second number: ";

cin >> num2;


cout << "Enter third number: ";

cin >> num3;

if (num1 > num2)

int temp = num1;

num1 = num2;

num2 = temp;

if (num2 > num3)

int temp = num2;

num2 = num3;

num3 = temp;

if (num1 > num2)

int temp = num1;

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>

using namespace std;

int main()

double a, b, c;

cout << "Enter the length of side a: ";

cin >> a;

cout << "Enter the length of side b: ";


cin >> b;

cout << "Enter the length of side c: ";

cin >> c;

if (pow(a, 2) + pow(b, 2) == pow(c, 2))

cout << "The triangle is a right triangle." << endl;

else if(pow(a, 2) + pow(c, 2) == pow(b, 2))

cout << "The triangle is a right triangle." << endl;

else if (pow(c, 2) + pow(b, 2)== pow(a, 2))

cout << "The triangle is a right triangle." << endl;

else

cout << "The triangle is not a right triangle." << endl;

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>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)

int totalCookies, cookiesPerBox, boxesPerContainer;

cout << "Enter the total number of cookies: ";

cin >> totalCookies;

cout << "Enter the number of cookies per box: ";

cin >> cookiesPerBox;

cout << "Enter the number of boxes per container: ";

cin >> boxesPerContainer;

int totalBoxes = totalCookies / cookiesPerBox;

int leftoverCookies = totalCookies % cookiesPerBox;

int totalContainers = totalBoxes / boxesPerContainer;

int leftoverBoxes = totalBoxes % boxesPerContainer;


cout << "\nNumber of boxes needed: " << totalBoxes <<endl;

cout << "Number of containers needed: " << totalContainers <<endl;

cout << "Leftover cookies: " << leftoverCookies << endl;

cout << "Leftover boxes: " << leftoverBoxes <<endl;

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 */

int main(int argc, char** argv)

float temp,celuise,farhinet;

char C,F,type;

cout<<"please enter temperature:";

cin>>temp;

cout<<"enter C for celesius and F for farhinet";

cin>>type;

if(type==C)

farhinet=(9*(temp)/5)+32;

cout<<temp<<"temperature in celiuse is=degree farhinet=\n"<<farhinet;

else

celuise=5*(temp-32)/9;

cout<<temp<<"temperature in farhinet="<<celuise<<"temperatuer in celiuse";

return 0;

}
OUTPUT

You might also like