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

3. When you define a class in C++, and do not provide any constructor, then the

ID: 3708614 • Letter: 3

Question

3. When you define a class in C++, and do not provide any constructor, then the default constructor will be used. Please type in the following code, add necessary header files, compile and run the code, and a main function with a call to the operator << and answer the question based on your observation.

How does the default constructor initialize the member variables for us?

the int member variable:

the double member variable:

the  array variable:

the char variable:

class YourClassName

{

   public:

friend ostream & operator<< (ostream & outs, const YourClassName & o)

{

outs << o.value << endl;

outs << o.dvalue << endl;

for (int i=0; i<10; i++)

outs <<"a["<<i <<"]:" << o.a[i]<<endl;

outs << o.c << endl;

return outs;

}

private:

int value;

double dvalue;

int a[10];

char c;

};

Explanation / Answer

the int member variable: -1 the double member variable: 2.10148e-317 the array variable: a[0]:1 a[1]:0 a[2]:4254377 a[3]:0 a[4]:3 a[5]:0 a[6]:59 a[7]:0 a[8]:0 a[9]:0 the char variable: (Ascii value of 1) ?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote