0% found this document useful (0 votes)
3 views

Assignment csc201 1

The document contains a series of C++ programming assignments related to cost calculations for construction materials and supermarket purchases. It includes code snippets for calculating total costs, balances, quantities of items, and VAT on purchases. Additionally, it covers water absorption tests for bricks and provides solutions for each programming task.

Uploaded by

myqhtsc6jf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment csc201 1

The document contains a series of C++ programming assignments related to cost calculations for construction materials and supermarket purchases. It includes code snippets for calculating total costs, balances, quantities of items, and VAT on purchases. Additionally, it covers water absorption tests for bricks and provides solutions for each programming task.

Uploaded by

myqhtsc6jf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Name: Ademola Adetunji David

Matric number: 22/11436

Department: Computer science

Level: 200

Course code: CSC 201

ASSIGNMENT 1

1. A bricklayer bought the following items at a local store;

Concrete bricks: 2 million naira

Cement: 7 million naira

Sand: 3 million naira

If the cost of delivering the materials was 600,000 naira.

a) Write a C++ program to find the total amount of cost the bricklayer bought the items.

b) Write a C++ program to find out the balance he will receive if he paid 100 million naira to the
cashier.

c) How many tippers of sand will he buy if a tipper of sand is 5,000 naira?

d) Write a C++ program to find out how many bags of cement he will buy, if one bag of cement is
4,200.

e) How many concrete bricks will he buy, if a brick of block is 80 naira.

SOLUTION!

A) #include <iostream>
B) using namespace std;

int main() {

int concreteBricks = 2000000;

int cement = 7000000;

int sand = 3000000;

int deliveryCost = 600000;

int totalCost = concreteBricks + cement + sand + deliveryCost;

cout << "Total amount of cost the bricklayer bought the items: " << totalCost << " naira" << endl;
return 0;

}
b) code to find the balance he will receive if he paid 100 million naira to the cashier

#include <iostream>
using namespace std;

int main() {
int totalAmountPaid = 100000000;
int totalCost = 2000000 + 7000000 + 3000000 + 600000;

int balance = totalAmountPaid - totalCost;

cout << "Balance the bricklayer will receive: " << balance << " naira" << endl;

return 0;
}
C) #include <iostream>
D) using namespace std;
E)
F) int main() {
G) // Cost of one tipper of sand
H) int costPerTipper = 5000;
I)
J) // Number of tippers
K) int numberOfTippers = 3000000 / costPerTipper; // 3 million divided by cost per tipper
L)
M) cout << "Number of tippers: " << numberOfTippers << endl;
N)
O) return 0;
P) }
D) #include <iostream>

using namespace std;

int main() {
// Cost of one bag of cement

int costPerBag = 4200;

// Number of bags

int numberOfBags = 7000000 / costPerBag; // 7 million divided by cost per bag

cout << "Number of bags of cement: " << numberOfBags << endl;
return 0;
}

E) #include <iostream>

using namespace std;

int main() {

// Cost of one concrete brick

int costPerBrick = 80;

// Number of bricks

int numberOfBricks = 2000000 / costPerBrick; // 2 million divided by cost per brick

cout << "Number of concrete bricks: " << numberOfBricks << endl;

return 0;

}
2. If a batch of concrete is made up of the following materials:

Cement: 200kg

Sand: 450kg

Granite: 750kg

Water: 300 liters

Write a C++ program to calculate and display, the amount of sand in a real number and the percentage
of the total amount of cement (decimal)

SOLUTION

#include <iostream>

using namespace std;

int main() {

// Materials in a batch of concrete

int cement = 200; // kg

int sand = 450; // kg

int granite = 750; // kg

int water = 300; // liters


// Total weight of materials

int totalWeight = cement + sand + granite + water;

// 1. Amount of sand in a real number

float sandAmount = static_cast<float>(sand);

cout << "Amount of sand in a real number: " << sandAmount << " kg" << endl;

// 2. Percentage of the total amount of cement (decimal)

float percentageDecimal = (static_cast<float>(cement) / totalWeight) * 100;

cout << "Percentage of the total amount of cement (decimal): " << percentageDecimal << "%" << endl;

return 0;

}
3. Two bricks of blocks were tested for water absorption the result are as follows:

Blocks/bricks Mass of dry blocks/bricks(kg) Mass of water absorbed(kg)


A 2.200 0.200
B 2.500 0.250

If water absorption = mass of water absorbed/mass of dry blocks

Write a c++ program to find the water of each block and the percentage involved.

SOLUTION

#include <iostream>

using namespace std;


int main() {

// Data for blocks A and B

float massA = 2.200; // kg

float waterAbsorbedA = 0.200; // kg

float massB = 2.500; // kg

float waterAbsorbedB = 0.250; // kg

// Calculate water absorption and percentage for each block

float waterAbsorptionA = waterAbsorbedA / massA;

float percentageA = waterAbsorptionA * 100;

float waterAbsorptionB = waterAbsorbedB / massB;

float percentageB = waterAbsorptionB * 100;

// Display results

cout << "Block A - Water Absorption: " << waterAbsorptionA << ", Percentage: " << percentageA <<
"%" << endl;

cout << "Block B - Water Absorption: " << waterAbsorptionB << ", Percentage: " << percentageB <<
"%" << endl;

return 0;

}
4. Mary, as the HOC of this class bought the where the prices of these items were displayed for view VAT
of each item included:

 1 bag of rice 50,700


 2 turkey 100,000
 Bag of beans 80,000
 3 25liter Kings oil each 60,000

If the VAT of each items varies between 5 and 10%, write a C++ program to determine the following:

1. Amount of money Mary spent in the supermarket.


2. The prices of each item Mary bought in the supermarket.
3. The total VAT
4. The transportation cost from warehouse to Mary’s was 70,000

Determine the total amount of money spent when 1 gallon of kings oil was returned to the market.

SOLUTION

#include <iostream>

#include <cstdlib> // for rand()

using namespace std;

int main() {

int prices[] = {50700, 100000, 80000, 60000};

int quantities[] = {1, 2, 1, 3};

float vatRangeMin = 0.05, vatRangeMax = 0.10, transportationCost = 70000;

float totalCost = 0, totalVAT = 0;


for (int i = 0; i < 4; ++i) {

totalCost += quantities[i] * prices[i];

totalVAT += totalCost * (vatRangeMin + (static_cast<float>(rand()) / RAND_MAX) * (vatRangeMax -


vatRangeMin));

cout << "Item " << i + 1 << ": Price " << prices[i] << " naira, VAT " << totalVAT << " naira" << endl;

float totalAmountSpent = totalCost + totalVAT + transportationCost;

cout << "1. Amount Mary spent: " << totalAmountSpent << " naira" << endl;

cout << "2. Total VAT: " << totalVAT << " naira" << endl;

cout << "3. Transportation cost: " << transportationCost << " naira" << endl;

// Assuming 10% discount for returning 1 gallon of Kings Oil

float priceOfKingsOilReturned = prices[3] * 0.9;

float totalAmountSpentAfterReturn = totalAmountSpent - (quantities[3] * prices[3]) +


priceOfKingsOilReturned;

cout << "Total amount spent after returning 1 gallon of Kings Oil: " << totalAmountSpentAfterReturn
<< " naira" << endl;

return 0;

You might also like