Вы находитесь на странице: 1из 10

Tarlac State University

COLLEGE OF ENGINEERING
Tarlac City







Compilation of Exercises in COMP 533
(ECE Computer Applications)







Submitted by
Bildan, Elton Jay G.
Gomez, Ralph Michael N.
Lorenzo, Jayson A.
Somera, Renante T.







Submitted to
Engr. Idris Jeffrey M. Manguera







July 2014
COMP 533/531L Exercises

1. A-1 Appliances needs a program that allows the store clerks to enter the number of dishwashers in stock
at the beginning of the month, the number purchased during the month, and the number sold during the
month. The program should calculate and display the number of dishwashers in stock at the end of the
month.
a. Create an IPO chart for the problem, and then desk-check the algorithm twice. For the first desk-
check, use 5000 as the number of dishwashers at the beginning of the month, 1000 as the number
purchased, and 3500 as the number sold. For the second desk-check, use 450, 20, and 125.
b. List the input, processing, and output items, as well as the algorithm, in a chart. Then code the
algorithm into a program.
c. Desk-check the program using the same data used to desk-check the algorithm.
d. Enter your C++ instructions into a source file named Introductory1.cpp. Also enter appropriate
comments and any additional instructions required by the compiler.
e. Save and run the program. Test the program using the same data used to desk-check the program.

IPO Chart
Input Processing Output
number of dishwashers
at the beginning of the
month
number of dishwashers
purchased during the
month
number of dishwashers
sold during the month
Processing Item:
total number of dishwashers during the
month

Algorithm:
1. Enter the number of dishwashers in
stock at the beginning of the month,
the number purchased during the
month, and the number sold during the
month.
2. Calculate the new number of
dishwashers in stock during the month
by adding the number of dishwashers
in stock at the beginning of the month
to the number purchased during the
month.
3. Calculate the number of dishwashers
in stock at the end of the month by
subtracting the number sold during the
month by the no. of dishwashers in
stock during the month.
4. Display the no. of dishwashers in
stock at the end of the month.

Number of dishwashers
in stock at the end of the
month.




C++ CODES:

// Introductory1.cpp - calculates and display the number of dishwashers in stock at the end of the month
// created by Totoy Brownies (Aba Matinde!) on July 9, 2014

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
// declare variables
int dishwashersBeginning = 0;
int purchasedDuring = 0;
int soldDuring = 0;
int newStock = 0;
int dishwashersEnd = 0;

// enter input items
cout<< "Enter number of dishwashers in stock at the beginning of the month: ";
cin>> dishwashersBeginning;
cout<< "Enter number of dishwashers purchased during the month: ";
cin>> purchasedDuring;
cout<< "Enter number of dishwashers sold during the month: ";
cin>> soldDuring;

// calculate the new stock and the number of dishwashers at the end of the month
newStock = dishwashersBeginning + purchasedDuring;
dishwashersEnd = newStock - soldDuring;

// display output item
cout<< "Stock at the end of the month: " << dishwashersEnd << endl;

return 0;

} // end of main function


DESK-CHECK
Number of
dishwashers at the
beginning of the
month
Number of
dishwashers
purchased
Number of
dishwashers sold
Total number of
dishwashers
during the month
Number of
dishwashers
5000 1000 3500 6000 2500
450 20 125 470 345



2. A concert hall has three seating categories: Orchestra, Main Floor, and the Balcony. Orchestra seats are
$25. Main Floor seats are $30, and Balcony seats are $15. The manager wants a program that allows him
to enter the number of tickets sold in each seating category. The program should calculate and display
the amount of revenue generated by each seating category, as well as the total revenue.
a. Create an IPO chart for the problem, and then desk-check the algorithm twice. For the first desk-
check, use 50, 100, and 75 as the number of Orchestra, Main Floor and Balcony seats. For the
second desk-check, use 30, 25, and 99.
b. List the input, processing, and output items, as well as the algorithm, in a chart. Then code the
algorithm into a program.
c. Desk-check the program using the same data to desk-check the algorithm.
d. Enter your C++ instructions into a source file named Introductory2.cpp. Also enter appropriate
comments and any additional instructions required by the compiler.
e. Save and run the program. Test the program using the same data used to desk-check the program.

IPO Chart
Input Processing Output
Orchestra seats
price
Main Floor seats
price
Balcony seats price
Number of
Orchestra seats
ticket sold
Number Main Floor
seats ticket sold
Number of Balcony
seats ticket sold
Processing Item: none

