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

This is just begging to be made into an array:

int sale1;
int sale2;
int sale3;
int sale4;
int sale5;
int sale6;
int sale7;
int sale8;
int sale9;
int sale10;
int sale11;
int sale12;

And please use code tags.

I know but arrays are harder I tried that but wouldn't I have to change the program I was given? I am not supposed to modify that.

I know but arrays are harder

I find they make things much simpler.

class Salesperson
{
   string name;
   int id;
   int sale[12];
public:
   void setId(int);
   void setName(char[80]);
   void setSales();
   int averageSales();
   int highestSales();
   int lowestSales();
   int totalSales();
   int displayInfo();
};//implentation section

This lends itself easily to something like this.

void Salesperson ::setSales()
{
   cout << "Enter " << sizeof sale / sizeof *sale << " sales figures:" << endl;
   for ( size_t i = 0; i < sizeof sale / sizeof *sale; ++i )
   {
      cin >> sale[i];
   }
}

int Salesperson ::totalSales()
{
   int sum = 0;
   for ( size_t i = 0; i < sizeof sale / sizeof *sale; ++i )
   {
      sum += sale[i];
   }
   return sum;
}

int Salesperson ::averageSales()
{
   return totalSales() / (sizeof sale / sizeof *sale);
}

int Salesperson ::highestSales()
{
   int high = numeric_limits<int>::min();
   for ( size_t i = 0; i < sizeof sale / sizeof *sale; ++i )
   {
      if ( high < sale[i] )
      {
         high = sale[i];
      }
   }
   return high;
}

int Salesperson ::displayInfo()
{
   cout << "name = " << name << '\n';
   cout << "id   = " << id   << '\n';
   for ( size_t i = 0; i < sizeof sale / sizeof *sale; ++i )
   {
      cout << "sale[" << i << "] = " << sale[i] << '\n';
   }
}

I tried that but wouldn't I have to change the program I was given? I am not supposed to modify that.

And no, nothing in main or getMenuOption is touched.

int high = numeric_limits<int>::min();
please explain I don't think we've done this yet can it aso be used to find the lowest

setSales cannot take parameters

int high = numeric_limits<int>::min();
please explain I don't think we've done this yet can it aso be used to find the lowest

Well, yeah, what I've posted is a little cryptic because this is homework. It's partly to show you how, but a lot to get you to think, too. Use what you've already done, then. (Probably initialize high to the value of the first element of the array.)

What this does is initialize high to the lowest possible integer value.

setSales cannot take parameters

Okay...???

what about displaying the id and name?

what about displaying the id and name?

What about them?

can I display both the name and id in the diaplayInfo() function? Whe I treid displayin the id before I didn't get anything I am not very comfortable with arrays how do I display the contents?

can I display both the name and id in the diaplayInfo() function? Whe I treid displayin the id before I didn't get anything I am not very comfortable with arrays how do I display the contents?

Pretty much just like I've shown for name and id. For the array, if you insist on doing it the hard way, change the sale[0] notation to its equivalent sale1 notation and unroll the loop (that you will no longer be using).

Why not post your latest code when you've made updates. Then it will be easier to see what's in your head or on your computer. [edit]On second thought, maybe not; the thought of what it would look like without arrays frightens me.

right now i'm so confused i don't think you'd like to see the mess I've made now nothing works not even the total sales

int Salesperson ::displayInfo()
{
   cout << "name = " << name << '\n';
   cout << "id   = " << id   << '\n';
   for ( size_t i = 0; i < sizeof sale / sizeof *sale; ++i )
   {
      cout << "sale[" << i << "] = " << sale[i] << '\n';
   }
   return 0;
}

Becomes...

int Salesperson ::displayInfo()
{
   cout << "name   = " << name   << '\n';
   cout << "id     = " << id     << '\n';
   cout << "sale1  = " << sale1  << '\n';
   cout << "sale2  = " << sale2  << '\n';
   // ...
   cout << "sale12 = " << sale12 << '\n';
   return 0;
}

thx for the help I'll try starting over using the sale array I still don't think I understand how to find the highest and lowest sale using an array

thx for the help I'll try starting over using the sale array I still don't think I understand how to find the highest and lowest sale using an array

Good. To help unconfuse you for this, you are probably expected to use 12 instead of sizeof sale / sizeof *sale.

And I've given a couple of hints of the min/max code. In your head or on paper how would you do it? Look at the first number that's the new high. Loop through the remaining numbers: if the current one you are looking at is bigger, that becomes the new high.

what about min() do I have to define this or does
high=sale[0]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.