Question

C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of...

C++

Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of 3.

If I want 32 engines I would need to purchase 1 box of 24 and 3 packages of 3 (I would end up with 1 extra engine). Write a program that calculates how many boxes and packages you must purchase to get a specific number of engines. Also enter the price of a box and a package and calculate the total cost of the purchase. Use integer division (/, %) to calculate the number of boxes and packages. Note: when printing out the answer the correct word (box/boxes, package/packages) should appear after the number. If the number is 0, don't print anything at all.

Example Output:

Enter the number of engines needed: 30

Enter the cost of a box of 24 engines: 65.95

Enter the cost of a package of 3 engines: 8.49

You will need to purchase 1 box and 2 packages of engines

at a total cost of $82.93.

-----

Enter the number of engines needed: 10

Enter the cost of a box of 25 engines: 65.95

Enter the cost of a package of 3 engines: 8.49

You will need to purchase 4 packages of engines

at a total cost of $33.96.

Required Test Cases:

2, 65.95, 8.49

6, 65.95, 8.49

35, 65.95, 8.49

50, 65.95, 8.49

70, 65.95, 8.49

Requirements:

  • Use the “Steps for creating a program” template to develop your solution.
  • Declare and use at least one const variable (pi is an obvious choice, can you think of others?).
  • Use meaningful variable names and reasonable data types.
  • Include a comment section at the top of you file, with your name, the assignment number and a brief summary (in your own words) of what the program does.
  • Include comments to describe the major sections of the program   
  • Prompt for each input value you need and annotate the output to describe what it represents.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The c++ program with the given function and the test screenshots with formatted output are added.

#include <iostream>
using namespace std;

// Calculates how many boxes and packages you must purchase to get a specific number of engines.
// Also enter the price of a box and a package and calculate the total cost of the purchase.
int main()
{
float costOfBox, costOfPackage, totalCost;
int numberOfEngines, numberOfBoxes, numberOfPackages;
const float pi = 3.14;
// Enter the number of engines
cout << "Enter the number of engines needed: " << endl;
cin >> numberOfEngines;
  
// Enter the cost of a box
cout << "Enter the cost of a box of 24 engines: " << endl;
cin >> costOfBox;
  
// Enter the cost of package
cout << "Enter the cost of a package of 3 engines: " << endl;
cin >> costOfPackage;

// Calculate the number of boxes required, which is the quotient when divided by 24
numberOfBoxes = numberOfEngines/24;
  
// Calculate the number of packages required, which is the sum of quotient and remainder when divided by 3
if ((numberOfEngines % 24)%3 > 0) {
numberOfPackages = (numberOfEngines % 24)/3 + 1;
}
else {
numberOfPackages = (numberOfEngines % 24)/3;
}

// Compute the total cost of engines
totalCost = numberOfBoxes*costOfBox + numberOfPackages*costOfPackage;

// 9 conditional statements for correct format of string
if (numberOfBoxes == 0 && numberOfPackages == 0) {
cout << "You will need to purchase at a total cost of $0.00.";
}
else if (numberOfBoxes == 0 && numberOfPackages == 1) {
cout << "You will need to purchase 1 package of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes == 1 && numberOfPackages == 0) {
cout << "You will need to purchase 1 box of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes == 1 && numberOfPackages == 1) {
cout << "You will need to purchase 1 box and 1 package of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes == 0 && numberOfPackages > 1) {
cout << "You will need to purchase " << numberOfPackages << " packages of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes > 1 && numberOfPackages == 0) {
cout << "You will need to purchase " << numberOfBoxes << " boxes of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes == 1 && numberOfPackages > 1) {
cout << "You will need to purchase 1 box and " << numberOfPackages << " packages of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes > 1 && numberOfPackages == 1) {
cout << "You will need to purchase " << numberOfBoxes << " boxes and 1 package of engines at a total cost of $" << totalCost << ".";
}
else if (numberOfBoxes > 1 && numberOfPackages > 1 ) {
cout << "You will need to purchase " << numberOfBoxes << " boxes and " << numberOfPackages << " packages of engines at a total cost of $" << totalCost << ".";
}
  

return 0;
}

#include <iostream> using namespace std; // Calculates how many boxes and packages you must purchase to get a specific number// 9 conditional statements for correct format of string if (numberOfBoxes -- 0 && numberOfPackages -- () { cout << You willExecute > Share main.cpp STDIN 1.li Result 30 65.95 8.49 Sg++ -o main *.CPP $main Enter the number of engines needed: Enter tExecute > Share main.cpp STDIN 1.li Result 10 65.95 8.49 $g++ -o main *.cpp $main Enter the number of engines needed: Enter t65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost35 65.95 8.49 $g++ -o main *.cpp Smain Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the c50 65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the c65.95 8.49 $g++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost

#include <iostream> using namespace std; // Calculates how many boxes and packages you must purchase to get a specific number of engines. // Also enter the price of a box and a package and calculate the total cost of the purchase. int maino float costOfBox, costOfPackage, totalCost; int numberOfEngines, numberOfBoxes, numberOfPackages; const float pi = 3.14; // Enter the number of engines cout << "Enter the number of engines needed: " << endl; cin >> numberOfEngines; // Enter the cost of a box cout << "Enter the cost of a box of 24 engines: " << endl; cin >> costOfBox; // Enter the cost of package cout << "Enter the cost of a package of 3 engines: " << endl; cin >> costOfPackage; // Calculate the number of boxes required, which is the quotient when divided by 24 numberOfBoxes = numberOfEngines/24; // Calculate the number of packages required, which is the sum of quotient and remainder when divided by 3 if ((numberOfEngines % 24)%3 > 0) { numberOfPackages - (numberOfEngines % 24)/3 + 1; else { numberOfPackages - (numberOfEngines % 24)/3; // Compute the total cost of engines totalCost numberOfBoxes*costOfBox + numberOfPackages *costOfPackage;

// 9 conditional statements for correct format of string if (numberOfBoxes -- 0 && numberOfPackages -- () { cout << "You will need to purchase at a total cost of $0.00."; else if (numberOfBoxes == 0 && numberOfPackages -- 1) { cout << "You will need to purchase 1 package of engines at a total cost of $" << total cost << "."; else if (numberOfBoxes == 1 && numberOfPackages -- ) { cout << "You will need to purchase 1 box of engines at a total cost of $" << total Cost << "."; else if (numberOfBoxes == 1 && numberOfPackages = 1) { I cout << "You will need to purchase 1 box and 1 package of engines at a total cost of $" « totalCost << "."; else if (numberOfBoxes == 0 && numberOfPackages > 1) { cout << "You will need to purchase " << numberOfPackages « " packages of engines at a total cost of $" < totalCost << "."; else if (numberOfBoxes > 1 && numberOfPackages -- 0) { cout << "You will need to purchase " << numberOfBoxes « " boxes of engines at a total cost of $" << totalCost << "."; else if (numberOfBoxes == 1 && numberOfPackages > 1) { cout << "You will need to purchase 1 box and " << numberOfPackages << " packages of engines at a total cost of $" < totalCost « "."; else if (numberOfBoxes > 1 && numberOfPackages == 1) { cout << "You will need to purchase " << numberOfBoxes << " boxes and 1 package of engines at a total cost of $" < total cost << "."; else if (numberOfBoxes > 1 && numberOfPackages > 1){ cout << "You will need to purchase " << numberOfBoxes << " boxes and " << numberOfPackages << " packages of engines at a total cost of $" << total cost << "."; return 0;

Execute > Share main.cpp STDIN 1.li Result 30 65.95 8.49 Sg++ -o main *.CPP $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines : You will need to purchase 1 box and 2 packages of engines at a total cost of $82.93.

Execute > Share main.cpp STDIN 1.li Result 10 65.95 8.49 $g++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 4 packages of engines at a total cost of $33.96.

We were unable to transcribe this image

35 65.95 8.49 $g++ -o main *.cpp Smain Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 1 box and 4 packages of engines at a total cost of $99.91.

50 65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 2 boxes and 1 package of engines at a total cost of $140.39

We were unable to transcribe this image

We were unable to transcribe this image

#include <iostream> using namespace std; // Calculates how many boxes and packages you must purchase to get a specific number of engines. // Also enter the price of a box and a package and calculate the total cost of the purchase. int maino float costOfBox, costOfPackage, totalCost; int numberOfEngines, numberOfBoxes, numberOfPackages; const float pi = 3.14; // Enter the number of engines cout << "Enter the number of engines needed: " << endl; cin >> numberOfEngines; // Enter the cost of a box cout << "Enter the cost of a box of 24 engines: " << endl; cin >> costOfBox; // Enter the cost of package cout << "Enter the cost of a package of 3 engines: " << endl; cin >> costOfPackage; // Calculate the number of boxes required, which is the quotient when divided by 24 numberOfBoxes = numberOfEngines/24; // Calculate the number of packages required, which is the sum of quotient and remainder when divided by 3 if ((numberOfEngines % 24)%3 > 0) { numberOfPackages - (numberOfEngines % 24)/3 + 1; else { numberOfPackages - (numberOfEngines % 24)/3; // Compute the total cost of engines totalCost numberOfBoxes*costOfBox + numberOfPackages *costOfPackage;

// 9 conditional statements for correct format of string if (numberOfBoxes -- 0 && numberOfPackages -- () { cout << "You will need to purchase at a total cost of $0.00."; else if (numberOfBoxes == 0 && numberOfPackages -- 1) { cout << "You will need to purchase 1 package of engines at a total cost of $" << total cost << "."; else if (numberOfBoxes == 1 && numberOfPackages -- ) { cout << "You will need to purchase 1 box of engines at a total cost of $" << total Cost << "."; else if (numberOfBoxes == 1 && numberOfPackages = 1) { I cout << "You will need to purchase 1 box and 1 package of engines at a total cost of $" « totalCost << "."; else if (numberOfBoxes == 0 && numberOfPackages > 1) { cout << "You will need to purchase " << numberOfPackages « " packages of engines at a total cost of $" < totalCost << "."; else if (numberOfBoxes > 1 && numberOfPackages -- 0) { cout << "You will need to purchase " << numberOfBoxes « " boxes of engines at a total cost of $" << totalCost << "."; else if (numberOfBoxes == 1 && numberOfPackages > 1) { cout << "You will need to purchase 1 box and " << numberOfPackages << " packages of engines at a total cost of $" < totalCost « "."; else if (numberOfBoxes > 1 && numberOfPackages == 1) { cout << "You will need to purchase " << numberOfBoxes << " boxes and 1 package of engines at a total cost of $" < total cost << "."; else if (numberOfBoxes > 1 && numberOfPackages > 1){ cout << "You will need to purchase " << numberOfBoxes << " boxes and " << numberOfPackages << " packages of engines at a total cost of $" << total cost << "."; return 0;

Execute > Share main.cpp STDIN 1.li Result 30 65.95 8.49 Sg++ -o main *.CPP $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines : You will need to purchase 1 box and 2 packages of engines at a total cost of $82.93.

Execute > Share main.cpp STDIN 1.li Result 10 65.95 8.49 $g++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 4 packages of engines at a total cost of $33.96.

We were unable to transcribe this image

35 65.95 8.49 $g++ -o main *.cpp Smain Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 1 box and 4 packages of engines at a total cost of $99.91.

50 65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 2 boxes and 1 package of engines at a total cost of $140.39

65.95 8.49 $g++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 2 boxes and 8 packages of engines at a total cost of $199.8:

65.95 8.49 Sg++ -o main *.cpp $main Enter the number of engines needed: Enter the cost of a box of 24 engines: Enter the cost of a package of 3 engines: You will need to purchase 2 packages of engines at a total cost of $16.98.

Add a comment
Know the answer?
Add Answer to:
C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

  • Computer science help! A software company sells their software packages for $99.00 each. They would like...

    Computer science help! A software company sells their software packages for $99.00 each. They would like you to write a program that will calculate and display an invoice for their customers. Quantity discounts are given according to the following table: Quantity   Discount 1 - 9 No discount 10 – 19 20% 20 – 49 30% 50 - 99 40% 100 or more 50% Write a C++ program that asks for the customer’s name and the number of software packages sold...

  • An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit...

    An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit organizations: Package A: 10 hours of access for $12.95 per month. Additional hours are $4.00 per hour. Package B: 20 hours of access for $14.95 per month. Additional hours are $2.00 per hour. Package C: 30 hours of access for $20 per month. Additional hours are $1.00 per hour. Package D: Unlimited access for $35.95 per month. A nonprofit organizations will get 20% discount...

  • Note: The subject I am taking is Cost Engineering. Please give a step by step solution...

    Note: The subject I am taking is Cost Engineering. Please give a step by step solution for the following problem. Problem: Bakery the Invincible Determine the production cost status for the month of August according to the following data: a.) Purchase of 250 packages of flour that is used every 15 days at a cost per package of 550 pesos. b.) Purchase 20 boxes of butter for weekly use at a cost of 770 pesos each box. c.) Purchase 10...

  • In PYTHON code: Examples of output are as follows: If the user entered Package A and...

    In PYTHON code: Examples of output are as follows: If the user entered Package A and 30 GB of data, then you should get the following output: Mobile Service Provider Enter your mobile phone package (A, B or C): A How many gigabytes data did you use? 30 Your total cost for Package A is 299.99 If you had chosen Package C you would have saved $ 230.00 If you had chosen Package B you would have saved $ 130.00...

  • USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the...

    USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user indicate the weight and quantity of the boxes. The program computes and prints the total cargo weight The output should match the sample below. Make sure you print the input number (Input #1, Input #2,) 3 - Input # 1. Weight of the box (lbs): 4 Enter quantity: 2 Input #2. Weight of the...

  • You are consulting for a trucking company that does a large amount of business shipping packages...

    You are consulting for a trucking company that does a large amount of business shipping packages between New York and Boston. The volume is high enough that they have to send a number of trucks each day between the two locations. Trucks have a fixed limit w on the maximum amount of weight they are allowed to carry. Boxes arrive at the New York station one by one, and each package i has a weight wi. The trucking station is...

  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

  • Part II – Cost Calculator (15 Points) A software company sells a package that retails for...

    Part II – Cost Calculator (15 Points) A software company sells a package that retails for $ 99. Quantity discounts are given according to the following table: Quantity Discount 10 to 19 20% 20 to 49 30% 50 to 99 40% 100 or more 50% Write a program that asks the user to enter the number of packages purchased. The program should then display the discount percentage, amount of the discount (can be 0) and the total amount of the...

  • Boxes Task: Evaluate whether you can load various sizes of jars into boxes. For each test,...

    Boxes Task: Evaluate whether you can load various sizes of jars into boxes. For each test, you will input the length, width, and height of a box as well as the diameter and height of a cylindrical jar. The algorithm will determine whether each jar will fit in its corresponding box. The jar can sit upright in the box, or it can lie on its side with its top parallel to one of the sides of the box.   Assume that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT