I have been given an assignment to write a class to accomodate the following code:
int getMenuOption ();
int main ()
{
int option;
int id;
char name[80];
//create a Salesperson object and sets all 12 monthly sales to 0.
Salesperson sp;
cout << "Enter name: ";
cin.getline(name, 80);
cout << "Enter salesperson id: ";
cin >> id;
sp.setId(id); //set the id number for the sales person
sp.setName(name); // set the name of the sales person
sp.setSales(); //read 12 monthly sales figures
do
{
option = getMenuOption();
switch(option)
{
case 1: //display average sales
cout << "Average Sales: " << sp.averageSales() << endl;
break;
case 2: //display highest sales
cout << "Highest Sales: " << sp.highestSales() << endl;
break;
case 3: //display lowest sales
cout << "Lowest Sales:" << sp.lowestSales() << endl;
break;
case 4: //display total sales
cout << "Total Sales:" << sp.totalSales() << endl;
break;
case 5: //display the name and id
sp.displayInfo();
break;
case 6:
cout << "Exiting Program" << endl; break;
default: cout << "Error! Invalid Menu Option" << endl;
}
}while (option != 6);
return 0;
}
//Accepts: Nothing
//Purpose: Display the menu and prompt the user to enter a menu option
//Returns: The menu option chosen by the user
int getMenuOption ()
{
int option;
cout << "Salesperson Statistics Applications" << endl << endl;
cout << "1.Average Sales" << endl;
cout << "2.Highest Sales" << endl;
cout << "3.Lowest Sales" << endl;
cout << "4.Total Sales" << endl;
cout << "5.Salesperson information" << endl;
cout << "6.Exit Application" << endl << endl;
cout << "Enter option [1..6]:> ";
cin >> option;
return option;
}
I've only gotten this far
#include <iostream>
#include <string>
using namespace std;
class Salesperson
{
private:
char name[80];
int id;
int sale1;
int sale2;
int sale3;
int sale4;
int sale5;
int sale6;
int sale7;
int sale8;
int sale9;
int sale10;
int sale11;
int sale12;
public:
void setId(int);
void setName(char[80]);
void setSales();
int averageSales();
int highestSales();
int lowestSales();
int totalSales();
int displayInfo();
};//implentation section
void Salesperson ::setId(int id1)
{
id=id1;
}
void Salesperson ::setName(char name1[80])
{
for(int count=0;count<80;++count)
cout<<name[count];
}
void Salesperson ::setSales()
{
cout<<"Enter 12 sales figures:"<<endl;
cin>>sale1;
cin>>sale2;
cin>>sale3;
cin>>sale4;
cin>>sale5;
cin>>sale6;
cin>>sale7;
cin>>sale8;
cin>>sale9;
cin>>sale10;
cin>>sale11;
cin>>sale12;
}
int Salesperson ::averageSales()
{
return (sale1+sale2+sale3+sale4+sale5+sale6+sale7+sale8+sale9+sale10+sale11+sale12)/12;
}
int Salesperson ::highestSales()
{
return sale1;
}
int Salesperson ::displayInfo()
{
return sale2;
}
int Salesperson ::totalSales()
{
return (sale1+sale2+sale3+sale4+sale5+sale6+sale7+sale8+sale9+sale10+sale11+sale12);
}
int Salesperson ::lowestSales()
{
return sale4;
}
I need help with the display info function whichs displays the id and name along with the higest and lowest sales