#ifndef SALES_H #define SALES_H #include using std:: string; class Sales { private: /* Write your code here */ string id; int year; string name; int amountSold; public: // constructors /* Write your code here */ //default contructors Sales (); //overloaded cóntructors Sales (string id, int year, string name, int amountSold) // setters /* Write your code here */ void setId (string givenId); void setYear (int givenYear); void setName (string givenName); void setAmount (int givenAmount); // getters /* Write your code here */ string getId(); int getYear (); string getName(); int getAmount(); // other functions /* Write your code here */ void display() const; double detAmountEarned() const; double detCommissionPercent() const; #endif

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The average amount Sold function is not run as expect. Please fix it.

The input file: sales.txt 

header in picture. It is over 5000 char. I can't copy.

13492785 2017 Jane North; 1000    
78534520 2012 Tim South; 950
20192756 2017 Linda East; 15000    
19273458 2012 Paul West; 5000
78520192 2017 Mary Jane Doe; 5001    
32278520 2012 Victor Smith; 7995
14278520 2012 Mary Johnson; 120
56192785 2017 Tom Baker; 1300    
88278529 2012 Diana Newman; 1500
89278527 2012 William Peterson; 14200
98278528 2012 Jim Gaddis; 1200
99192785 2017 Laura King; 1000    
43278524 2012 Ann McDonald; 2000

The output expect: in picture.

#include "Sales.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

const int MAX_SIZE = 30;

void readData(string fileName, Sales salesArr[], int n);
double calcSalesAvg(Sales salesArr[], int n);
void displayOverAvg(Sales salesArr[], int n, double avg);
void writeReport(Sales salesArr[], int n, string fileName);
void showReport(string fileName);

int main()
{
    Sales salesArr[MAX_SIZE];
    int size = 0; 
    string fileName;
    cout << "Please enter the input file's name: ";
    getline(cin, fileName);
    readData(fileName, salesArr, size);
    
    double avg = calcSalesAvg(salesArr, size);
    displayOverAvg(salesArr, size, avg);
    writeReport(salesArr, size, fileName);
    
    string option;
    cout << "Show report?" << endl;
    getline(cin, option);
    if (option == "Y" || option == "y") 
       showReport(fileName);

    return 0;
}

void readData(string fileName, Sales salesArr[], int n) {
   ifstream inFile;
   inFile.open(fileName);
   if (!inFile) {
      cout << "Input file: " << fileName << " not found!" << endl;
      exit (101);
   }
   
   string line;
   n = 0;

   if (inFile.is_open()) {
      while (getline(inFile, line)) {
      stringstream ss(line);
      string id;
      ss >> id;
      int year;
      ss >> year;
      string name;
      getline(ss, name, ';');

      int amountSold;      
      ss >> amountSold;
      salesArr[n].setId(id);
      salesArr[n].setYear(year);
      salesArr[n].setName(name);
      salesArr[n].setAmount(amountSold);
      n++;
      }
   }
   
   inFile.close();

}

double calcSalesAvg(Sales salesArr[], int n) {
   double sum = 0;
   for (int i = 0; i < n; i++) {
      sum += salesArr[i].getAmount();
   }
      return (sum / n);

}

void displayOverAvg(Sales salesArr[], int n, double avg) {
   cout << "Average Sales: " << fixed << setprecision(2) << avg << endl;
   cout << "Salespeople with above average sales:" << endl;
   int count = 0;
   for (int i = 0; i < n; i++) {
      if (salesArr[i].getAmount() > avg) {
         cout << salesArr[i].getName() << "($" << salesArr[i].getAmount() << ")" << endl;
         count++;
      }
   }
   if (count == 0)
      cout << "N/A" << endl;
}

void writeReport(Sales salesArr[], int n, string fileName) {
  string outfileName;
  outfileName.insert(fileName.find("."), "Report");
  ofstream out(outfileName);
  out << "Sales Report\n"
       << setw(20) << left << "==================== =============\n"
       << setw(20) << left << "Name" << " " << setw(9) << right << "Amount Earned\n"
       << setw(20) << left << "==================== =============\n";
  out << fixed << setprecision(2);
  for (int i = 0; i < n; i++) {
      out << setw(20) << left << salesArr[i].getName() << " ";
      out << setw(9) << right << salesArr[i].getAmount() << endl;
  }
   out << setw(20) << left << "==================== =============\n"
       << "Number of salespeople: " << n << endl; 
    cout << "Report saved in: " << outfileName << endl;
 }

void showReport(string fileName){
   fileName.insert(fileName.find("."), "Report");
   ifstream in(fileName);
   if (in.fail()){
        cout << "Input file: " << fileName << " not found!" << endl;
        exit(EXIT_FAILURE);
   }
   string line;
   while (getline(in, line)){
      cout << line << endl;
   }
   in.close();
}

 

sales.txt
Input
Y
Please enter the input file's name: Average Sales: -nan
Your output
Salespeople with above average sales:
N/A
Please enter the input file's name: Average Sales: $4328.15
Salespeople with above average sales:
Linda East ($15000) 4
Paul West ($5000) e
Mary Jane Doe ($5001) 4
victor Smith ($7995) 4
William Peterson ($14200) e
Report saved in: salesReport.txtd
Show report?e
Sales Reporte
Name
Amount Earned
Jane North
30.004
Expected output
Tim South
28.504
Linda East
900.004
Paul West
225.004
Mary Jane Doe
262.554
Victor Smith
419.744
Mary Johnson
3.604
Tom Baker
58.504
Diana Ne wman
67.504
William Peterson
852.004
Jim Gaddis
54.004
Laura King
30.004
Ann McDonald
90.004
Number of salespeople: 134
Transcribed Image Text:sales.txt Input Y Please enter the input file's name: Average Sales: -nan Your output Salespeople with above average sales: N/A Please enter the input file's name: Average Sales: $4328.15 Salespeople with above average sales: Linda East ($15000) 4 Paul West ($5000) e Mary Jane Doe ($5001) 4 victor Smith ($7995) 4 William Peterson ($14200) e Report saved in: salesReport.txtd Show report?e Sales Reporte Name Amount Earned Jane North 30.004 Expected output Tim South 28.504 Linda East 900.004 Paul West 225.004 Mary Jane Doe 262.554 Victor Smith 419.744 Mary Johnson 3.604 Tom Baker 58.504 Diana Ne wman 67.504 William Peterson 852.004 Jim Gaddis 54.004 Laura King 30.004 Ann McDonald 90.004 Number of salespeople: 134
#ifndef SALES_H
#define SALES_H
#include <string>
using std:: string;
class Sales
{
private:
/* Write your code here */
string id;
int year;
string namej
int amountSold;
public:
// constructors
/* Write your code here */
//default contructors
Sales ();
//overloaded cóntructors
Sales (string id, int year, string name, int amountSold);
// setters
/* Write your code here */
void setId (string givenId);
void setYear (int givenYear);
void setName (string givenName);
void setAmount (int givenAmount);
// getters
/* Write your code here */
string getId();
int getYear()3
string getName ();
int getAmount();
// other functions
/* Write your code here */
void display() const;
double detAmountEarned() const;
double detCommissionPercent() const;
};
#endif
Transcribed Image Text:#ifndef SALES_H #define SALES_H #include <string> using std:: string; class Sales { private: /* Write your code here */ string id; int year; string namej int amountSold; public: // constructors /* Write your code here */ //default contructors Sales (); //overloaded cóntructors Sales (string id, int year, string name, int amountSold); // setters /* Write your code here */ void setId (string givenId); void setYear (int givenYear); void setName (string givenName); void setAmount (int givenAmount); // getters /* Write your code here */ string getId(); int getYear()3 string getName (); int getAmount(); // other functions /* Write your code here */ void display() const; double detAmountEarned() const; double detCommissionPercent() const; }; #endif
Expert Solution
Step 1

Here, I have to write a C++ program to the above question.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education