SlideShare a Scribd company logo
1 of 8
Download to read offline
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 <<
- used to display reports and write data to file.
Overloaded relational operator (<)
- used to sort the array in ascending order by name (insertion sort)
*/
#include "Sales.h"
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <string>
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 << "Please enter the input file's name: ";
getline(cin, fileName);
readData(fileName, salesArr, size);
insertSort(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;
}
// 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 < size; i++) {
for (int j = i + 1; j < size; j++) {
if (salesArr[j] < salesArr[i]) {
Sales temp(salesArr[i]);
salesArr[i] = salesArr[j];
salesArr[j] = temp;
}
}
}
}
double calcSalesAvg(Sales *salesArr, int size) {
double d = 0;
for (int i = 0; i < size; i++) {
d += (salesArr[i].getAmountSold());
}
return (double) d / size;
}
void displayOverAvg(Sales *salesArr, int size, double avg) {
cout << "Average Sales: " << avg << endl;
string nm ;
cout << "Salespeople with above average sales:" << endl;
for (int i = 0; i < size; i++) {
if (salesArr[i].getAmountSold() > avg) {
cout << salesArr[i];
}
}
}
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 < size; i++) {
ptr << salesArr[i];
}
ptr.close();
}
/*
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 << "Input file: " << fileName << " not found!" << endl;
exit(EXIT_FAILURE);
}
string line;
while (getline(in, line))
{
cout << line << endl;
}
in.close();
}
Sales.h
/*
Specification file for the Sales class
- Overloaded stream insertion operator (<<)
- Overloaded relational operator (<)
*/
#ifndef SALES_H
#define SALES_H
#include <string>
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 <
bool operator< (Sales &b);
// Overloaded <<
friend ostream& operator<< (ostream &out, Sales &b);
};
#endif
Sales.cpp
/*
Implementation file for the Sales class.
*/
#include "Sales.h"
#include <iostream>
#include <iomanip>
#include <string>
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::operator< (Sales &b) {
if (this->getName().compare(b.getName()) <= 0)
return true;
return false;
}
ostream& operator<<(ostream &out, Sales &b) {
out << setw(20) << left << b.getName();
out << setw(9) << right << b.getAmountSold();
out << setw(13) << right << rand()%500;
out << endl;
return out;
}
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 ( << ) and use it to display
reports and write data to file using the same format (see below). - Overload the relational
operator ( < ) and use it to sort the array in ascending order by name (insertion sort) This
program will create an array of 30 Sales objects and it will read data from an input file (Sales.txt)
into this array. It will sort the array in ascending order by name. Then it will calculate the
average of all sales people and display on the screen the average sale followed by the names of
the salespeople with above average sales, the amount sold and the amount earned. If the list is
empty, write "N/A" as shown below: Average Sales: $9125 Salespeople with above average
sales: N / A Finally, it will write to another file (salesReport.txt) a table as shown below: Display
the amount earned with 2 decimals (out setprecision(2) fixed; ). Assume that a name has at most
20 characters (for formatting). Prompt the user to enter the name of the input file (with
extension). Generate the name of the output file by adding the word "Report" to the input file's
name. If the input file name is sales.txt, the output file name will be salesReport.txt If the input
file name is newSales.txt, the output file name will be newSalesReport.txt Display the output
file's name as shown below: Program errors displayed here Exited with return code -6
(SIGABRT). terminate called after throwing an instance of 'std::invalid_argument' what (): stoi
Program output displayed here Please enter the input file's name:

More Related Content

Similar to Below is my code- I have an error that I still have difficulty figurin.pdf

STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASenthil Kanth
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfarjuncollection
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfPBIMINERADC
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATEIke Ellis
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
Database Management System - SQL Advanced Training
Database Management System - SQL Advanced TrainingDatabase Management System - SQL Advanced Training
Database Management System - SQL Advanced TrainingMoutasm Tamimi
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADataconomy Media
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMongoDB
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMongoDB
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfpasqualealvarez467
 
SQL Tips Calculate Running Totals.pptx
SQL Tips Calculate Running Totals.pptxSQL Tips Calculate Running Totals.pptx
SQL Tips Calculate Running Totals.pptxSelect Distinct Limited
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Charles Givre
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Reportnyin27
 
Brian Adams
Brian AdamsBrian Adams
Brian Adamsbrad817
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfinfo189835
 
power point presentation on object oriented programming functions concepts
power point presentation on object oriented programming functions conceptspower point presentation on object oriented programming functions concepts
power point presentation on object oriented programming functions conceptsbhargavi804095
 
A Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiA Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiGrowth Intelligence
 
How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)Maik Becker
 

Similar to Below is my code- I have an error that I still have difficulty figurin.pdf (20)

STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBA
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
 
Statistics.hpp
Statistics.hppStatistics.hpp
Statistics.hpp
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdf
 
Slides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATESlides for PUG 2018 - DAX CALCULATE
Slides for PUG 2018 - DAX CALCULATE
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
Database Management System - SQL Advanced Training
Database Management System - SQL Advanced TrainingDatabase Management System - SQL Advanced Training
Database Management System - SQL Advanced Training
 
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project A
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
 
I really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdfI really need help with this Assignment Please in C programming not .pdf
I really need help with this Assignment Please in C programming not .pdf
 
SQL Tips Calculate Running Totals.pptx
SQL Tips Calculate Running Totals.pptxSQL Tips Calculate Running Totals.pptx
SQL Tips Calculate Running Totals.pptx
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Report
 
Brian Adams
Brian AdamsBrian Adams
Brian Adams
 
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdfC++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
power point presentation on object oriented programming functions concepts
power point presentation on object oriented programming functions conceptspower point presentation on object oriented programming functions concepts
power point presentation on object oriented programming functions concepts
 
A Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiA Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with Luigi
 
How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)
 

More from armanuelraj

Briefly give the- Theoretical conceptual framework- Implications for f.pdf
Briefly give the- Theoretical conceptual framework- Implications for f.pdfBriefly give the- Theoretical conceptual framework- Implications for f.pdf
Briefly give the- Theoretical conceptual framework- Implications for f.pdfarmanuelraj
 
Briefly summarize the process of DNA replication using correct biologi.pdf
Briefly summarize the process of DNA replication using correct biologi.pdfBriefly summarize the process of DNA replication using correct biologi.pdf
Briefly summarize the process of DNA replication using correct biologi.pdfarmanuelraj
 
briefly explain three types of DBMS language namely - a- Date definiti.pdf
briefly explain three types of DBMS language namely - a- Date definiti.pdfbriefly explain three types of DBMS language namely - a- Date definiti.pdf
briefly explain three types of DBMS language namely - a- Date definiti.pdfarmanuelraj
 
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdf
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdfBriefly describe the change in the brown adipose tissue (BAT) mass and.pdf
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdfarmanuelraj
 
Bright Green environmentalism is unique in its emphasis on Question 17.pdf
Bright Green environmentalism is unique in its emphasis on Question 17.pdfBright Green environmentalism is unique in its emphasis on Question 17.pdf
Bright Green environmentalism is unique in its emphasis on Question 17.pdfarmanuelraj
 
Break down the word by drawing a line between Prefix (if present)- roo.pdf
Break down the word by drawing a line between Prefix (if present)- roo.pdfBreak down the word by drawing a line between Prefix (if present)- roo.pdf
Break down the word by drawing a line between Prefix (if present)- roo.pdfarmanuelraj
 
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdf
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdfBramble Corporation issued 111-000 shares of $19 par value- cumulative.pdf
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdfarmanuelraj
 
Bottom of Form The influence of social media is huge- How can Facebook.pdf
Bottom of Form The influence of social media is huge- How can Facebook.pdfBottom of Form The influence of social media is huge- How can Facebook.pdf
Bottom of Form The influence of social media is huge- How can Facebook.pdfarmanuelraj
 
Both roots of the quadratic equation x2+x+ can take all values from -1.pdf
Both roots of the quadratic equation x2+x+ can take all values from -1.pdfBoth roots of the quadratic equation x2+x+ can take all values from -1.pdf
Both roots of the quadratic equation x2+x+ can take all values from -1.pdfarmanuelraj
 
Both eukaryotic and prokaryotic viruses have the essential function of.pdf
Both eukaryotic and prokaryotic viruses have the essential function of.pdfBoth eukaryotic and prokaryotic viruses have the essential function of.pdf
Both eukaryotic and prokaryotic viruses have the essential function of.pdfarmanuelraj
 
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdf
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdfBONUS (5 points) Write the equations for the standard error of ^j- Exp.pdf
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdfarmanuelraj
 
blank 1 market - accounting -replacement blank 2 net -free - operatin.pdf
blank 1 market - accounting -replacement blank 2  net -free - operatin.pdfblank 1 market - accounting -replacement blank 2  net -free - operatin.pdf
blank 1 market - accounting -replacement blank 2 net -free - operatin.pdfarmanuelraj
 
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdf
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdfBlack body- vestigial wings and brown eyes are mutations in Drosophila.pdf
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdfarmanuelraj
 
Bob budgets $24 a week for entertainment- He splits his time between g.pdf
Bob budgets $24 a week for entertainment- He splits his time between g.pdfBob budgets $24 a week for entertainment- He splits his time between g.pdf
Bob budgets $24 a week for entertainment- He splits his time between g.pdfarmanuelraj
 
BMI is the only factor used when determining the effect of fat on risk.pdf
BMI is the only factor used when determining the effect of fat on risk.pdfBMI is the only factor used when determining the effect of fat on risk.pdf
BMI is the only factor used when determining the effect of fat on risk.pdfarmanuelraj
 
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdf
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdfBlood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdf
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdfarmanuelraj
 
Blood Tracings The drawings can be simple lines but should show locat.pdf
Blood Tracings  The drawings can be simple lines but should show locat.pdfBlood Tracings  The drawings can be simple lines but should show locat.pdf
Blood Tracings The drawings can be simple lines but should show locat.pdfarmanuelraj
 
