Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Practice Questions Classes & Objects Can a class data type include variables?   o  Yes   o  No Can a class data type include functions?   o  Yes   o  No Variables declared in a class data type are called ______________________

Practice Questions Classes & Objects Can a class data type include variables?   o  Yes   o  No Can a class data type include functions?   o  Yes   o  No Variables declared in a class data type are called ______________________

Computer Science

Practice Questions

Classes & Objects

  1. Can a class data type include variables?   o  Yes   o  No
  2. Can a class data type include functions?   o  Yes   o  No
  3. Variables declared in a class data type are called ______________________.
  4. Functions declared in a class data type are called______________________.
  5. _____________ is using variables and functions as a single data type.
  6. A member function of a class whose name is the same as that of the class is called __________. Its purpose is ____________________.
  7. A variable whose type is a class is called ________________.
  8. ______________ is called when an object of a class is created.
  9. The name of a constructor of a class data type named Employee is _________________.
  10. The return of a constructor of a class data type is __________________.
  11. The constructor of a class data type without parameter variables is called ___________.
  12. When a class does not define its constructor, the compiler creates _____________________.  In this case, the values of the data members of the object are _________________.
  13. (T/F) A constructor of a class can be overloaded.

 

  1. (T/F) A destructor of a class can be overloaded.

 

  1. Suppose that NodeS is a struct type and NodeC is a class type and both data types contain a variable of int type named entry. In addition, the NodeC has the entry under its private section.

Write a code segment of main() that creates an instance of each data type and assigns a value to the entry.

 

  1. In each of the following code, write the prototype of a constructor that is called and complete each line.

new Employee;

new Employee(10);

 

  1. What is (are) the difference between struct and class in C++? How does it make an impact on main()?

 

  1. The keyword, private and public, in the class declaration are called ____________.

 

  1. What is the difference between private members and public members?
  2. Can a public member function of a class call a private member function of the same class?
  3. Can a private member function of a class call a public member function of the same class?
  4. Your program consists of Employee.h, Employee.cpp and main.cpp to enable a separate compilation. Should Employee.cpp be included in main.cpp? Why/Why not?

 

  1. ___________________ is implicitly called when an object is out of scope and its purpose is typically ___________________.
  2. The keyword this can be used in any member function of a class. T/F?
  3. The value of this is _______________________________________________.
  4. How is it possible to use the keyword this? Who makes it work and how?
  5. What is an instance member function and a static member function of a class? How do they differ from each other? Write a code segment to call each.
  6. A static variable is located in the stack of the memory. T/F?
  7. A static variable of a class can be accessed by both instance and static member function. T/F?
  8. A setter/manipulator of a class requires an argument. T/F?
  9. A getter/accessor of a class has void as the return type. T/F?
  10. How and where do you initialize a static variable named size of a class named Employee?
  11. How does main() call a static member function, get_size() of the Employee class?
  12. If you have a class named Person, which of the following correctly declare a constructor in the class definition?
    1. Person::Person();
    2. Person();
    3. init();
    4. Person void Person();
    5. self();

 

  1. In a of the above question, :: is called ___________________ and its purpose is ____________________.
  2. Given the following class definition and the following header of a member function, which is the correct way to output the private data?

 

class Person

{

public:

            void print(ostream& out);

private:

int age;

float weight;

int id;

};

 

void Person::print(ostream& out)

{

            //what goes here?

}

    1. out << person.age << person.weight << person.id;
    2. out << person;
    3. out << age << weight << id;
    4. print(person);

 

  1. Given the following class definition, what is missing?

class Item

{

public:

            Item(int, float);

            static int get_size() const;

            float get_cost() const;

            void set_size(int);

            void set_cost(float);

private:

            static int size;

            float cost;

};

 

    1. nothing
    2. a default constructor
    3. accessor functions
    4. mutator functions

 

 

 

 

 

  1. Given the following class definition, how would you declare an object of the class, so that the object automatically called the default constructor?

 

class Item

{

public:

            Item();

             Item(int, float);

            static int get_size() const;

            float get_cost() const;

            void set_size(int);

            void set_cost(float);

private:

            static int size;

