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

Create a class named Employee that has three member variables: name – A string t

ID: 3769716 • Letter: C

Question

Create a class named Employee that has three member variables:

name – A string that stores the employee’s name

numDependents – An integer that tracks how many dependents the employee has

classDependents – an array of strings with the names of the employee’s dependents

Write corresponding constructors, as well as mutator and accessor functions for the class which includes the following:

A function that inputs all appropriate user values, including the class names.

A function that outputs the employee name and a list of his dependents

A destructor that releases all memory that has been allocated

Write a main function which tests all your functions.

Keyboard Shortcuts

Answer in C++

Explanation / Answer

#include<iostream>
#include<conio>
#include<string>
using namespace std;

class Employee
{
public:
   string name;
   int numDependents;
   string classDependents[3];

   Employee()
   {
       name="";
       numDependents=0;
       classDependents[]={""};
   }

   void set(string n, int nd, string cd1, string cd[])
   {
       strcpy(name,n);
       numDependents=nd;
       for(i=0;i<3;i++)
           strcpy(classDependents[i],cd[i]);
   }

   void print()
   {
       cout<<name<<endl;
       cout<<numDependents<<endl;
       for(i=0i<3;i++)
       {
           cout<<classDependents[i]<<endl;
       }
   }

   ~Employee()
   {
       cout<<"Bye";
   }
};


void main()
{
   string n="aaa";
   int nd=0;
   string cd[]={"bbb","ccc","ddd"};

   Employee o;
   o.set(n,nd,cd);
   o.print();
  
  
   getch();
}

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