In: Computer Science
A PC store sells many types of computers. The PC can have either 16 or 8 gigabytes of memory.
The quality of the PCs can be either New, Refurbished, or Dented.
The price list is given as follows:
Memory size/Status New Refurbished Dented
16 gigabytes 849.99 729.99 609.99
8 gigabytes 699.99 579.99 439.99
Determine the price of a given PC dependent on the user inputs. The sale tax is 9.25% for each PC.
User input can only be 8 or 16 for memory size and 'N', 'R', or 'D' for quality (upper-case). The input quantityt should be 0 or positive.
If any user input is not correct, display an error message and skip all calculation.
All currency amount should be displayed with 2 digits in decimal fraction.
Here are several separate program sample runs. There is No need to use loop for repetition.
Enter the memory size of the PC (8 or 16 gigabytes): 16
Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): N
Enter PC quantity want to buy: 2
The item price is $1699.98
The sale tax is $157.25
The total bill is $1,857.23
----------------------
Enter the memory size of the PC (8 or 16 gigabytes): 8
Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): R
Enter PC quantity want to buy: 3
The item price is $1739.97
The sale tax is $160.95
The total bill is $1900.92
----------------------
Enter the memory size of the PC (8 or 16 gigabytes): 15
Invalid memory size!
----------------------
Enter the memory size of the PC (8 or 16 gigabytes): 8
Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): A
Invalid PC quality!
----------------------
Enter the memory size of the PC (8 or 16 gigabytes): 8
Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): (user hit Tab key)
Invalid PC quality!
----------------------
Enter the memory size of the PC (8 or 16 gigabytes): 16
Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): R
Enter PC quantity want to buy: -2
Invalid PC quantity!
[C++ PROGRAMING]
SOURCE CODE IN C++:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int size;
cout << "Enter the memory size of the PC (8 or 16 gigabytes): "; //input prompt
cin >> size; //input
if(size!=8 && size!=16) //input validation
{
cout << "Invalid memory size!" << endl; //error message
return 1; //terminating program
}
char quality;
cout << "Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): "; //input prompt
cin >> quality; //input
if(quality!='N' && quality!='R' && quality!='D') //input validation
{
cout << "Invalid PC quality!" << endl; //error message
return 1; //terminating program
}
int quantity;
cout << "Enter PC quantity want to buy: "; //input prompt
cin >> quantity; //input
if(quantity<0) //input validation
{
cout << "Invalid PC quantity!" << endl; //error message
return 1; //terminating program
}
//determining price for user input
double price;
if(size==16)
{
if(quality=='N')
price=849.99;
else if(quality=='R')
price=729.99;
else
price=609.99;
}
else
{
if(quality=='N')
price=699.99;
else if(quality=='R')
price=579.99;
else
price=439.99;
}
//calculating total price and sales tax and then total bill
price*=quantity;
double sales_tax=0.0925*price;
double total=price+sales_tax;
//output
printf("The item price is $%.2f\n",price);
printf("The sales tax is $%.2f\n",sales_tax);
printf("The total bill is $%.2f\n",total);
return 0;
}
OUTPUT: