Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is my code. I have an error that I have difficulty figuring out. Please explain and teach me how to fix it. Thank you!

image text in transcribed

image text in transcribed

image text in transcribedBelow is my code. I have an error that I have difficulty figuring out. Please explain and teach me how to fix it. Thank you!

image text in transcribed

main.cpp

/* Overloaded stream insertion operator

#include "Sales.h" #include #include #include #include #include using namespace std;

const int MAX_SIZE = 30;

/* Write your code here: declare the function you are going to call in this program */ void readData(string fileName, Sales *salesArr, int &size); void insertSort(Sales *salesArr, int size); double calcSalesAvg(Sales *salesArr, int size); void displayOverAvg(Sales *salesArr, int size, double avg); void writeReport(Sales *salesArr, int size, string fileName); void showReport(string fileName);

int main() { Sales salesArr[MAX_SIZE]; int size = 0; string fileName; cout

return 0; }

// function definitions void readData(string fileName, Sales *salesArr, int &size) { string temp; int i = 0;

fstream ptr; ptr.open(fileName, ios::in); while (getline(ptr, temp)) { size++; stringstream chk(temp); string t2; int id, year, amountSold; string fname, lname;

int j = 0; while (getline(chk, t2, ' ')) { if (j == 0) { id = stoi(t2); } if (j == 1) { year = stoi(t2); } if (j == 2) { fname = t2; } if (j == 3) { lname = t2; } if (j == 4) { amountSold = stoi(t2); } j++; } string gg = fname + " " + lname; gg[gg.size() - 1] = 0; Sales ss(id, year, gg, amountSold); salesArr[i] = ss; i++; } ptr.close(); }

void insertSort(Sales *salesArr, int size) { for (int i = 0; i

double calcSalesAvg(Sales *salesArr, int size) { double d = 0;

for (int i = 0; i

void displayOverAvg(Sales *salesArr, int size, double avg) { cout avg) { cout

void writeReport(Sales *salesArr, int size, string fileName) { fileName.insert(fileName.find("."), "Report"); fstream ptr; ptr.open(fileName, ios::out);

for (int i = 0; i

/* This function receives the name of a file and displays its contents to the screen. */ void showReport(string fileName) { fileName.insert(fileName.find("."), "Report"); ifstream in(fileName); if (in.fail()) { cout

Sales.h

/* Specification file for the Sales class - Overloaded stream insertion operator (

#ifndef SALES_H #define SALES_H #include

using std::ostream; using std::string; // ^^^ avoid adding using namespace std;

class Sales { private: int id; int year; string name; int amountSold; public: // constructors Sales(); Sales(int i, int y, string n, int a); Sales(Sales &s); // getters int getId(); int getYear(); string getName(); int getAmountSold(); // setters void setId(int); void setYear(int); void setName(string); void setAmountSold(int); // overloaded operators // Overloaded

Sales.cpp

/* Implementation file for the Sales class. */

#include "Sales.h" #include #include #include using namespace std;

// default constructor; setting everything to 0 or "" Sales::Sales() { id = 0; year = 0; name = ""; amountSold = 0; }

// overloaded constructor; setting the variables according to the parameters Sales::Sales(int i, int y, string n, int a) { id = i ; year = y; name = n; amountSold = a; }

Sales::Sales(Sales &s) { id = s.getId(); year = s.getYear(); name = s.getName(); amountSold = s.getAmountSold(); }

// getter and setter int Sales::getId() { return id; }

void Sales::setId(int i) { id = i; }

int Sales::getYear() { return year; }

void Sales::setYear(int y) { year = y; }

string Sales::getName() { return name; }

void Sales::setName(string n) { name = n; }

int Sales::getAmountSold() { return amountSold; }

void Sales::setAmountSold(int a) { amountSold = a; }

bool Sales::operatorgetName().compare(b.getName())

ostream& operator 7.15 Lab: Sales Class - Array of Sales objects (overload operators) Reuse the sales class with the following modifications: - Overload the stream insertion operator (

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

16.1 Components of a Time Series

Answered: 1 week ago

Question

4. Are there any disadvantages?

Answered: 1 week ago

Question

3. What are the main benefits of using more information technology?

Answered: 1 week ago

Question

start to review and develop your employability skills

Answered: 1 week ago