Take any previous home assignment and modify it to save the

Take any previous home assignment and modify it to save the output it shows on the screen to save to a file as well. For example, the BMR program, you could write out the person\'s calories per day to a file named BMR.txt You should ask them for the filename as shown below: count

Solution

// C++ code determine tax and the total cost for the item and save it to output file

#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>

using namespace std;

int main ()
{
    string filename;
    cout << \"What is the filename to store to? \";
    cin >> filename;

    ofstream fin;
    fin.open(filename.c_str());
  
    if(!fin.is_open())
    {
        cout << \"could not open \" << filename << endl;
        return 0;
    }

    string ItemName;
    double unitPrice;
    double numberItemSold;
    double Subtotal;
    double tax;
    double shipping = 4.98;
    double total;

    cout << \"Enter Item name: \";
    cin >> ItemName;

    cout << \"Enter unit price: \";
    cin >> unitPrice;

    cout << \"Enter numbers of items sold: \";
    cin >> numberItemSold;

    Subtotal = unitPrice*numberItemSold;
    tax = Subtotal*8.25/100;
    total = Subtotal + tax + shipping;

    fin <<left<< setw(30) << \"Unit price: \" << unitPrice << endl;
    fin <<left<< setw(30) << \"Number of items sold: \" << numberItemSold << endl;
    fin <<left<< setw(30) << \"Subtotal: \" << Subtotal << endl;
    fin <<left<< setw(30) << \"tax: \" << tax << endl;
    fin <<left<< setw(30) << \"Shipping: \" << shipping << endl;
    fin << left<< setw(30) << \"Total: \" << total << endl;

    return 0;
}


/*
output:
What is the filename to store to? output.txt
Enter Item name: cookie
Enter unit price: 23
Enter numbers of items sold: 12


output.txt
Unit price:                   23
Number of items sold:         12
Subtotal:                     276
tax:                          22.77
Shipping:                     4.98
Total:                        303.75

*/

 Take any previous home assignment and modify it to save the output it shows on the screen to save to a file as well. For example, the BMR program, you could wr
 Take any previous home assignment and modify it to save the output it shows on the screen to save to a file as well. For example, the BMR program, you could wr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site