C++ questions, class. Make sure all answers are in C++ not C C++ questions, clas
ID: 3562972 • Letter: C
Question
C++ questions, class.
Make sure all answers are in C++ not C
C++ questions, class Make sure all answers are in C++ not C 1. Why should the attributes of a class be private? 2. Can a Time class definition that includes both of the following constructors: Time( int h = 0, int m = 0, int s = 0); Time(); be used to default construct a time Time Object? If not, explain why. 3. Write a statement that creates a pointer to a Circle object and instantiates the Circle object being pointed to . Use dynamic memory and initialize the object to the value 5.Explanation / Answer
1)Attribute of class Should be private. by making them private it is accessible only to class members thus it prevent misuse, abuse, or just someone doing something wrong. it's good design. It gives you, the more control over how it is used.
2)If the caller were to call Tme(), the compiler would not be able to disambiguate whether the user wanted Time(int h=0;int m=0;int s=0) with default values or Time(). thus the following definition of constructor will not work.
Time();
Time(int h=0;int m=0;int s=0);
will not work;
also same is true for method overloading.
3) Suppose there is a class Circle and has a constructor Circle(double Rad);
then we can instantiate it as follow
Circle * circle=new Circle(5); //a pointer to circle is created then a new object is created dynamically and its address is assigned to circle pointer;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.