i need help with this assignment
i have this class and i need to implement the functions and the main
i've implemented it but i want to check if its right
and i have a problem in writing the main

#ifndef
#define
class GBook
{
   public:
      GBook();
      void inputGrades();
      void setCourseNo(long x);
      long getCourseNo()const;
      void displayMsg();
      int max(int x1,int x2,int x3);
      void displayReport();
   private:
      long CourseNo;
      int MaxValue;
};
#endif


//functions implementation

//function to input 3 grades
void GBook::inputGrades(int x1,int x2,int x3)
{
   grade1=x1;
   grade2=x2;
   grade3=x3;
}

//constructor
GBook::GBook()
{
   CourseNo=1001;
   MaxValue=0;
}

//set function
void GBook::setCourseNo(long x)
{
   CourseNo=x;
}

//get function
long GBook::getCourseNo()
{
   return CourseNo;
}

/*function to display  MSG and
to take course no from get function*/
void GBook::displayMsg()
{
   cout<<"welcome in the course no ";
   cout<<getCourseNo()<<endl;
}

//function to find max value from 3 values
int GBook::max(int x1,int x2,int x3)
{
   max=x1;
   if(x2>x1)
   max=x2;
   else if(x3>x2)
   max=x3;
}

/*function to call  all previous
funtions to be used in the main
void GBook::displayReport()
{
   setCourseNo(x);
   displayMsg();
   inputGrades(x1,x2,x3);
   max(x1,x2,x3);
}

//destructor
GBook::~GBook()
{

}

I have to write the main now and ask
the user to input 3 grades then call
only "displayReport" function not all the functions

>>and i have a problem in writing the main
If you really wrote the code you posted writing main() should be a breaze. So what is it about main() you can't (or won't) do ?

first i need to know if my implementation to the function is right
specially the destructor i don't know what to put in {}

about the main here is what i wrote

void main()
{
   int x1;
   int x2;
   int x3;

   cout<<"enter 1'st num";
   cin>>x1;
   cout<<endl;
   cout<<"enter 2'nd num";
   cin>>x2;
   cout<<endl;
   cout<<"enter 3'rd num";
   cin>>x3;
   cout<<endl;

//i want to call "displayReport" function i don't know how to do it

}

>first i need to know if my implementation to the function is right
Does it compile? Does it run? Does it produce the results you expect? Do you get the expected results for a large number of test cases? Those are the first questions you ask yourself to see if the implementation is correct.

>void main()
main returns int, always. Don't listen to anyone who tells you otherwise.

>>//i want to call "displayReport" function i don't know how to do it

First you have to create an object of the class you want to use, then you can call its method(s). I don't see that function doing anything except displaying a welcome message.

GBook book;
book.displayReport();

I made a few changes in the functions implementations to make it correct
thats the new implementation

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

/*#ifndef
#define*/
class GBook
{
   public:
      GBook();
      ~GBook();
      void inputGrades(int,int,int);
      void setCourseNo(long x);
      long getCourseNo()const;
      void displayMsg();
      int max(int x1,int x2,int x3);
      void displayReport();
   private:
      long CourseNo;
      int MaxValue;
};
//#endif

//functions implementation

//function to input 3 grades
void GBook::inputGrades(int x1,int x2,int x3)
{
   cout<<"input first grade";
   cin>>x1;
   cout<<endl;
   cout<<"input seconde  grade";
   cin>>x2;
   cout<<endl;
   cout<<"input third grade";
   cin>>x3;
   cout<<endl;
}

//constructor
GBook::GBook()
{
   CourseNo=1001;
   MaxValue=0;
}

//set function
void GBook::setCourseNo(long x)
{
   CourseNo=x;
}

//get function
long GBook::getCourseNo()const
{
   return CourseNo;
}

/*function to display  MSG and
to take course no from get function*/
void GBook::displayMsg()
{
   cout<<"welcome in the course no ";
   cout<<getCourseNo()<<endl;
}

//function to find max value from 3 values
int GBook::max(int x1,int x2,int x3)
{
   int max=x1;
   if(x2>max)
   max=x2;
   if(x3>max)
   max=x3;
   return max;
}

/* I had a problem in here i want to call all the functions (setCourseNo,displayMsg,inputGrades,max )
 in the "displayReport" function but it's full with errors so how can
I call functions in a function */ 
void GBook::displayReport()
{
   setCourseNo(x);
   displayMsg();
   inputGrades(x1,x2,x3);
   max(x1,x2,x3);
}

//destructor
GBook::~GBook()
{

}

/*here i want to call only one function "displayReport" since it already contain all other functions so I created an object and used it to call the function yet it didn't work so what 
did I do wrong */
int main()
{
   GBook book;

   cout<<book.displayReport()<<endl;

   getch();
   return 0;

}
class GBook
{
      // ...
      void inputGrades( int& ,int&, int& );
      // ....
      void displayReport( int course_number ) ;
      // ...
};
// ...
void GBook::inputGrades( int& x1, int& x2, int& x3 )
{
  // ...
}
// ...
void GBook::displayReport( int course_number )
{
   setCourseNo( course_number );
   displayMsg();
   int x1, x2, x3 ;
   inputGrades(x1,x2,x3);
   MaxValue = max(x1,x2,x3);
   cout << "max: " << MaxValue << '\n' ;
}
// ...
int main()
{
   GBook book;
   int cn ;
   cout << "course no.: " ;
   cin >> cn ;
   book.displayReport( cn ) ;
}

Thanks a lot for everyone for your help
I changed my program according to your
replies and it worked great so thank you

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.