Blood is made up of two broad types of cells (red Blood Cells and whit.pdf
Blood is made up of two broad types of cells (red Blood Cells and whit.pdfBlood is made up of two broad types of cells (red Blood Cells and whit.pdf
Blood is made up of two broad types of cells (red Blood Cells and whit.pdfarmanuelraj
 
Blockehain is being taiked about in almost every industry as a disrupt.pdf
Blockehain is being taiked about in almost every industry as a disrupt.pdfBlockehain is being taiked about in almost every industry as a disrupt.pdf
Blockehain is being taiked about in almost every industry as a disrupt.pdfarmanuelraj
 
Blocking refers to the idea that the variability in a variable can be.pdf
Blocking refers to the idea that the variability in a variable can be.pdfBlocking refers to the idea that the variability in a variable can be.pdf
Blocking refers to the idea that the variability in a variable can be.pdfarmanuelraj
 

More from armanuelraj (20)

Briefly give the- Theoretical conceptual framework- Implications for f.pdf
Briefly give the- Theoretical conceptual framework- Implications for f.pdfBriefly give the- Theoretical conceptual framework- Implications for f.pdf
Briefly give the- Theoretical conceptual framework- Implications for f.pdf
 
Briefly summarize the process of DNA replication using correct biologi.pdf
Briefly summarize the process of DNA replication using correct biologi.pdfBriefly summarize the process of DNA replication using correct biologi.pdf
Briefly summarize the process of DNA replication using correct biologi.pdf
 
briefly explain three types of DBMS language namely - a- Date definiti.pdf
briefly explain three types of DBMS language namely - a- Date definiti.pdfbriefly explain three types of DBMS language namely - a- Date definiti.pdf
briefly explain three types of DBMS language namely - a- Date definiti.pdf
 
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdf
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdfBriefly describe the change in the brown adipose tissue (BAT) mass and.pdf
Briefly describe the change in the brown adipose tissue (BAT) mass and.pdf
 
Bright Green environmentalism is unique in its emphasis on Question 17.pdf
Bright Green environmentalism is unique in its emphasis on Question 17.pdfBright Green environmentalism is unique in its emphasis on Question 17.pdf
Bright Green environmentalism is unique in its emphasis on Question 17.pdf
 
Break down the word by drawing a line between Prefix (if present)- roo.pdf
Break down the word by drawing a line between Prefix (if present)- roo.pdfBreak down the word by drawing a line between Prefix (if present)- roo.pdf
Break down the word by drawing a line between Prefix (if present)- roo.pdf
 
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdf
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdfBramble Corporation issued 111-000 shares of $19 par value- cumulative.pdf
Bramble Corporation issued 111-000 shares of $19 par value- cumulative.pdf
 
Bottom of Form The influence of social media is huge- How can Facebook.pdf
Bottom of Form The influence of social media is huge- How can Facebook.pdfBottom of Form The influence of social media is huge- How can Facebook.pdf
Bottom of Form The influence of social media is huge- How can Facebook.pdf
 
Both roots of the quadratic equation x2+x+ can take all values from -1.pdf
Both roots of the quadratic equation x2+x+ can take all values from -1.pdfBoth roots of the quadratic equation x2+x+ can take all values from -1.pdf
Both roots of the quadratic equation x2+x+ can take all values from -1.pdf
 
Both eukaryotic and prokaryotic viruses have the essential function of.pdf
Both eukaryotic and prokaryotic viruses have the essential function of.pdfBoth eukaryotic and prokaryotic viruses have the essential function of.pdf
Both eukaryotic and prokaryotic viruses have the essential function of.pdf
 
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdf
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdfBONUS (5 points) Write the equations for the standard error of ^j- Exp.pdf
BONUS (5 points) Write the equations for the standard error of ^j- Exp.pdf
 
blank 1 market - accounting -replacement blank 2 net -free - operatin.pdf
blank 1 market - accounting -replacement blank 2  net -free - operatin.pdfblank 1 market - accounting -replacement blank 2  net -free - operatin.pdf
blank 1 market - accounting -replacement blank 2 net -free - operatin.pdf
 
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdf
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdfBlack body- vestigial wings and brown eyes are mutations in Drosophila.pdf
Black body- vestigial wings and brown eyes are mutations in Drosophila.pdf
 
Bob budgets $24 a week for entertainment- He splits his time between g.pdf
Bob budgets $24 a week for entertainment- He splits his time between g.pdfBob budgets $24 a week for entertainment- He splits his time between g.pdf
Bob budgets $24 a week for entertainment- He splits his time between g.pdf
 
BMI is the only factor used when determining the effect of fat on risk.pdf
BMI is the only factor used when determining the effect of fat on risk.pdfBMI is the only factor used when determining the effect of fat on risk.pdf
BMI is the only factor used when determining the effect of fat on risk.pdf
 
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdf
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdfBlood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdf
Blood will agglutinate and hemolyze if--- 1- If the recipient and dono.pdf
 
Blood Tracings The drawings can be simple lines but should show locat.pdf
Blood Tracings  The drawings can be simple lines but should show locat.pdfBlood Tracings  The drawings can be simple lines but should show locat.pdf
Blood Tracings The drawings can be simple lines but should show locat.pdf
 
Blood is made up of two broad types of cells (red Blood Cells and whit.pdf
Blood is made up of two broad types of cells (red Blood Cells and whit.pdfBlood is made up of two broad types of cells (red Blood Cells and whit.pdf
Blood is made up of two broad types of cells (red Blood Cells and whit.pdf
 
Blockehain is being taiked about in almost every industry as a disrupt.pdf
Blockehain is being taiked about in almost every industry as a disrupt.pdfBlockehain is being taiked about in almost every industry as a disrupt.pdf
Blockehain is being taiked about in almost every industry as a disrupt.pdf
 
Blocking refers to the idea that the variability in a variable can be.pdf
Blocking refers to the idea that the variability in a variable can be.pdfBlocking refers to the idea that the variability in a variable can be.pdf
Blocking refers to the idea that the variability in a variable can be.pdf
 

Recently uploaded

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Below is my code- I have an error that I still have difficulty figurin.pdf

  • 1. 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 << - used to display reports and write data to file. Overloaded relational operator (<) - used to sort the array in ascending order by name (insertion sort) */ #include "Sales.h" #include <iostream> #include <sstream> #include <iomanip> #include <fstream> #include <string> 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 << "Please enter the input file's name: "; getline(cin, fileName); readData(fileName, salesArr, size); insertSort(salesArr, size); double avg = calcSalesAvg(salesArr, size); displayOverAvg(salesArr, size, avg); writeReport(salesArr, size, fileName);
  • 2. string option; cout << "Show report?" << endl; getline(cin, option); if (option == "Y" || option == "y") showReport(fileName); 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++; }
  • 3. 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 < size; i++) { for (int j = i + 1; j < size; j++) { if (salesArr[j] < salesArr[i]) { Sales temp(salesArr[i]); salesArr[i] = salesArr[j]; salesArr[j] = temp; } } } } double calcSalesAvg(Sales *salesArr, int size) { double d = 0; for (int i = 0; i < size; i++) { d += (salesArr[i].getAmountSold()); } return (double) d / size; } void displayOverAvg(Sales *salesArr, int size, double avg) { cout << "Average Sales: " << avg << endl; string nm ; cout << "Salespeople with above average sales:" << endl; for (int i = 0; i < size; i++) { if (salesArr[i].getAmountSold() > avg) { cout << salesArr[i]; } } } void writeReport(Sales *salesArr, int size, string fileName) { fileName.insert(fileName.find("."), "Report"); fstream ptr; ptr.open(fileName, ios::out);
  • 4. for (int i = 0; i < size; i++) { ptr << salesArr[i]; } ptr.close(); } /* 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 << "Input file: " << fileName << " not found!" << endl; exit(EXIT_FAILURE); } string line; while (getline(in, line)) { cout << line << endl; } in.close(); } Sales.h /* Specification file for the Sales class - Overloaded stream insertion operator (<<) - Overloaded relational operator (<) */ #ifndef SALES_H #define SALES_H #include <string> using std::ostream; using std::string; // ^^^ avoid adding using namespace std; class Sales { private: int id;
  • 5. 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 < bool operator< (Sales &b); // Overloaded << friend ostream& operator<< (ostream &out, Sales &b); }; #endif Sales.cpp /* Implementation file for the Sales class. */ #include "Sales.h" #include <iostream> #include <iomanip> #include <string> using namespace std; // default constructor; setting everything to 0 or "" Sales::Sales() { id = 0;
  • 6. 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; }
  • 7. int Sales::getAmountSold() { return amountSold; } void Sales::setAmountSold(int a) { amountSold = a; } bool Sales::operator< (Sales &b) { if (this->getName().compare(b.getName()) <= 0) return true; return false; } ostream& operator<<(ostream &out, Sales &b) { out << setw(20) << left << b.getName(); out << setw(9) << right << b.getAmountSold(); out << setw(13) << right << rand()%500; out << endl; return out; } 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
  • 8. 7.15 Lab: Sales Class - Array of Sales objects (overload operators) Reuse the sales class with the following modifications: - Overload the stream insertion operator ( << ) and use it to display reports and write data to file using the same format (see below). - Overload the relational operator ( < ) and use it to sort the array in ascending order by name (insertion sort) This program will create an array of 30 Sales objects and it will read data from an input file (Sales.txt) into this array. It will sort the array in ascending order by name. Then it will calculate the average of all sales people and display on the screen the average sale followed by the names of the salespeople with above average sales, the amount sold and the amount earned. If the list is empty, write "N/A" as shown below: Average Sales: $9125 Salespeople with above average sales: N / A Finally, it will write to another file (salesReport.txt) a table as shown below: Display the amount earned with 2 decimals (out setprecision(2) fixed; ). Assume that a name has at most 20 characters (for formatting). Prompt the user to enter the name of the input file (with extension). Generate the name of the output file by adding the word "Report" to the input file's name. If the input file name is sales.txt, the output file name will be salesReport.txt If the input file name is newSales.txt, the output file name will be newSalesReport.txt Display the output file's name as shown below: Program errors displayed here Exited with return code -6 (SIGABRT). terminate called after throwing an instance of 'std::invalid_argument' what (): stoi Program output displayed here Please enter the input file's name: