Question
Below is my code. I have an error that I still have difficulty figuring out. Please explain and teach me the solution to fix it
Below is my code. I have an error that I still have difficulty figuring out. Please explain and teach me the solution to fix it specifically (e.g. changing which line in the code). Thank you!
main.cpp
/* Overloaded stream insertion operator
#include "Sales.h" #include
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
// 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
Sales.txt
13492785 2017 North, Jane; 1000 78534520 2012 South, Tim; 950 20192756 2017 East, Linda; 15000 19273458 2012 West, Paul; 5000 78520192 2017 Doe, Mary Jane; 5001 32278520 2012 Smith, Victor; 7995 14278520 2012 Johnson, Mary; 120 56192785 2017 Baker, Tom; 1300 88278529 2012 Newman, Diana; 1500 89278527 2012 Peterson, William; 14200 98278528 2012 Gaddis, Jim; 1200 99192785 2017 King, Laura; 1000 43278524 2012 McDonald, Ann; 2000 88288522 2013 Newman, Dan; 5500
newSales.txt
13491995 2015 Davis, Andrew; 9125 78531280 2014 Potter, Monica T.; 9125 22112756 2013 Lucas, George Paul; 9125 76573458 2011 Pan, Peter; 9125
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started