Algorithm:
1. Enter the number of Orchestra seats,
Main Floor seats, and Balcony seats.
2. Calculate the amount of revenue
generated by each category by
multiplying their price to the number
of tickets sold in each category.
3. Calculate the total revenue by adding
the amount of revenue in each seating
category.
4. Display the amount of revenue
generated by each seating categories
and the total revenue.
Amount of revenue
generated by each seating
category.
Total revenue.


C++ CODES:
// Introductory2.cpp - calculates and display the amount of revenue generated by each seating category as well
as total revenue
// created by Totoy Brownies (Aba Matinde!) on July 9, 2014

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
// declare variables
int orchestra = 0;
int mainFloor = 0;
int balcony = 0;
const int orchestraPrice = 25;
const int mainFloorPrice = 30;
const int balconyPrice = 15;
int revenueGenerated = 0;
int totalRevenue = 0;
double orchestraPriceRevenue = 0.0;
double mainFloorPriceRevenue = 0.0;
double balconyPriceRevenue = 0.0;

// enter input items
cout<< "Enter number of orchestra seats: ";
cin>> orchestra;
cout<< "Enter number of main floor: ";
cin>> mainFloor;
cout<< "Enter number of balcony: ";
cin>> balcony;

// calculate the revenue generated by each seating category and the total revenue
orchestraPriceRevenue = orchestra * orchestraPrice;
mainFloorPriceRevenue = mainFloor * mainFloorPrice;
balconyPriceRevenue = balcony * balconyPrice;
totalRevenue = orchestraPriceRevenue + mainFloorPriceRevenue + balconyPriceRevenue;

// display output item
cout<< "Orchestra Revenue Generated: " << orchestraPriceRevenue << endl;
cout<< "Main Floor Revenue Generated: " << mainFloorPriceRevenue << endl;
cout<< "Balcony Revenue Generated: " << balconyPriceRevenue << endl;
cout<< "Total Revenue: " << totalRevenue << endl;

return 0;

} // end of main function


DESK-CHECK
no. of sold
tickets for
Orchestra
seats
no. of sold
tickets for
Main Floor
seats
no. of sold
tickets for
Balcony
seats
amount of
revenue
Orchestra
seats
amount of
revenue
Main Floor
seats
amount of
revenue
Balcony
seats
total amount
of revenue
50 100 75 $1250 $3000 $1125 $5375
30 25 99 $750 $750 $1485 $2985
3. The manager of Mama Calaris Pizza Place wants a program that calculates and displays the number of
slices of pizza into which a circular pizza can be divided. The manager will enter the radius of the entire
pizza. For this exercise, use the number 14.13 as the area of pizza slice, and use 3.14 as the value of pi.
a. Create an IPO chart for the problem, and then desk-check the algorithm twice. For the first desk-
check, use 10 as the radius of the pizza. For the second desk-check, use 6. (Hint: For the first desk-
check, the number of slices should be a little over 22.)
b. List the input, processing, and output items, as well as the algorithm, in a chart. Then code the
algorithm into a program.
c. Desk-check the program using the same data to desk-check the algorithm.
d. Enter your C++ instructions into a source file named Intermediate1.cpp. Also enter appropriate
comments and any additional instructions required by the compiler.
e. Save and run the program. Test the program using the same data used to desk-check the program.

IPO Chart
Input Processing Output
Radius of pizza
Area of pizza (14.13)
Value of pi (3.14)
Processing Item:
area of pizza

Algorithm:
1. Enter the radius of pizza
2. Calculate the area of pizza
by squaring the radius of
pizza and multiplying the
result by the value of pi
(3.14).
3. Calculate the total no. of
pizza slices by dividing the
area of pizza by the area of
sliced pizza (14.13).
4. Display the total no. of
pizza slices.
Total number of pizza slices



C++ CODES:
// Intermediate1.cpp - calculates and display the number of slices of pizza
// created by Totoy Brownies (Aba Matinde!) on July 9, 2014

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
// declare variables
double radiusOfPizza = 0.0;
const double areaPerSlice = 14.13;
const double pi = 3.14;
int radiusSquared = 0;
int numberOfSlices = 0;
double area = 0.0;

// enter input items
cout<< "Radius of the pizza: ";
cin>> radiusOfPizza;

// calculate the number of slices
radiusSquared = radiusOfPizza*radiusOfPizza;
area = pi*radiusSquared;
numberOfSlices = area/areaPerSlice;

// display output item
cout<< "Number of Slices: " << numberOfSlices << endl;

return 0;

} // end of main function




DESK-CHECK
Radius of pizza Area of pizza Total no. of pizza slices
10 314 22
6 113.04 8




