Suppose in the file named list NumberyourLastNametxt that st

Suppose in the file named list Number_yourLastName.txt that stores one string and S decimal numbers. For example: Liem 77.5 92.25 88.0 81.5 78.25 The retirement of this questoin asks for C++ code that opens the above file listNumber_yourLastName.txt, reads the string for the name and 5 numbers for tests\' scores and calculates the average of 5 numbers. Next, opens an output Me named \'averageScore_younastName.txt. writes the name and the average of S tests\' scores in the following format. Name = Liem Average = 83.5 Finally, closes file llstNumber_yourLastName.txt and file averageScore_yourLastName.txt To answer the above Question 2. one student wrote the fallowing lines of C++ code but the program is not complete and gets some errors. You should rewrite the following program so that it accomplishes what it is intended to do. Remember to close the Mes after finishing using namescase std; int main() {double scorel, secore2, secore3, score4, score5; sting name; ifstream infile; infile >> name; outfile. open (\" 1st ofNumber_yourLast/Name.txt); infile >> name; outile.open (\"list ofNumber_yourLast/Name.text\"); infile >> score1 >> score2>> score3 >> score4 >> score5; outfile

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

*/

 Suppose in the file named list Number_yourLastName.txt that stores one string and S decimal numbers. For example: Liem 77.5 92.25 88.0 81.5 78.25 The retiremen
 Suppose in the file named list Number_yourLastName.txt that stores one string and S decimal numbers. For example: Liem 77.5 92.25 88.0 81.5 78.25 The retiremen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site