Lab 2 - Intro C++
Lab 2 - Intro C++
1. Trace and show the output of the following program. Suppose the input is:
340
#include<iostream>
int main(){
return 0;
}
2. To make a profit, a local store marks up the prices of its items by a certain percentage.
Write a complete C++ program that reads the original price of the items sold, the
percentage of the mark-up price, and the sales tax rate. The program then outputs the
original price of the item, the percentage of the mark-up, the store’s selling price of the
item, the sales tax rate, the sales tax amount, and the final price of the item. (The final
price of the item is the selling price plus the sales tax.)
#include <iostream>
int main()
{
double originalPrice, salesTaxRate, totalPrice,
1
markupPercentage, salesTaxPrice, markupPrice;
return 0;
}
2
3. A milk carton can hold 3.78 liters of milk. Each morning, a dairy farm ships cartons of
dairy milk to a local grocery store. The cost of producing one liter of milk is RM 0.38
and the profit of each carton of milk is RM 0.27. Write a complete C++ program that
does the following:
a. Prompts the user to enter the total amount of milk produced in the morning.
b. Outputs the number of milks carton needed to hold milk.
c. Outputs the cost of producing milk.
d. Outputs the profit of producing milk.
#include <iostream>
#include <iomanip>
int main(){
double milkProduced, cartonsRequired;
3
return 0;
}
4. You found an exciting part-time job during the UTP semester break, in which you
worked for a period of 7 weeks. It pays, say, RM 15.50 per hour. Suppose that the total
tax you pay on your income from the job is 14%. After paying the taxes, you spend
25% of your net income to buy new clothes and other accessories for the incoming
new semester and 4% to buy stationeries. After buying clothes and stationeries, you
use 45% of the remaining money to invest in unit trust. For each RM 2.00 that you
spend on unit trust, your parents spend RM 0.50 to buy additional unit trust for you.
Write a complete C++ program that will prompts the user to enter the number of hours
worked for each week, which may be different from one week to the other. The
program then outputs the following:
a. Your income before and after taxes from your part-time job.
b. The money you spend on clothes and other accessories.
c. The money you spend on stationeries.
d. The money that you invest on unit trust.
e. The money your parents spend to buy additional unit trust for you.
f. The money left for you to bring back to UTP.
#include <iostream>
#include <iomanip>
int main()
{
double payRate, grossIncome, netIncome, stationeryAmount,
trustAmount;
double clothesAmount, parentsBondsAmount, hoursWorked;
4
const double PARENTS_CO_CONTRIBUTION_AMOUNT = 0.50;
return 0;
}