In: Computer Science
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.
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:)