using namespace std;

class product 
    int code;
    char name[20];
    double price;
int instock;
double soldperyear[12];
    void setproduct(int c , char n[],double p,int i)
    void peryear(int i)
    for ( i=1;i<=12;i++)
void setcode(int c)
void setname(char n[])

strncpy(name, n,19);
void setprice(double p)
price = p> 0.0?p:0.0;
void setinstock(int i)
int getcode()
{ return code;}
char * getname()
return name;
double getprice()
return price;
int getstock()
    return instock;
void increment(int inc)
    instock=instock +inc ;
void decrement(int ins,int month)
else cout<<" not enough products in stock "<<endl;
int total (){
int total =0;
for (int i=1;i<=12;i++)
total +=soldperyear[i];
return total ;

void print() {

    cout<<" Product: "<<endl;
    cout<<"code :"<<getcode()<<endl;
    cout<<"Name : "<<getname()<<endl;
    cout<<"price: "<<getprice()<<endl;
    cout<<"sold per year : " <<total()<<endl;
    cout<<" In stock : " <<getstock()<<endl;


product::product(int c, char n[], double p, int i){
  setproduct( c ,  n, p, i);

void main()


Create a class product with the following data members: 

   Code – The product’s code
The valid values are any number between 2500 and 2750
(Defaults to 2500) 

   Name - The product’s name. Ex. “Japanese Corner” or “Rustic Table”…. 
(string of 20 characters. Defaults to “New Product”) 

   Price - The product’s price 
A double value representing the product’s price. The valid values should be greater than 0.0. (Defaults to 0.0) 

   SoldPerYear – A 12 elements array of double that saves the sales per month over the span of a year. (The elements’ values must default to 0) 

   InStock – The number of items available (Defaults to 0)

And the following member functions: 
   A constructor with default arguments for Code, Name, Price and InStock
   Set functions with integrity checks for Code, Name, Price and InStock
   Get functions for Code, Name, Price and InStock
   A member function that increments InStock by a certain value. 
   A member function that decrements InStock by a certain value while it increments one of the elements of SoldPerYear.  Make sure that the value is less than or equal to Available; if not display an error message.
   A member function that calculates the total sales for the year.
   A print function to print all attributes of a product. 

Write a program to test your class by: 
   Creating two objects, a pointer and a reference. 
   Using the two objects, pointer and reference test all the member functions of your class 

Saying you need help, tells us nothing. Specify what kind of help you need please.

lol guys i told u i need help in the main at 

    Using the two objects, pointer and reference test all the member functions of your class 

lol guys i told u i need help in the main at

Using the two objects, pointer and reference test all the member functions of your class

Actually, you didn't; you simply copied the assignment statement with no information of where you needed help. In any case, you'll need to be more specific than this if we're going to be able to help you with it. What aspect of writing the test code has you troubled?

Are you uncertain how to test the class functions? We can give some advice on the matter, but we cannot write the tests for you. Realistically, it seems straightforward enough, the only real problem is that you'd need to test it in the two cases of a reference and of a pointer, which means using the local member notation for the former and the member indirection notation for the latter. Were you explained these notations clearly, and do you see why they differ?

BTW, in C++ the main() function always is of type int, and has to have a return value of either zero or some error code. Always, without exception. While it was permissible in earlier versions of the C standard (in order to accomodate some non-standard operating systems), it has never been acceptable in C++, even pre-standard. Your compiler should be warning you about this, and the fact that it isn't is a sign that it isn't a standards-compliant compiler.

lol are you sure you know c++ for real ?? cause the main can also be void and in this case i need it void ! but dont worry i just solved the problem thanks for ur help !

Trust me, while your compiler may accept void main(), and your instructor may have claimed it is acceptable, the standard does not. I would direct you to this C and C++ FAQ and this essay for clarification on the subject. The point is that in C++, the main() function must explicitly return a status code to the operating system, no exceptions, and if a compiler allows you to declare main() as void, it is a fault in the compiler, not a feature of the language.

In current c++ compilers, main() must return an int, NOT void. That is deprecated, and will generate errors or warnings with any recent (since 1999 or so) c++ compiler.