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

Question 1 What if anything does a destructor return a pointer to the class the

ID: 3833914 • Letter: Q

Question

Question 1

What if anything does a destructor return

a pointer to the class

the object of the class

status code stating that the class was destructed properly

destructors return nothing

Question 2

What should you do with data fields of your class that represent attributes of a real world object ?

Make them all public always

Always make them private, provide accessors and/or mutators depending on Use cases that access those objects

Just never make them public and never provided accessors and mutators ever.

Make them private, provide accessors and/or mutators depending on need, BUT move them to public if needed

Question 3

How would you decide to make a class method public or private or a friend function ?

Never make a class method public

Always make a class method public

Make a method public if it is part of an action of a use case and needs therefore to be in the public interface of the object to be invokable.

Make the method public in case theres any possibility that someone may want to use it

Question 4

Make the interface public and invariant - the implementation pluggable and variable

True

False

Question 5

Given an arbitrary definition of a class named Object as abstract data type - if a designer wanted to use an associative container like an std::map of the form std::map< Object, int* > - state and explain what important property must be defined for the class Object for it to be usable in the std::map as shown.

Question 6

State what are the 2 problems in the following code (2pts)

Provide a solution for each problem so that the code compiles and runs correctly by adding to this code (3pts)

// ----------------- Quiz question ----------------

#include <iostream>
#include <set>
#include <string>
#include <ctime>

using std::string;

class Employee
{
public:
    Employee(const int& n) : m_eid(n) {}
    ~Employee() {}
    int getEmpId() const
    {
        return m_eid;
    }
private:
    int m_eid;
};

int main(int argc, char* argv[])
{
    using std::cout;
    using std::endl;
    using std::set;

    set mySet;
    srand(time(NULL));

    unsigned int x = 0;
    while (x < 1000)
    {
        Employee emp( rand() % 1000 + 1 );
        mySet.insert( emp );
        x++;
    }
   
    return 0;
}

a pointer to the class

the object of the class

status code stating that the class was destructed properly

destructors return nothing

Explanation / Answer

HI, I have answered first 4 Questions.

Please repost others in separate post.

Please let me know in case of any issue in first 4.


Q1.
   Ans: destructors return nothing

   A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters.

Q2.
   Ans: Make them private, provide accessors and/or mutators depending on need, BUT move them to public if needed

   It is always good to encapsulate your class attrivutes with accessor and mutators. Sometimes some attributes can be public based on need

Q3.
   Ans:    Make a method public if it is part of an action of a use case and needs therefore to be in
   the public interface of the object to be invokable.

Q4.
   True

   Interface only provides the abstract methods and constant variables

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