I used a basic input file to input 3 rows of sales data like 300 300 300. I must use link lists and pointers and at the same time use a class to input my data and output it. I need a average fuction that will add the code and do a average,and output everything to the oupt file. I have ran into a block any help would be appreciated.
Code:
#include <iostream>
#include <cstddef>
#include <iomanip>
#include <fstream>
using namespace std;
class TotalSales
{
public:
/*************************************************************************************
overloaded operators +, -, /, and * declared to calculate 2 numbers
***********************************************************************************/
friend TotalSales operator +(const TotalSales& sale1, const TotalSales&
sale2);
friend TotalSales operator -(const TotalSales& sale1, const TotalSales&
sale2);
friend TotalSales operator *(const TotalSales& sale1, const TotalSales&
sale2);
friend TotalSales operator /(const TotalSales& sale1, int denominator);
/*************************************************************************************
Overloaded operators << and >>, inputs and outputs number totals
***********************************************************************************/
friend istream& operator >>(istream& ins, TotalSales& sale1);
friend ostream& operator <<(ostream& outs, TotalSales& sale2);
/*************************************************************************************
Declared constructor that intializes the member variable and intializes it
to zero
***********************************************************************************/
TotalSales(double jan, double feb, double mar, double
totals1);//constructor intializes member variables
TotalSales (); //constructor intialzes member variables to zero
/*************************************************************************************
Accessor function returns jantotals, febtotals. martotals, totals.
***********************************************************************************/
double get_jantotals();
double get_febtotals();
double get_martotals();
double get_totals();
/*************************************************************************************
Declared the member variables in private
***********************************************************************************/
private:
double jantotals;
double martotals;
double febtotals;
double totals;
double average();
};
int quarterly();
typedef struct Node* lref, lnode;
typedef struct Node
{
double data;
lref next;
}Node;
total_average(lref& head);
int main()
{
/******************************************************************************
outputs the file
************************************************************************/
ifstream fins;
ofstream fout;
/*********************************************************************
gives the array a variable name
******************************************************************/
lref head;
head = NULL;
lref end;
lref tail;
end = new Node;
if (head == NULL)
{
head = end;
}
else
{
tail= end;
end->next = new Node;
}
//int array_size;
//lref size;
//size = new Node[array_size];
TotalSales amount; //************ declares the objects being used with
the class
fins.open("ins.txt"); //opens the input file
if (fins.fail())
{
cout <<"Input file failed." << endl;
exit(1);
}
fout.open("outs.txt"); //opens the output file
if (fout.fail()) // will output a error if the output file fails
{
cout << "Output file failed." << endl;
exit(1);
}
/**********************************************************
gives the decimal point and sets it to 2
******************************************************/
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);
/***********************************************************
outputs the average and total info to the output file for display
**************************************************************/
fout << "January" <<setw(15) << "February" << setw(15) << "March" <<
setw(15) << "Average" << endl;
do
{
double average(lref head);
fins >> head->data;
fout << head->data;
}
while (! fins.eof());
fins.close();
fout.close(); //closes the output file
delete head, end, tail;
system("pause"); // pauses the screen after the program runs
return 0;
}