Question

In: Computer Science

Wholesalers often provide reduced prices on goods if the customer purchases more than one item. Your...

Wholesalers often provide reduced prices on goods if the customer purchases more than one item. Your company wants to create a program that customers can use to determine the cost of their purchase.

Quantity

0 ≤ q < 10
10 ≤ q < 100 100 ≤ q < 1000 1000 ≤ q

Price

$15.00 per unit
$10.00 per unit + $50.00 $7.50 per unit + $300.00 $2.00 per unit + $5,080.00

Your program should prompt the user for the number of items purchased then calculate the cost of the purchase. You may not use if - else structures, but must instead limit yourself to the relational operators. The output must include printing the number of items ordered as well as the cost of the purchased. The output should be properly formatted.

Your program must also include comments with your name, the date, and a short description of the project. It must also print this information as a splash screen at the beginning of the program run.

Solutions

Expert Solution

So, here I am giving you wellcommented C++ code along with the screenshots of the code and the output of the code.
I hope this will help.

Source Code:

#include <iostream>
#include <ctime>
using namespace std;
//function to add a timer for splash screen if you want you can remove it
void sleep(float seconds){
    //clock object
    clock_t startClock = clock();
    //seconds it will be running
    float secondsAhead = seconds * CLOCKS_PER_SEC;
    //running a loop and doing nothing until the required time pass
    while(clock() < startClock+secondsAhead);
    return;
}

int main()
{
    //replace name, date and Description according to you
    cout<<endl<<"\t\tName"<<endl<<"\t\tDate"<<endl<<"\t\tThis app is used to find the cost of the purchase";
    
    //function calling to pause the screen
    sleep(3.0);
    //function to clear the contents of splash screen
    //(this command will only work if you run this code into the GCC compilers not in turbo or online compilers)
    system("CLS"); 
    //taking quantity from the user
    int q;
    cout<<"Enter the number of items purchases: ";
    cin>>q;
    float cost;

    // calculating the cost according to the ques using ternary operator 
    (0<=q && q<10)? cost = 15.00*q : (q<100)?cost = 10.00*q + 50.00 : (q<1000)? 7.50*q + 300 : cost = 2.00*cost + 5080.00;
    
    //printing the cost of the given quantity
    cout<<"The Cost of "<<q<<" items is "<<cost;
    return 0;
}

Here I am attaching the screenshots.

Output:

Splash Screen You should replace the contents with your own name and all details according to you.

So, this was the solution for the given probelm.
I hope it will help you.
If yes, then do give it a thumbs up
It really helps:)


Related Solutions

A customer can order one or more items in one transaction (طلبية) . Every item has...
A customer can order one or more items in one transaction (طلبية) . Every item has a unique ID, Name, Price, and Description. Given the following item class, assume it is already programmed and ready for use. Class Item { public: Item(); void SetID(int);                       int GetID(); void SetPrice(double);              double GetPrice();        void SetName(string);              string GeName();        void SetDesc(string);               string GetDesc(); private: int id; String name, description; double price; }; Define a new class called Transaction that represents a customer order, where it...
Beginning inventory, purchases, and sales for an inventory item are as follows: Purchases Cost of Goods...
Beginning inventory, purchases, and sales for an inventory item are as follows: Purchases Cost of Goods Sold Inventory Event Unit Cost Total Cost Unit Cost Total Cost Total Cost QTY Bought Qty sold Qty Unit Cost Beginning Inventory 150 755 First Sale 120 First Purchase 400 785 Second Sale 200 Second Purchase 300 805 Sale 290 The firm uses the perpetual inventory system and there are 240 units of the item on hand at the end of the year A....
How can there be more than one efficient distribution of goods? Which distribution of goods is...
How can there be more than one efficient distribution of goods? Which distribution of goods is "most efficient”?
to test the claim that the resistance of electric wire can be reduced by more than...
to test the claim that the resistance of electric wire can be reduced by more than 0.050 ohm by alloying, thirty two (32) values were obtained for standard wire, and the sample average calculated was equal to 0.136 ohm. in addition, thirty two (32) values were obtained for alloyed wire, and the sample average calculated was equal to 0.083 ohm. the standard deviation resistance for standard wire is known to be 0.004 ohm, whereas the standard deviation resistance for alloyed...
Provide an alternative product or service to the items your classmate purchased. For one item, it...
Provide an alternative product or service to the items your classmate purchased. For one item, it needs to be a complement and the other a substitute. State what that item is, and whether it is a complement or a substitute good. (e.g. Honda – I bought a Toyota, it is a substitute. Prescription drugs - complement). Also, give an estimate of the cross-price elasticity coefficient for your items (e.g. > 0, 0, or <0)
Please provide your classmates with an example of one item for each of the three sections...
Please provide your classmates with an example of one item for each of the three sections of the Statement of Cash Flows.
1. State one of the reasons, why cancer does not occur more often than it already...
1. State one of the reasons, why cancer does not occur more often than it already does. 2. State one of the four general ways, a proto-oncogene is turned in to an oncogene.
C++ Often times a user has more than one account at the bank and managers have...
C++ Often times a user has more than one account at the bank and managers have asked to view the account with the largest balance first. We already have a handy utility function that is used for finding the maximum of two ints. int max(int a, int b) { if (b > a) { return b; } else { return a; } } How can we make a generic version? As a first step lets start by using pass by...
What is the exchange rate risk? In no more than 500 words, provide one example of...
What is the exchange rate risk? In no more than 500 words, provide one example of a multinational firm, and explain why would the firm be concerned about it. (please don't send pictures of this answer)
What is the exchange rate risk? In no more than 500 words, provide one example of...
What is the exchange rate risk? In no more than 500 words, provide one example of a multinational firm, and explain why would the firm be concerned about it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT