Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Assignment # 1

Programming Fundamentals (Lab)


Name: Abdul Rehman Roll Num: 70131431
1. To make a profit, a local store marks up the prices of its items by a certain
percentage. Write a C++ program that reads the original price of the item sold, the
percentage of the marked- 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, and the final price of the item. (The final price
of the item is the selling price plus the sales tax.)
#include <iostream>
using namespace std;
int main(){
int original_price;
double mark_up;
double tax_rate;

cout<<"Enter the original price: ";


cin>>original_price;
cout<<endl;
cout<<"Enter the percentage of the marked-up price: ";
cin>>mark_up;
cout<<endl;
cout<<"Enter the sales tax rate: ";
cin>>tax_rate;
cout<<endl<<endl;
cout<<"Orignal Price: "<<original_price<<endl;
cout<<"Mark-up Price: "<<original_price * (mark_up / 100)<<endl;
cout<<"Sales Tax Rate: "<<original_price * (tax_rate / 100)<<endl<<endl;
cout<<"Final Price: "<<original_price+(original_price * (mark_up /
100))+(original_price * (tax_rate / 100));

return 0;}

PseudoCode: Declare original_price as int, declare mark_up and tax_rate as double.

Get the values of original_price, mark_up and tax_rate and store them.

Display original price.

Calculate mark_up price and Display. Calcultate Sales Tax and Display. Calculate Final Price and
Display.
Assignment # 1

2. If you buy a 40GB hard drive, then chances are that the actual storage on the hard
drive is not 40GB. This is due to the fact that, typically, a manufacturer considers that
1000 bytes are equal to 1KB, 1000KB is equal to 1MB, 1000MB is equal to 1GB.
Therefore, according to the manufacturer, a 40GB hard drive contains 40,000,000,000
bytes. This is wrong because in computer memory, 1KB is equal to 1024 bytes, and so
on. So the actual storage on a 40GB hard drive is approximately 37.25GB. Write a
program that prompts the user to enter the size of the hard drive specified by the
manufacturer, on the hard drive box, and outputs the actual storage capacity of the hard
drive.

#include <iostream>

using namespace std;

int main(){
double givensize, realsize;

cout << "Please enter the size of the HDD: ";


cin >> givensize;

givensize = givensize * 1000 * 1000;


realsize = givensize / 1024 / 1024;

cout << "Hard Drive is actually: " << realsize << "GB" << endl;

return 0;
}

Declare givensize and realsize as doubles.

Get givensize from user.

Assign givensize*1000*1000 to givensize.

Assign givensize / 1024 / 1024 to realsize.

Display realsize.
Assignment # 1

3. You found an exciting summer job for five weeks. It pays, say, $15.50
per hour. Suppose that
the total tax you pay on your summer job income is 14%. After paying the
taxes, you spend
10% of your net income to buy new clothes and other accessories for the
next school year
and 1% to buy school supplies. After buying clothes and school supplies,
you use 25% of the
remaining money to buy savings bonds. For each dollar you spend to buy
savings bonds,
your parents spend $0.50 to buy additional savings bonds for you. Write a
program that
prompts the user to enter the pay rate for an hour and the number of hours
you worked each
week. The program then outputs the following:
a) Your income before and after taxes from your summer job.
b) The money you spend on clothes and other accessories.
c) The money you spend on school supplies.
d) The money you spend to buy savings bonds.
e) The money your parents spend to buy additional savings bonds for you
Assignment # 1

#include <iostream>
#include <iomanip>

using namespace std;

int main(){
double payRate, grossIncome, netIncome, schoolAmount, bondsAmount;
double clothesAmount, parentsBondsAmount, hoursWorked;

double TAX_RATE = 0.14;


double CLOTHES_PERCENTAGE_OF_INCOME = 0.10;
double SCHOOL_PERCENTAGE_OF_INCOME = 0.01;
double SAVINGS_BONDS_PERCENTAGE_OF_INCOME = 0.25;
double PARENTS_CO_CONTRIBUTION_AMOUNT = 0.50;

cout << "How many hours did you work: ";


cin >> hoursWorked;

cout << "What was the hourly rate: $";


cin >> payRate;

grossIncome = hoursWorked * payRate;


netIncome = grossIncome *= TAX_RATE;
clothesAmount = netIncome * CLOTHES_PERCENTAGE_OF_INCOME;
schoolAmount = netIncome * SCHOOL_PERCENTAGE_OF_INCOME;
netIncome = netIncome - (clothesAmount + schoolAmount);
bondsAmount = netIncome * SAVINGS_BONDS_PERCENTAGE_OF_INCOME;
parentsBondsAmount = bondsAmount * PARENTS_CO_CONTRIBUTION_AMOUNT;

cout << "Gross Income: " << grossIncome << endl;


cout << "Net Income: " << netIncome << endl;
cout << "Clothes & Accessories: " << clothesAmount << endl;
cout << "School Supplies: " << schoolAmount << endl;
cout << "Savings Bonds: " << bondsAmount << endl;
cout << "Parents Bonds Co-Contribution: " <<parentsBondsAmount << endl;

return 0;
}
Assignment # 1
Pseudo Code: Declare payRate, grossIncome, netIncome, schoolAmount, bondsAmount, clothesAmount,
parentsBondsAmount and hoursWorked as doubles.

Declare all the given data as doubles.

Get hoursWorked and payRate from User.

Calculate grossIncome = hoursWorked * payrate.

Calculate netIncome = grossIncome *= TAX_RATE.


Calculate clothesAmount = netIncome * CLOTHES_PERCENTAGE_OF_INCOME.

Calculate schoolAmount = netIncome * SCHOOL_PERCENTAGE_OF_INCOME.

Calculate netIncome = netIncome - (clothesAmount + schoolAmount).

Calculate bondsAmount = netIncome * SAVINGS_BONDS_PERCENTAGE_OF_INCOME.

Calculate parentsBondsAmount = bondsAmount * PARENTS_CO_CONTRIBUTION_AMOUNT.

Display grossIncome ,netIncome ,clothesAmount ,schoolAmount ,bondsAmount ,parentsBondsAmount .

You might also like