I have an assignment to implement a salesperson class.
Here is the layout I got from prof.
My questions are typed in red between function prototypes.

Any help is appreciated.
Thanks.

cClass Salesperson
{
public:
Salesperson(); //default constructor
// I know that a default constructor is suppose to set the values by default but how would I do this implementation for this constructor. I mean what would this constructor set the value for and how.


~Salesperson(); // destructor

Salesperson(double q1, q2, q3, q4);

void getsales();
// how would I use this function


void setsales(int quarter, double sales);
//And how would I use this function

void printsales();

void ReadFile();

void EditFile();

private:
double slaes[4];//quarterly sales figures
};

These are basic questions that should be explained in your text, and in your lessons.

In short, the default constructor will allocate the date member(s), sales[4] in this case, but will not initialize the array to any specific values. That would occur in a constructor that you create, such as the one you have with four doubles as parameters.

"get" functions normally provide a means for accessing the class's private data, while "set" functions give you the means to modify the private data.

Thanks, I actually figured out most of the stuff.
But I have some problem in my code. In the main(), I am trying to print the sales figure, but instead it is printing the address of the sales array. How can I resolve this without using pointers.

Once again,
Thanks.

My code

#include "stdafx.h"

//#ifndef Salesperson_H
//#define Salesperson_H
#include <iostream>
#include <iomanip>
using namespace std;


class Salesperson
{
public:
	Salesperson(); // default constructor 
	~Salesperson();//destructor;

	 Salesperson(double , double , double , double );//constructor 

	void getSales(); //function to get 4 sales figures from user

	void setsales(int , double );

	void printsales();

	void ReadFile();

	void EditFile();

private:
	double sales[4]; // array for quarterly sales figures.
	
};

Salesperson::Salesperson()
{
	sales [0] = 0.0;
	sales [1] = 0.0;
	sales [2] = 0.0;
	sales [3] = 0.0;
	
}

 Salesperson::Salesperson(double quart1, double quart2, double quart3, double quart4)
{
	sales [0] = quart1;
	sales [1] = quart2;
	sales [2] = quart3;
	sales [3] = quart4;

}

void Salesperson::getSales()
{
	int quarter;
	double sales;

	cout<<"Please input the the quarter number of the year."<<endl;
	cin>> quarter;

	cout<<"Please enter the sales of this quarter."<<endl;
	cin>>sales;

	setsales(quarter, sales);

	

	return;

}

void Salesperson::setsales(int quart, double sales)
{
	
	if(quart == 1) 
		sales[0] = sales;

	if(quart == 2)
		sales[1] = sales;
		
	if(quart == 3)
		sales[2] = sales;
		
	if(quart == 4)
		sales[3] = sales;
		sales= sales [0] + sales [1] + sales [2] + sales [3];

	return;
}

Salesperson::~Salesperson()
{}

void Salesperson::printsales()
{
	cout<<"The total annual sale of the year was: $"<<sales<<endl;

	return;
}

void ReadFile()
{
	cout<<"The file contents were: "<<endl;

	return;
}
void EditFile()
{
	cout<<"Please enter a sentence. You have a space for 80 characters."<<endl;
}





int main()
{
Salesperson s;



	return 0;
}

You need to keep things straight better.

void Salesperson::setsales(int quart, double sales)
{
	if(quart == 1) 
		sales[0] = sales;

	if(quart == 2)
		sales[1] = sales;
		
	if(quart == 3)
		sales[2] = sales;
		
	if(quart == 4)
		sales[3] = sales;
		sales= sales [0] + sales [1] + sales [2] + sales [3];

	return;
}

Using the same name for your parameter as the data member array should be causing a compile error, as the one will mask the other. You should rename the parameter - say, "new_sales".

Why are you adding all the quarterly sales values in this function?

Your printsales( ) function is doing exactly what you tell it, displaying the address of the array. If you want to see each quarter's sales amount, you need to display each element of the array one at a time - best with a nice little for loop. If, on the other hand, you want to display just a total value, you still need that for loop to add up the array elements. Figure out what it is you really want to do.

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.