            float cost;

};

    1. Item() myItem;
    2. Item    myItem(1, 0.0);
    3. Item    myItem;
    4. Item     myItem();
    5. You can not do this

 

 

  1. Given the following class, what would be the best declaration for a mutator function that allows the user of the class to change the age?

 

class Wine

{

private:

           int age;

           float cost;

public:

           Wine();

           int get_age();

           float get_cost();

};

    1. int get_age(int newAge);
    2. Wine();
    3. void set_age();
    4. void set_age(int newAge);

 

 

  1. Given the following class, what would be the best prototype for a constructor that would allow the user to initialize the object with an initial age and cost?

class Wine

{

private:

           int age;

           float cost;

public:

           Wine();

           int get_age();

           float get_cost();

};

    1. int get_age(int);
    2. Wine();
    3. Wine(int);
    4. Wine(int, float);

 

 

 

 

 

  1. Given the following class and object declaration, how would you print out the age and cost of a bottle of wine?

 

class Wine

{

public: 

            Wine();

            int get_age();

            double get_cost();

private:

            int age;

            double cost;

}

 

Wine bottle;

 

    1. cout << bottle;
    2. cout << Wine.age, Wine.cost;
    3. cout << bottle.get_age() << bottle.get_cost();
    4. cout << bottle.get_age << bottle.get_cost;
    5. cout << bottle.age << bottle.cost;

 

  1. What is the sequence of the constructor and destructor calls of the following program?

 

int main() {

            ClassA  obj1;

             ClassB  obj2;

            return 0;

}

 

  1. What is the sequence of the constructor and destructor calls of the following program? What will be in the stack and heap of the virtual address space of the program?

int main() {

            ClassA  obj;

             ClassA* p = new ClassA;

            delete p;

            return 0;

}

 

 

  1. Write a synax to declare a const member function named print in the classA that does not take any argument and does not return a value.

 

  1. What does the keyword const describe or specify about a member function of a class?

 

 

  1. A project consists of classA, classB, and main.cpp and main() uses both classA andB. However, classA or classB does not use the other. Write a makefile for this project.

 

 

  1. In Q44, what does the role a colon (:) in the makefile?  What should come after a colon?

 

  1. In Q44, suppose you created the executable file. Now, you have changed classA.cpp. When you execute make, what commands will be displayed on the console?

 

 

  1. In Q44, why do you need to include ClassA.h in ClassA.cpp?

 

 

  1. What is the fundamental difference between an object file and an executable file?

 

 

  1. Compilation is the process to combine multiple object files and produce an executable file. T/F?

 

  1. ___________________ is the process to combine multiple object files and produce an executable file. T/F?

 

 

  1. The identifier used in the #ifndef directive should be
    1. the name of the class in upper case letters
    2. Your name in upper case letters
    3. The file name in uppercase letters (with an _ instead of a .)
    4. whatever you want it to be

 

  1. We use the #ifndef, #define, and #endif
  1. to prevent multiple definitions of a class
  2. when we use separate files
  3. whenever we use a class
  4. none of the above
  5. A and B

 

  1. Which file name will end in a .h?
      1. Implementation
      2. Application
      3. All input files
      4. Interface File
      5. A and B

 

  1. Which file name will end in a .cpp?
  1. Implementation File
  2. Application File
  3. All input files
  4. Interface File
  5. A and B

 

  1. If you have a class defined in separate files, and change the way a member function is defined (the body of the function), which files need to be re-compiled?
  1. The interface
  2. The application
  3. The Implementation
  4. All files
  5. B and C

 

  1. Compilation is ___________________________________________________________________.

 

 

  1. _____________ allows multiple functions or member functions of a class to use the same function name as long as their _________________ are different.

 

  1. The signature of a function in C++ is uniquely determined by ________________, ______________, and __________________. Return type may be/may not be a part of the signature of a function, depending on what compiler is used.

 

  1. A variable that is declared within a function, whether it is regular or a member of a class/struct is ______________ to the ____________ and the memory that is occupied by the variable is deleted when ______________________.

 

Option 1

Low Cost Option
Download this past answer in few clicks

18.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE