Question

The designer of a class C mentions to you that he needs to add a default...

The designer of a class C mentions to you that he needs to add a default constructor to C. Which of the following is almost certainly true? C has const data members The designer should write his own destructor for C C has const member functions It is not currently possible to declare an array of C The designer should write his own assignment operator for C. It is not currently possible to declare any variables of type C.

Which of the following is almost certainly true? (Can be as many selections as possible)

C has const data members

The designer should write his own destructor for C

C has const member functions

It is not currently possible to declare an array of C

The designer should write his own assignment operator for C.

It is not currently possible to declare any variables of type C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ques: Which of the following is almost certainly true? (Can be as many selections as possible)

Answer:

  • C has const data members

Reason: When a class has const data members, that const data member can only be initialized using a constructor (default constructor in this case) and there is no other way of doing that.
All other options do not depend upon the default constructor. So, the only option true is the first one.

Code to demonstrate how to initialize a const data member using a default constructor:-

class C{
private:
    const int a;
    
public:
    //Default constructor to initialize const data member a to 0
    C() : a(0) {}
};

If you remove the default constructor then you'll not be able to declare any object of class C.

Add a comment
Know the answer?
Add Answer to:
The designer of a class C mentions to you that he needs to add a default...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING C++ Consider class Thing t string secretName unsigned mschiefLevel:; public: ThingO ...) Thing( const Thing &t)(·.) // Assume these three // member functions const Thing &operator-(...

    USING C++ Consider class Thing t string secretName unsigned mschiefLevel:; public: ThingO ...) Thing( const Thing &t)(·.) // Assume these three // member functions const Thing &operator-(.. -ThingO are properly class CatInTheHat Thing thing_1; Thing thing 2; Thing "seuss; /points to an array of suessize Things unsigned suessize; public: There isn't enough info here to write this, so I'm not asking. CatInTheHat( const CatIn TheHat &cat); const CatInTheHat &operator-(const CatInTheHat &cat); CatInTheHat0; 5) Write the CatInTheHat copy constructor. (2 pts...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • The function should have a class name CPizza that will have three constructors (default, type, and...

    The function should have a class name CPizza that will have three constructors (default, type, and copyl, public functions to use and implement are noted for you in the starter kit, and private member variables (all which are allocated dynamically). The private member variables include the three different sizes of pizza (Large, Medium, and Small), cost, a bool delivery, name, and delivery fee. The prices of the pizzas' are $20. $15, and $10 for large, medium, and small respectively. The...

  • C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve...

    C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve very big integer calculations that are outside the limit of all available primitive data types. For example, factorial of 100 contains 158 digits in it so we can’t store it in any primitive data type available. We can store as large Integer as we want in it. Your goal is to overload the operators for a generic “BigInt” class. You will need to write...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

  • In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following...

    In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • 2. (50 marks) A string in C++ is simply an array of characters with the null...

    2. (50 marks) A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in <string.h> as well as I/O functions in <iostream>. With the addition of the STL (Standard Template Library), C++ now provides a string class. But for this assignment, you are to develop your own string class. This will give you a chance to develop and work with...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as...

    IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT