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

Locate the errors in the following code. You will notice, not every line will co

ID: 3561844 • Letter: L

Question

Locate the errors in the following code. You will notice, not every line will contain a mistake. Pay close attention to the line preceding it. Look out for uninitialized pointers, NULL pointers, pointers to deleted objects, and confusing pointers with objects. Implement a class person with the following fields: A pointer to the persons best friend A popularity counter that indicates how many people have this person as their best friend Write a program that reads in a list of names, allocates a new Peron for every one of them, and places them in a vector. Next, request the name of each best friend for every Person objects. Find the object matching the friend's name, and call a set_best_friend member function to update the pointer and counter. Lastly, print out every Person objects. Labeling the name, best friend, and popularity counter for all. Consider the following classes B and D: Determine the answer by hand, not by compiling and running the program. Implement a base class person. Derive classes Student and Professor from Person. Every Person has will have a name, and birthdate. Every student will have a major, and every professor will have an income. Write the class definitions, the constructors, and the member functions printQ for all classes.

Explanation / Answer

Part A:

2. p=5 is inappropriate way of initializing a value to the pointer.

6. Employee is not initiated before assigning a object ->salary=38000.

Part B:

include <iostream>
using namespace std;

class Person {
    char name[20];
    Person* bestfriend;
public:
    Person (char*,Person*);

};

Rectangle::Rectangle (char[] nm, char[] friend) {
int i=0;
strcpy(name,nm);
strcpy(bestfriend->name,friend);
}

int main () {
Person one ('Rex','Rock');
Person two ('qux','mill');
   return 0;
}

Part C:

Prints

B::B (-3)

D::D (3)

Part D:

// derived classes
#include <iostream>
using namespace std;

class Person {
protected:
    char name[20];
    char birthdate[20];
};

class Professor: public Person {
public:
    double income;
    Professor::Professor(void)
{
    cout << "Professor is being created" << endl;
}

};

class Student: public Person {
public:
    char Major[20];
        Student::Student(void)
{
    cout << "Student is being created" << endl;
}
};

int main () {
Person one;
Professor argl;
Student arg2;
return 0;
}

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