Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with my questions ASAP. thank you. Bonus Question Why do you thin

ID: 3626777 • Letter: P

Question

Please help me with my questions ASAP. thank you.

Bonus Question
Why do you think initializing a class member variable during declaration is not permitted?

4. Consider the following statements:
class dog: public animal
{
.....
};
In this declaration, which class is the base class, and which class is the derived class?

8. Consider the following statements:
class yClass class xClass: public yClass
{ {
public: public:
void one (); void one ();
void two (int, int); xClass ();
yClass (); private:
private: int z;
int a;
int b; };
};
suppose the following statements are in a user program (client code):
yClass y;
xClass x;
a. the private members of yClass are public members of xClass. true or false?
b. Mark the following statements as valid or invalid. If a statement is invalid, explain why.
i. void yClass::one()
{
cout<< a+b<< endl;
}
ii. y.a=15;
x.b=30;
iii. void xClass::one();
{
a=10;
b=15;
z=30;
cout<< a+b+z<<endl;
}
iv. cout<<y.a<<" "<<y.b<<" "<<x.z<<endl;

12. Consider the following class definition:
class first
{
public:
void setX ();
void print const ();
protected:
int y;
void setY (int a);
private:
int x;
};
Suppose that class second is derived from class first using the statement:
class second: private first
Determine which members of class first are private, protected, and public in class second.

14. Assume the declaration of Exercise 12. Suppose that class fourth is derived from class first using the statement:
class fourth: public first
Determine which members of class first are private, protected, and public in class fourth.

18. What is the output of the following C++ program?
#include <iostream>
#include <string>
using namespace std;
class baseClass;
{
public:
void print () const;
baseClass (string s = " ", int a =0);
//Postcondition: str = s; x= a;
protected:
int x;
private:
string str;
};
class derivedClass: public baseClass
{
public:
void print() const;
derivedClass (string s = " ", int a = 0, int b = 0);
// Postcondition: str = s; x = a; y = b;
private:
int y;
};
int main ()
{
baseClass baseObject ("This is the base class", 2);
derivedClass derivedObject ("DDDDDD", 3,7);

baseObject.print();
derivedObject.print();

return 0;
}
void baseClass::print() const
{
cout<<x<<" "<<str<<endl;
}
baseClass::baseClass (string s, int a)
{
str=s;
x=a;
}
void derivedClass::print() const
{
cout<<"Derived Class:" << y<< endl;
baseClass::print();
}
derivedClass::derivedClass(string s, int a, int b)
:baseClass("Hello Base", a+b)
{
y = b;
}


Please help me with all 6 of those questions thank you.

Explanation / Answer

the bonus question from my opinion i think coz u don`t allocate memory for the class when u declare it unless u declared an object of the class so when the compiler compile he will be confused where to save the value of the variable coz there is no memory allocated for it Q(4) base animal derived dog Q(8) false (b) i- valid ii- invalid coz the variables a and b are private in the class Yclass iii-invalid coz the variables a and b are private in the class Yclass and can not be accessed out side the class unless u used the functions in Yclass iv-invalid coz the variables a and b are private in the class Yclass and z is private too Q(12) i will give u this to understand it better in the derived class i.e in the functions of it u can access the public and protected members no matter what type of inheritance exists but the difference can happen in the main and this is what happen if the inheritance is private u can not access any variable of the base class in the main if the inheritance is protected u can not access any variable of the base class in the main if the inheritance is public u can access the public variable of the base class in the main not the protected nor the private one and the answer here public: void setX (); void print const (); protected: int y; void setY (int a); private: int x; in the main u can not access any of them Q(14) public: void setX (); void print const (); protected: int y; void setY (int a); private: int x; in the main u can access only void setX (); void print const (); Q(18) 2 This is the base class Derived class:7 10 Hello Base