0% found this document useful (0 votes)
4 views9 pages

Formatted Assignment C++ Programs

The document contains a programming assignment with multiple questions that include pseudo code and C++ programs for various tasks such as calculating item prices, employee pay, room area, number parity, circle properties, temperature conversion, and pizza slice calculation. Each question is accompanied by a program that demonstrates the implementation of the pseudo code, along with sample outputs. The assignment aims to reinforce programming fundamentals through practical coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Formatted Assignment C++ Programs

The document contains a programming assignment with multiple questions that include pseudo code and C++ programs for various tasks such as calculating item prices, employee pay, room area, number parity, circle properties, temperature conversion, and pizza slice calculation. Each question is accompanied by a program that demonstrates the implementation of the pseudo code, along with sample outputs. The assignment aims to reinforce programming fundamentals through practical coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Name : Umar Gillani

Roll No : 240531
Course : ADCS

ASSINGMENT 1
Programming Fundamental
Assignment
Question 1:

Pseudo Code:

1. Start
2. Declare variables for item prices (soup, bread, drink)
3. Declare variables to store the number of items bought
4. Calculate the total price for each item by multiplying the price by quantity
5. Calculate the total cost by summing up the prices of all items
6. Display the cost of each item and the total cost
7. End

Program:

#include<iostream>

using namespace std;

int main()

int soup_price, bread_price, drink_price, totalCost;

int hot_soup = 20, cold_drink = 30, Bread = 40;

int soupAmount, drink_Amount, Bread_Amount;

cout<<"Welcome to our store."<<endl;

cout<<"Enter amount of soup you want to have : ";

cin>>soupAmount;

cout<<"Enter amount of drink you want to have : ";

cin>>drink_Amount;

cout<<"Enter amount of bread you want to have : ";


cin>>Bread_Amount;

soup_price = hot_soup*soupAmount;

bread_price = Bread*Bread_Amount;

drink_price = drink_Amount*cold_drink;

totalCost = soup_price + bread_price + drink_price;

cout<<"Soup Price = "<<soup_price<<endl;

cout<<"Bread Price = "<<bread_price<<endl;

cout<<"Drink Price = "<<drink_price<<endl;

cout<<"----------------------------"<<endl;

cout<<"Total Amount = "<<totalCost<<endl;

return 0;

Output:

Welcome to our store.


Enter amount of soup you want to have : 2
Enter amount of drink you want to have : 1
Enter amount of bread you want to have : 3
Soup Price = 40
Bread Price = 120
Drink Price = 30
----------------------------
Total Amount = 190
Question 2:

Pseudo Code:
1. Start
2. Declare variables for employee name, hours worked, and hourly rate
3. Calculate total pay by multiplying hours worked by hourly rate
4. Display the employee's paycheck details
5. End

Program:
#include <iostream>
using namespace std;
int main() {
string employeeName;
int hoursWorked;
float hourlyRate, totalPay;

cout << "Enter employee's name: ";


cin >> employeeName;
cout << "Enter hours worked: ";
cin >> hoursWorked;
cout << "Enter hourly rate: $";
cin >> hourlyRate;

totalPay = hoursWorked * hourlyRate;


cout << "Paycheck for " << employeeName << ": $" << totalPay << endl;
return 0;
}

Output:
Enter employee's name: John
Enter hours worked: 40
Enter hourly rate: $15
Paycheck for John: $600

Question 3:

Pseudo Code:
1. Start
2. Declare variables for length and width
3. Calculate area by multiplying width and length
4. Display the area of the room
5. End

Program:
#include <iostream>
using namespace std;
int main() {
float width, length, area;
cout << "What is the room’s width? ";
cin >> width;
cout << "What is the room’s length? ";
cin >> length;
area = width * length;
cout << "The area of the room is: " << area << " square units" << endl;
return 0;
}

Output:
What is the room’s width? 10
What is the room’s length? 20
The area of the room is: 200 square units

Question 4:

Pseudo Code:

1. Start
2. Declare an integer variable `num`.
3. Ask the user to input an integer.
4. Check if the number is divisible by 2:
- If true, the number is even.
- Else, the number is odd.
5. Display whether the number is even or odd.
6. End

Program:

#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter an integer: ";
cin >> num;

if (num % 2 == 0)
cout << num << " is even." << endl;
else
cout << num << " is odd." << endl;

return 0;
}

Output:

Enter an integer: 5
5 is odd.

Question 5:

Pseudo Code:

1. Start
2. Declare constant `PI = 3.14159` and an integer `radius`.
3. Ask the user to input the radius of the circle.
4. Calculate:
- Diameter = 2 * radius
- Circumference = 2 * PI * radius
- Area = PI * radius * radius
5. Display the diameter, circumference, and area.
6. End

Program:

#include <iostream>
using namespace std;

int main() {
const float PI = 3.14159;
int radius;

cout << "Enter the radius: ";


cin >> radius;

cout << "Diameter: " << 2 * radius << endl;


cout << "Circumference: " << 2 * PI * radius << endl;
cout << "Area: " << PI * radius * radius << endl;

return 0;
}

Output:

Enter the radius: 7


Diameter: 14
Circumference: 43.9823
Area: 153.93791

Question 6:

Pseudo Code:

1. Start
2. Declare variables for Celsius and Fahrenheit temperatures.
3. Ask the user to input the temperature in Celsius.
4. Convert the Celsius temperature to Fahrenheit using the formula:
Fahrenheit = (9 / 5) * Celsius + 32
5. Display the temperature in Fahrenheit.
6. End

Program:

#include <iostream>
using namespace std;

int main() {
float celsius, fahrenheit;
cout << "Enter temperature in Celsius: ";
cin >> celsius;

fahrenheit = (9.0 / 5.0) * celsius + 32;

cout << "Temperature in Fahrenheit: " << fahrenheit << endl;


return 0;
}

Output:

Enter temperature in Celsius: 25


Temperature in Fahrenheit: 77

Question 07:

Pseudo Code:

1. Start
2. Declare constants:
- PI = 3.14159
- SLICE_AREA = 14.125
3. Declare variables for diameter, radius, area, and number of slices.
4. Ask the user to input the diameter of the pizza.
5. Calculate the radius using the formula: radius = diameter / 2
6. Calculate the area using the formula: area = PI * radius * radius
7. Calculate the number of slices: number of slices = area / SLICE_AREA
8. Display the number of slices rounded to one decimal place.
9. End

Program:

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
const float PI = 3.14159;
const float SLICE_AREA = 14.125;
float diameter, radius, area, numSlices;
// Ask the user for the pizza's diameter
cout << "Enter the diameter of the pizza (in inches): ";
cin >> diameter;

// Calculate the radius and area of the pizza


radius = diameter / 2;
area = PI * radius * radius;

// Calculate the number of slices


numSlices = area / SLICE_AREA;

// Display the number of slices with 1 decimal precision


cout << fixed << setprecision(1);
cout << "The number of slices: " << numSlices << endl;

return 0;
}

Output:

Enter the diameter of the pizza (in inches): 16


The number of slices: 14.5

THE END

You might also like