Please help in C++

class smart
{
public :
void print () const ;
void set (int , int );
int sum ();
smart ();
smart (int , int );

private :
int x ;
int y ;
int secret ();
};

class superSmart : public smart
{
public :
void print () const ;
void set (int , int , int );
int manipulate ();
superSmart ();
superSmart (int , int , int );

private :
int z ;
};



a. Write the definition of the default constructor of smart so that the instance
variables of smart are initialized to 0 .
b. Write the definition of the default constructor of superSmart so that the
instance variables of superSmart are initialized to 0 .
c. Write the definition of the member function set of smart so that the instance
variables are initialized according to the parameters.
d. Write the definition of the member function sum of the class smart so that it
returns the sum of the instance variables.
e. Write the definition of the member function manipulate of the class superSmartso that it returns the (x + y)^z, that is, return x plus y to the power of z.
Can someone please explain to me what we have to do?
You can start by reading about constructors in the link I provided, then creating one that initializes x and y to 0.

Then a default constructor for superSmart that initializes z to 0.
Last edited on
is x and y private variables can i still set it to 0
Yes, private stuff can still be used inside the class, just not outside. Please take your time to read the link I gave you, it literally says this about private members after a few lines of words.

If you prefer people explaining it, you can always watch youtube videos about how classes work =)
Please tell me this correct for the part a

smart()

{
x=0;
y=0;
}
If you create the constructor within the class then yes that is correct, but you usually want to have the class in the .h file and the functions in the .cpp file - Watch this -
https://www.youtube.com/watch?v=NTip15BHVZc&list=PLAE85DE8440AA6B83&index=15
Thank you very much and the links you sent me was so helpful thank again
Topic archived. No new replies allowed.