4. Complete INTRODUCTORY Exercise 2. Enter (or copy) the instructions from the Introductory2.cpp
file into a new source file named Advanced1.cpp. Modify the code in the Advanced14.cpp file so that it
also calculates and displays the percentage of the total revenue contributed by each seating category.
Save and run the program. Test the program using 50, 100, and 75 as the number of Orchestra, Main
Floor, and Balcony seats. Then test it using 30, 25, and 99. (Dont be concerned about the extra decimal
places in the answers.)

IPO Chart
Input Processing Output
No. of sold tickets
for Orchestra seats
No. of sold tickets
for Main Floor seats
No. of sold tickets
for Balcony seats
Orchestra seat cost
($25)
Main Floor seat
cost ($30)
Balcony seat cost
($15)
Processing Item: none

Algorithm:
1. Enter the no. of sold tickets for
Orchestra seats, no. of sold tickets for
Main Floor seats, and no. of sold
tickets for Balcony seats.
2. Calculate the amount of revenue in
Orchestra seats by multiplying the no.
of sold tickets by the Orchestra seat
cost ($25).
3. Calculate the amount of revenue in
Main Floor seats by multiplying the
no. of sold tickets by the Main Floor
seat cost ($30).
4. Calculate the amount of revenue in
Balcony seats by multiplying the no.
of sold tickets by the Balcony seat cost
($15).
5. Calculate the amount of revenue by
adding the amount of revenue
Orchestra seats, amount of revenue
Main Floor seats, and amount of
revenue Balcony seats.
6. Calculate the percentage of the total
revenue contributed by each seating
category by dividing total revenue of
each seating category by the total
revenue then multiplying by 100
7. Display the amount of revenue by
adding the amount of revenue
Orchestra seats, amount of revenue
Main Floor seats, amount of revenue
Balcony seats, and the total amount of
revenue and the percentage of the total
revenue by each seating category.
amount of revenue
Orchestra seats
amount of revenue Main
Floor seats
amount of revenue
Balcony seats
total amount of revenue
percentage of Orchestra
Seats
percentage of Main Floor
Seats
percentage of Balcony
Seats


C++ CODES:
// Introductory2.cpp - calculates and display the percentage of the total revenue contributed by each seating
category.
// created by Totoy Brownies (Aba Matinde!) on July 9, 2014

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
// declare variables
int orchestra = 0;
int mainFloor = 0;
int balcony = 0;
const int orchestraPrice = 25;
const int mainFloorPrice = 30;
const int balconyPrice = 15;
int revenueGenerated = 0;
int totalRevenue = 0;
double orchestraPriceRevenue = 0.0;
double mainFloorPriceRevenue = 0.0;
double balconyPriceRevenue = 0.0;
double percentageOrchestra = 0.0;
double percentageMainFloor = 0.0;
double percentageBalcony = 0.0;


// enter input items
cout<< "Enter number of orchestra seats: ";
cin>> orchestra;
cout<< "Enter number of main floor: ";
cin>> mainFloor;
cout<< "Enter number of balcony: ";
cin>> balcony;

// calculate the revenue generated by each seating category and the total revenue and the percentage of
each category
orchestraPriceRevenue = orchestra * orchestraPrice;
mainFloorPriceRevenue = mainFloor * mainFloorPrice;
balconyPriceRevenue = balcony * balconyPrice;
totalRevenue = orchestraPriceRevenue + mainFloorPriceRevenue + balconyPriceRevenue;
percentageOrchestra = (orchestraPriceRevenue/totalRevenue)*100;
percentageMainFloor = (mainFloorPriceRevenue/totalRevenue)*100;
percentageBalcony = (balconyPriceRevenue/totalRevenue)*100;

// display output item
cout<< "Orchestra Revenue Generated: " << orchestraPriceRevenue << endl;
cout<< "Main Floor Revenue Generated: " << mainFloorPriceRevenue << endl;
cout<< "Balcony Revenue Generated: " << balconyPriceRevenue << endl;
cout<< "Total Revenue: " << totalRevenue << endl;
cout<< "Percetage of Orchetra: " << percentageOrchestra << " %" << endl;
cout<< "Percentage of Main Floor: " << percentageMainFloor << " %" << endl;
cout<< "Percentage of Balcony: " << percentageBalcony << " %" << endl;

return 0;

} // end of main function


DESK-CHECK
No. of tickets sold Amount of revenue Total
amount
of
revenue
Percentage of total revenue
Orchestra Main
Floor
Balcony Orchestra Main
Floor
Balcony Orchestra Main
Floor
Balcony
50 100 75 $1250 $3000 $1125 $5375 23.26% 55.81% 20.93%
30 25 99 $750 $750 $1485 $2985 25.13% 25.13% 49.75%

Вам также может понравиться