Question

Write a C++ program that calculates the discount of the original price of an item and...

Write a C++ program that calculates the discount of the original price of an item and displays the new price, and the total amount of savings. This program should have a separate header (discount.h), implementation (discount.cpp) and application files (main.cpp). The program must also have user input: the user must be prompted to enter data (the original price, and the percent off as a percentage). There must also be a validation, for example:

Output: “Enter the original price of the item”

User input: “29”

Output: “Now enter the percent discount”

User input: “0.10”

Output: “Please enter the discount as a percentage”

Now the user input: “10”

------------------

The user input should be stored within an object. Be sure to use mutators to assign values to Class Variables. Classes should also include functions which will manipulate/calculate data for the final result (both the calculated discount and the total savings). When the final results are calculated/processed, the program should store the final results (discounted price and savings) as a text file. The final result should also be accompanied with any context which should help a reader understand what the results mean (“the original price of the item was “user inputted price,” with a “user inputted percent discount,” the new price of the item is “calculated price”! You saved “amount of savings” this much money!

Please leave \\comments and label where Discount.h, Discount.cpp, and main.cpp are, thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//dicount.cpp file

#include<iostream>
#include<fstream>
using namespace std;
class Discount
{
// Access specifier
public:

// Data Members
float amount;
float percentage;
float discount;
float savings;

// Functions()
void calc_discount(float amt,float per)
{amount=amt;percentage=per;
discount=(amount-(percentage*amount/100.0));
savings=amount-discount;
cout << "After discount the amount is: " << discount;
cout<<"savings="<<savings;
ofstream myfile;
myfile.open("newfile.txt");
myfile<<"After discount the amount is: " << discount;
myfile<<"\nsavings= "<<savings;
myfile.close();
}
};

//discount.h file

#include<iostream>
#include<fstream>
using namespace std;
class Discount
{
// Access specifier
public:

// Data Members
float amount;
float percentage;
float discount;
float savings;

// Functions()
void calc_discount(float amt,float per)
{amount=amt;percentage=per;
discount=(amount-(percentage*amount/100.0));
savings=amount-discount;
cout << "After discount the amount is: " << discount;
cout<<"savings="<<savings;
ofstream myfile;
myfile.open("newfile.txt");
myfile<<"After discount the amount is: " << discount;
myfile<<"\nsavings= "<<savings;
myfile.close();
}
};

///main.cpp

#include <iostream>

#include"discount.h"

int main() {

float amount;float percentage;

cout<<"Enter the original price of the item: ";

cin>>amount;

cout<<" Now enter the percent discount: ";

cin>>percentage;

while(percentage<1)

{cout<<"Please enter the discount as a percentage: ";

cin>>percentage;

}

Discount d;

d.calc_discount(amount,percentage);

return 0;

}

Project2. [Project2.dev]- [魟 CAUsers MAHEDocuments Project2.exe File Edit Search View Project Execute Tools AStyle Window Hel

//all the files are in same directory..

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that calculates the discount of the original price of an item and...
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
  • 1. Write a program that calculates sales price of each article. The program will get the...

    1. Write a program that calculates sales price of each article. The program will get the unit price of each article through the keyboard, and then calculate actual sales price. Actual sales price of each article is calculated as follows: • Sales Price = (2 x unit price) + (unit price x sales tax) Sales tax for each item is fixed to 5%. Your program should keep asking user to input unit price. If the user does not have any...

  • Please Answer Quickly Quantity discount program Write a MATLAB program that takes two inputs from the...

    Please Answer Quickly Quantity discount program Write a MATLAB program that takes two inputs from the user, Input 1: a decimal number that is a unit price (the price of one item) in dollars and cents Input 2: an integer that is the quantity of the item to purchase. The program prints 3 outputs, each on its own line: output 1: the total cost with no discount (unit price X quantity) output 2: the amount of discount in dollars and...

  • Java I: Create a Java program that will accept the price of an item and the...

    Java I: Create a Java program that will accept the price of an item and the quantity being purchased of that item. After accepting the input, calculate the amount of the purchase (based on the price and quantity), calculate the sales tax on the purchase, then output the product price, quantity, subtotal, sales tax, and the total sale based on the output format shown below. Structure your file name and class name on the following pattern: The first three letters...

  • Write in C++ using emacs. Write a program that calculates the ending balance of several savings...

    Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...

  • Write a method that calculates a 15% discount on the price of an item. Have the...

    Write a method that calculates a 15% discount on the price of an item. Have the method return the discounted price. For example if the price is $100.00 the method should return $85.00. Write the method using either returning void and using a referene parameter or write it returning the value as a double or decimal and taking a value parameter. Call the function passing it an appropriate variable. Display the result.

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates...

    WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates a price change of a stock. When the program runs, it should do the following:  Create a Stock class which must include fields: name, symbol, currentPrice, nextPrice, priceChange, and priceChangePercentage.  The Stock class must have two constructor: a no-argument constructor and a constructor with four parameters that correspond to the four fields. o For the no-argument constructor, set the default value for...

  • Write a Python program that asks the user to enter the number of calories and fat...

    Write a Python program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, therefore: Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as follows: Calories from fat / total calories If the calories from fat are less than 30 percent of the total...

  • 12.5 Program: Divide by Zero (C++) This program will test exception handling during division. The user...

    12.5 Program: Divide by Zero (C++) This program will test exception handling during division. The user will enter 2 numbers and attempt to divide (in a try block) the 1st number by the 2nd number. The program will provide for 2 different catch statements: Division by zero - denominator is zero Division results in a negative number The user should be prompted with Enter 2 numbers: For input of 7 and 0 the output should be Exception: Division by zero...

  • Write a C++ program that will calculate the total amount of money for book sales at...

    Write a C++ program that will calculate the total amount of money for book sales at an online store. For each sale, your program should ask the number of books sold and then the price for each book and the shipping method (‘S’ for standard shipping and ‘E’ for expedited shipping). The program will produce a bill showing the subtotal, the sales tax, the discount, the shipping charge, and the final total for the sale. The program will continue processing...

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