Question: PLEASE ANSWER THANK YOU!!! Read the following code, and write a comment in the code to mark the point in the program's execution that constructors
PLEASE ANSWER THANK YOU!!!
Read the following code, and write a comment in the code to mark the point in the program's execution that constructors of the Student class is called, and which constructor is called. Also write comment next to the line of code where destructor is called.
class Student {
public:
friend Student OutputDuplicate (Student obj);
Student (); //default constructor
Student (string n);
Student (Student obj); //copy constructor
...
private:
string name;
...
};
Student OutputDuplicate (Student obj)
{
cout <<"Student record:";
cout < Student * anotherObj = new Student ("Jane Smith"); *anotherObj = obj; return *anotherObj; } int main() { Student a, b ("John Smith"); b = OutputDuplicate (a); } 3. When you define a class, 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. 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["< outs << o.c << endl; return outs; } private: int value; double dvalue; int a[10]; char c; }; // Todo: How does the default constructor initialize the member variables for us? // int member variable: // double member variable: // array variable // char variable: // 4 For which of the following classes do we need to implement the big three, i.e., copy constructor, destructor, and overload assignment operator? Explain briey why. Note that all member variables for the class is listed, but member functions are omitted. (a) class Student class Student { // used for student public: ... private: string name; Date birthday; }; (b) class AbsenceDates class AbsenceDates { // used to keep track absence dates for a student... public: .. private: Date * ptrDateArray; // points to an array of Date int length; // the capacity of array that ptrDateArray points to }; (c) class HomeworkGrades class HomeworkGrades { public: ... private: double grades[10]; int length; //number of grades entered into the array grades };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
