You are on page 1of 6

OOP COURSE ASSIGNMENT#2

  
Program:
CODE:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct salesPersonRec
{
string ID;
double saleByQuarter[4];
double totalSale;
};
int intialize(salesPersonRec SalePersonRecList[], int size);
int process(salesPersonRec SalePersonRecList[], int size);
int SalebyQuarter(salesPersonRec SalePersonRecList[], int size, double
Totalsalebyquarter[], int size1);
int SalebyPerson(salesPersonRec SalePersonRecList[], int size);
void display(salesPersonRec SalePersonRecList[], int size, double TotalsalebyQuarter[],
int size1,string id, int quarter,double maxperson,double maxquarter);
double MaximumSalebyPerson(salesPersonRec SalePersonRecList[], int size, string& id);
double MaximumSalebyQuarter(double TotalsalebyQuarter[], int size,int& quater);
int main()
{
double maxperson, maxquarter;
string id = "0";
int quarter = 0;
salesPersonRec SalePersonRecList[6];
double totalSalebyquarter[4] = { 0 };
double totalSalebyperson[6] = { 0 };
intialize(SalePersonRecList, 6);
process(SalePersonRecList, 6);
SalebyQuarter(SalePersonRecList, 6, totalSalebyquarter, 4);
SalebyPerson(SalePersonRecList, 6);
maxperson = MaximumSalebyPerson(SalePersonRecList, 6,id);
maxquarter = MaximumSalebyQuarter(totalSalebyquarter, 4,quarter);
display(SalePersonRecList, 6, totalSalebyquarter,
4,id,quarter,maxperson,maxquarter);
cout << endl;
system("pause");
return 0;
}
int intialize(salesPersonRec SalePersonRecList[], int size)
{
ifstream file;
int i = 0;
file.open("ID.txt");
if (file.is_open())
{
while (!file.eof())
{
file >> SalePersonRecList[i].ID;
i++;

1|Page
}
}
else
cout << "The Id File not Found\n";
for (int i = 0; i < size; i++)
{
for (int j = 0; j < 4; j++)
{
SalePersonRecList[i].saleByQuarter[j] = 0;
}
SalePersonRecList[i].totalSale = 0;
}
return 0;
}
int process(salesPersonRec SalePersonRecList[], int size)
{
ifstream file;
int i = 0;
double month, sale, id;
string data;
file.open("Saledata.txt");
if (file.is_open())
{
while (!file.eof())
{
file >> data >> month >> sale;
for (int i = 0; i < size; i++)
{
if (data == SalePersonRecList[i].ID)
{
if (month >= 1 && month <= 3)
SalePersonRecList[i].saleByQuarter[0] =
SalePersonRecList[i].saleByQuarter[0] + sale;
else if (month >= 4 && month <= 6)
SalePersonRecList[i].saleByQuarter[1] =
SalePersonRecList[i].saleByQuarter[1] + sale;
else if (month >= 7 && month <= 9)
SalePersonRecList[i].saleByQuarter[2] =
SalePersonRecList[i].saleByQuarter[2] + sale;
else if (month >= 10 && month <= 12)
SalePersonRecList[i].saleByQuarter[3] =
SalePersonRecList[i].saleByQuarter[3] + sale;
}
}
}
}
else
cout << "The Id File not Found\n";
return 0;
}
int SalebyQuarter(salesPersonRec SalePersonRecList[], int size, double
Totalsalebyquarter[], int size1)
{
for (int j = 0; j < size1; j++)
{
for (int i = 0; i < size; i++)
{

2|Page
Totalsalebyquarter[j] = Totalsalebyquarter[j] +
SalePersonRecList[i].saleByQuarter[j];
}
}
return 0;
}
int SalebyPerson(salesPersonRec SalePersonRecList[], int size)
{
for (int j = 0; j < size; j++)
{
for (int i = 0; i < 4; i++)
{
SalePersonRecList[j].totalSale = SalePersonRecList[j].totalSale +
SalePersonRecList[j].saleByQuarter[i];
}
}
return 0;
}
void display(salesPersonRec SalePersonRecList[], int size,double TotalsalebyQuarter[],
int size1,string id,int quarter, double maxperson, double maxquarter)
{
cout << fixed << setprecision(2);
cout << " ----------------------Annual Sales Report------------------------\n\n";
cout << " __ID__________QT1________QT2________Qt3________Qt4________Total__\n";
for (int i = 0; i < size; i++)
{
cout << " "<< SalePersonRecList[i].ID << setw(14) <<
SalePersonRecList[i].saleByQuarter[0];
cout << setw(11) << SalePersonRecList[i].saleByQuarter[1] << setw(11);
cout << SalePersonRecList[i].saleByQuarter[2] << setw(11) <<
SalePersonRecList[i].saleByQuarter[3] << setw(13);
cout << SalePersonRecList[i].totalSale << endl;
}
cout << " Total" << setw(14);
for (int i = 0; i < size1; i++)
{
cout << TotalsalebyQuarter[i] << setw(11);
}
cout << endl << endl;
cout << " The maximum Sale by Saleperson: ID = " << id << ", Amount = $" <<
maxperson << endl;
cout << " The maximum Sale by Quarter: Quarter = " << quarter << ", Amount = $" <<
maxquarter << endl;
}
double MaximumSalebyPerson(salesPersonRec SalePersonRecList[], int size,string& id)
{
double max = SalePersonRecList[0].totalSale;
id = SalePersonRecList[0].ID;
for (int i = 1; i < size; i++)
{
if (SalePersonRecList[i].totalSale > max)
{
max = SalePersonRecList[i].totalSale;
id = SalePersonRecList[i].ID;
}
}
return max;
}

3|Page
double MaximumSalebyQuarter(double TotalsalebyQuarter[], int size,int& quarter)
{
double max = TotalsalebyQuarter[0];
quarter = 1;
for (int i = 1; i < size; i++)
{
if (TotalsalebyQuarter[i] > max)
{
max = TotalsalebyQuarter[i];
quarter = i + 1;
}
}
return max;
}

OUTPUT:

ID TEXT FILE FILE:

4|Page
SALE DATA TEXT FILE:

5|Page

You might also like