A retail clothing store uses software to compute total cost

A retail clothing store uses software to compute total cost of items. This software also handles sales tax and any discounts that need to be applied to an order. The costs of a customer purchase are provided through an input file named clothing.dat with the following data:

T-Shirt:

15

Jeans:

60

Jacket:

80

Sweatshirt:

30

Hoodie:

40

Socks:15

Discount:

10

You will need to create the specified input file and then write a C++ program that reads data from the input file and stores the output in the file clothing_cost.dat. Calculate the total cost of the order and include a 7% sales tax. Also assume that the customer has a coupon that will discount the entire order by the percent listed in the input, this discount should be taken before taxes are added.

Your file output should follow this same format:

Total cost of all items: $240.00

List of items:

T-Shirt: $15.00

Jeans: $60.00

Jacket: $80.00

Sweatshirt: $30.00

Hoodie: $40.00

Socks: $15.00

Discount: 10%

Amount saved with discount: $24.00

Price after discount: $216.00

Taxes: $15.12

Total cost of order: $231.12

Make sure to format the output of decimal numbers to two decimal places.

Solution


#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
   // Declarations
   ifstream fileIn;
   ofstream fileOut;
   string title;
   double tshirt, jeans, jacket, sweatshirt, hoodie, socks,
           discount, discountSavings, discountedPrice, taxes,
           totalCost, resultCost;

   // Input file contents
   fileIn.open(\"clothing.dat\", ios::in);
   fileIn >> title >> tshirt >> title >> jeans >> title >> jacket >> title
   >> sweatshirt >> title >> hoodie >> title >> socks >> title >> discount;
   fileIn.close();

   // Calculations for overwrite
   totalCost = tshirt + jeans + jacket + sweatshirt + hoodie + socks;
   discount = discount/100;
   discountSavings = totalCost * discount;
   discountedPrice = totalCost - discountSavings;
   taxes = discountedPrice*0.07;
   resultCost = discountedPrice + taxes;
  
   // Output file contents
   fileOut.open(\"clothing_cost.dat\", ios::out);
   fileOut << fixed << showpoint << setprecision(2)
   << \"Total cost of all items: $\" << totalCost << endl << endl
   << \"List of items:\" << endl
   << \"T-Shirt: $\" << tshirt << endl
   << \"Jeans: $\" << jeans << endl
   << \"Jacket: $\" << jacket << endl
   << \"Sweatshirt: $\" << sweatshirt << endl
   << \"Hoodie: $\" << hoodie << endl
   << \"Socks: $\" << socks << endl << endl
   << \"Discount: \" << (int)(discount * 100) << \"%\" << endl << endl
   << \"Amount saved with discount: $\" << discountSavings << endl << endl
   << \"Price after discount: $\" << discountedPrice << endl
   << \"Taxes: $\" << taxes << endl
   << \"Total cost of order: $\" << resultCost << endl;
   fileOut.close();

   return 0;
}


clothing.dat

T-Shirt:
15
Jeans:
60
Jacket:
80
Sweatshirt:
30
Hoodie:
40
Socks:
15
Discount:
10

A retail clothing store uses software to compute total cost of items. This software also handles sales tax and any discounts that need to be applied to an order
A retail clothing store uses software to compute total cost of items. This software also handles sales tax and any discounts that need to be applied to an order
A retail clothing store uses software to compute total cost of items. This software also handles sales tax and any discounts that need to be applied to an order

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site