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

Need help, I was struggling with this code. How do I compelet this code vectorsA

ID: 3834800 • Letter: N

Question

Need help, I was struggling with this code. How do I compelet this code vectorsAndClasses

/*This program demonstrates the use of vectors with classes, defines operator functions, uses the pointer defererencing (->) operator.*/

//Name

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;
class Employee
{
public:
    /*Place the default constructor declaration below */
    //
    void setName(string &_name){name=_name;}
    string getName() {return name;}
    void setID(string _id) {id = _id;}
  
    /*Fill in the code for getID */
    string getID(){/*   */}
    void setSupervisorName(string _name)
  
    {
        /*Set supervisor's name to _name. Remember: this is a pointer so you have to use the arrow pointer-deference operator */
      
        //
    }
  
  
    string getSupervisorName()
    {
        /*Return supervisor's name */
        //
    }
  
    void setSupervisor(Employee *_supervisor)
    {supervisor = _supervisor; }
  
    /*Create an Employee Operator as a friend function prototype */
    //
  
private:
    string name;
    string id;
  
    /*Define a pointer to an Employee type called supervisor */
    //
};

/*Define the default constructor definition */
//
{
    name = "";
    id = -1;
    supervisor = nullptr;
}

/*Define a the operator << function allowing Employee to be streamed. Remember to return ostream& */
//
{
  
    out <<"Name: " << _employee.getName() << endl;
    out <<"ID: " << _employee.getID()<<endl;
    out <<"Supervisor: " << _employee.getSupervisorName() << endl;
  
    return out;
}

/*Note that the input Employee function was not defined as a friend function to the Employee class, so you must use Mutator and Accessor functions*/

void inputEmployee(Employee &_employee)
{
    string employeeName, supervisorName, id;
    Employee * supervisor = new Employee;
    cout << "Employee Name: ";
  
    getline (cin, employeeName);
  
    /*Set the name for _employee to employeeName*/
    //
  
  
    cout <<"Employee ID: ";
    getline (cin, id);
    _employee.setID(id);
  
    cout <<"Supervisor Name: ";
    getline (cin, supervisorName);
  
    _employee.setSupervisor(supervisor);
    _employee.setSupervisorName(supervisorName);
  
}

/*Note: The ostream works for cout AND for ofstream objects*/
void printVector (ostream& out, vector<Employee> &employeeVector)
{
    for (int i=0; i < employeeVector.size(); i++)
    {
        out << employeeVector[i] <<endl <<endl;
    }
}

int main()
{
    vector <int> intVector;
  
    /* create a vector of Employees called employeeVector */
    //
    Employee employee1;
    char menu='z';
  
    ifstream infile("input.txt");
    ofstream outfile("output.txt");
  

    while (menu != 'e')
    {
        cout << "a. add employee"<<endl;
        cout << "b. print all employees to screen"<<endl;
        cout << "c. print all employees to file"<<endl;
        cout << "e. exit" << endl;
        cin >> menu;
      
        switch (menu)
        {
            case 'a':
                inputEmployee(employee1);
              
                /*add employee1 to the employee Vector */
                //
                break;
            case 'b':
                /*call the function printvector outputing to the monitor */
                //
                break;
              
            case 'c':
                /*call the function printvector outputing to the outfile */
                //
                break;
              
            case 'e':exit(0);
                break;
              
              
            default:break;
        }
      
    }
    return 0;
}                    

Explanation / Answer

Please find my implementation.

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
class Employee
{
public:
/*Place the default constructor declaration below */
//
Employee();
void setName(string &_name){name=_name;}
string getName() {return name;}
void setID(string _id) {id = _id;}
  
/*Fill in the code for getID */
string getID(){
return id;
}
void setSupervisorName(string _name)
  
{
/*Set supervisor's name to _name. Remember: this is a pointer so you have to use the arrow pointer-deference operator */
  
supervisor->name = _name;
}
  
  
string getSupervisorName()
{
/*Return supervisor's name */
return supervisor->name;
}
  
void setSupervisor(Employee *_supervisor)
{supervisor = _supervisor; }
  
/*Create an Employee Operator as a friend function prototype */
friend ostream &operator<<( ostream &output, Employee &e );
  
private:
string name;
string id;
  
/*Define a pointer to an Employee type called supervisor */
//
Employee *supervisor;
};
/*Define the default constructor definition */
Employee::Employee()
{
name = "";
id = -1;
supervisor = nullptr;
}
/*Define a the operator << function allowing Employee to be streamed. Remember to return ostream& */
ostream &operator<<( ostream &out, Employee &_employee)
{
  
out <<"Name: " << _employee.getName() << endl;
out <<"ID: " << _employee.getID()<<endl;
out <<"Supervisor: " << _employee.getSupervisorName() << endl;
  
return out;
}
/*Note that the input Employee function was not defined as a friend function to the Employee class, so you must use Mutator and Accessor functions*/
void inputEmployee(Employee &_employee)
{
string employeeName, supervisorName, id;
Employee * supervisor = new Employee;
cout << "Employee Name: ";
  
getline (cin, employeeName);
  
/*Set the name for _employee to employeeName*/
_employee.setName(employeeName);
  
  
cout <<"Employee ID: ";
getline (cin, id);
_employee.setID(id);
  
cout <<"Supervisor Name: ";
getline (cin, supervisorName);
  
_employee.setSupervisor(supervisor);
_employee.setSupervisorName(supervisorName);
  
}
/*Note: The ostream works for cout AND for ofstream objects*/
void printVector (ostream& out, vector<Employee> &employeeVector)
{
for (int i=0; i < employeeVector.size(); i++)
{
out << employeeVector[i] <<endl <<endl;
}
}
int main()
{
vector <int> intVector;
  
/* create a vector of Employees called employeeVector */
vector<Employee> employeeVector;
Employee employee1;
char menu='z';
  
ifstream infile("input.txt");
ofstream outfile("output.txt");
  
while (menu != 'e')
{
cout << "a. add employee"<<endl;
cout << "b. print all employees to screen"<<endl;
cout << "c. print all employees to file"<<endl;
cout << "e. exit" << endl;
cin >> menu;
  
switch (menu)
{
case 'a':
inputEmployee(employee1);
  
/*add employee1 to the employee Vector */
employeeVector.push_back(employee1);
break;
case 'b':
/*call the function printvector outputing to the monitor */
printVector(cout, employeeVector);
break;
  
case 'c':
/*call the function printvector outputing to the outfile */
printVector(outfile, employeeVector);
break;
  
case 'e':exit(0);
break;
  
  
default:break;
}
  
}
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