Suppose in the file named list NumberyourLastNametxt that st
Solution
// Question 2
// C++ code open file and and determine average and write to file
#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main ()
{
double score1,score2,score3,score4,score5;
string name;
ifstream infile;
infile.open(\"listNumber_yourLastName.txt\");
infile >> name;
infile >> score1 >> score2 >> score3>> score4 >> score5;
ofstream outfile;
outfile.open(\"averageScore_yourLastName.txt\");
outfile << \"Name = \" << name << endl;
outfile << \"Average = \" << (score1+score2+score3+score4+score5)/5 << endl;
return 0;
}
/*
listNumber_yourLastName.txt
Liem 77.5 92.25 88.0 81.5 78.25
averageScore_yourLastName.txt
Name = Liem
Average = 83.5
*/
// Question 3
// C++ code determine tax and the total cost
#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
using namespace std;
int main ()
{
ofstream outfile;
outfile.open(\"SummaryOfSale_yourLastname.txt\");
string itmeName;
double unitPrice;
double numberItemSold;
double Subtotal;
double tax;
double shipping = 4.98;
double total;
cout << \"Enter Itm name: \";
cin >> itmeName;
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;
outfile <<left<< setw(30) << \"Item name \" << \"Adjustable Table\ \";
outfile <<left<< setw(30) << \"Unit price: \" << unitPrice << endl;
outfile <<left<< setw(30) << \"Number of items sold: \" << numberItemSold << endl;
outfile <<left<< setw(30) << \"Subtotal: \" << Subtotal << endl;
outfile <<left<< setw(30) << \"tax: \" << tax << endl;
outfile <<left<< setw(30) << \"Shipping: \" << shipping << endl;
outfile << left<< setw(30) << \"Total: \" << total << endl;
return 0;
}
/*
output:
Enter Itm name: cookies
Enter unit price: 69.99
Enter numbers of items sold: 25
SummaryOfSale_yourLastname.txt
Item name Adjustable Table
Unit price: 69.99
Number of items sold: 25
Subtotal: 1749.75
tax: 144.354
Shipping: 4.98
Total: 1899.08
*/

