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

In C++ complete the following with an implementation file header file and source

ID: 3722290 • Letter: I

Question

In C++ complete the following with an implementation file header file and source file. You are asked to write a program that reads this input file and separate faculty from students then prints the output of each category to a separate output file. To keep track with each faculty member and each student we need to create an object for each one. To avoid repeating variables and functions, we will create a general class and call it “Members”. This class contains the shared data that each student and faculty member should have (first name, last name, id). Our class should also have the following: • A constructor that takes no arguments. • A constructor that takes three arguments to set the member variable: first name, last name, and id. Members(const string& firstName, const string& lastName, int idNum); • A print function “printMember” that prints first name, last name, and the id for the calling object. void printMember() const; • A function “readWriteMembers” that accepts an input file object and output file object to read and write members to files. (The definition in the Base class is not that important since we will use it to read student members or faculty members only). void readWriteMembers(ifstream& instream, ofstream& outstream); • Getters and setters for the first name, last name, and id. We will have two derived classes, the first one called “Faculty”. This class inherits all member variables and member functions from “Members”. It also has the following: • An extra member variable called “salary” of type double • A constructor with no arguments. • In the parameterized constructor, call the base class constructor to set the first name, last name, and id. Then set the salary member variable. • Redefine the function “printMember” to print the data for the calling object such as “The faculty member name is …, the id is … , and the salary is …”. • Redefine the function “readWriteMembers” to read the input file (the lines that start with ‘f’ only). Then send the following output to an output file called “FacultyOutput.txt”: “Faculty name: … ID: … Salary: ….” • Getters and setters for the salary. The second class is “Student” that inherits all member variables and member functions from “Members” and has the following details: • An extra member variable “major” of type string. • A constructor that takes no arguments. • A constructor that accepts four arguments. Call the base class constructor to set the first three arguments, then set the major member variable. • Redefine the member function “printMember” to print the calling object data such as “The student name is … ID: …. Major:…..”. • Redefine the member function “readWriteMembers” to read the input file (the lines that start with ‘s’ only). Then send the following output to an output file called “StudentOutput.txt”: “Student name: … ID: … Major: ….” • Getters and setters for the major. In the main, you should only create the file input and output objects, Faculty object, and a Student object. Then call the “readWriteMembers” for each class instance and let the redefined member function take care of the rest. The getters and setters are really important, since you may want to create and add a new Student to the output by typing the following: Student stu (“Max”, “underwoo”, 703, “Science”); Note: in the previous line we made a mistake and we entered a wrong name. In this case you can simply fix it as the following: Stu.setLastName(“Underwood”); Then you may print this student information or another student information as the following: Stu.printMember(); //This is the difference between this function and “readWriteMembers” input file: f Zach Shiffer 100 10000.29 s Jack Smith 102 Art f Toni Alberto 103 98000.39 s Sam Wael 104 History s Kim Watson 105 Math s Nancy Thomson 106 Geography s Tim Jefferson 107 Art f Andrew Jazz 108 94000.55 f Kyle Zipp 109 68344.09 s Sam Anthony 110 Engineering

Explanation / Answer

here is your file : ------------->>>>>>>>>>

member.h : ----------->>>

#ifndef _MEMBER_H
#define _MEMBER_H
#include<iostream>
#include<fstream>

using namespace std;

class Member{
protected:
string fname;
string lname;
int id;

public:
  Member();
  Member(string&,string&,int);
  void printMember()const;
  void readWriteMembers(ifstream&,ofstream&);
  void setFirstName(string&);
  void setLastName(string&);
  void setID(int);
  int getID()const;
  string getFirstName()const;
  string getLastName()const;
};

#endif

member.cpp : --------->>>>>

#include "member.h"

Member::Member(string &fn,string &ln,int id){
fname = fn;
lname = ln;
this->id = id;
}
Member::Member(){
fname = "";
lname = "";
id = 0;
}
void Member::printMember()const{
cout<<"Name : "<<fname<<" "<<lname<<" ID: "<<id;
}
void Member::readWriteMembers(ifstream &ifs,ofstream &ofs){

}
void Member::setFirstName(string &fn){
fname = fn;
}
void Member::setID(int id){
this->id = id;
}
void Member::setLastName(string &ln){
lname = ln;
}
int Member::getID()const{
return id;
}
string Member::getFirstName()const{
return fname;
}
string Member::getLastName()const{
return lname;
}

faculty.h : ---------->>>>>>>>

#ifndef _FACULTY_H
#define _FACULTY_H
#pragma once
#include "member.cpp"

class Faculty:public Member{
double salary;

public:
  Faculty():Member(){
  }
  Faculty(string &fn,string &ln,int id,double sal):Member(fn,ln,id){
   salary = sal;
  }
  void setSalary(double);
  double getSalary()const;
  void printMember()const;
  void readWriteMembers(ifstream &ifs,ofstream &ofs);
};

#endif

faculty.cpp : ------->>>>

#include "faculty.h"

void Faculty::printMember()const{
Member::printMember();
cout<<" Salary: "<<salary;
}
void Faculty::setSalary(double sal){
salary = sal;
}
double Faculty::getSalary()const{
return salary;
}
void Faculty::readWriteMembers(ifstream &ifs,ofstream &ofs){
if(ifs.is_open()){
  if(ofs.is_open()){
   char ch;
   string fn;
   string ln;
   int idf;
   double sal;
   string maj;
   ifs>>ch;
   while(!ifs.eof()){
    if(ch == 'f'){
     ifs>>fn>>ln>>idf>>sal;
     fname = fn;
     lname = ln;
     id = idf;
     salary = sal;
     ofs<<" Faculty Name : "<<fn<<" "<<ln<<" ID: "<<idf<<" Salary: "<<sal;
     break;
    }else{
     ifs>>fn>>ln>>idf>>maj;
    }
    ifs>>ch;
   }
  }else{
   cout<<" Output File Not Open";
   return;
  }
}else if(ofs.is_open()){
  ofs<<" Faculty Name : "<<fname<<" "<<lname<<" ID: "<<id<<" Salary: "<<salary;
}else{
  cout<<" Output File Not Open";
  return;
}
}

student.h : ----------->>>>>

#ifndef _STUDENT_H
#define _STUDENT_H
#include "faculty.cpp"

class Student:public Member{
string major;

public:
  Student():Member(){
  }
  Student(string &fn,string &ln,int id,string &major):Member(fn,ln,id){
   this->major = major;
  }
  void setMajor(string &);
  string getMajor()const;
  void printMember()const;
  void readWriteMembers(ifstream &ifs,ofstream &ofs);
};

#endif

student.cpp : --------->>>>>

#include "student.h"

void Student::setMajor(string &maj){
major = maj;
}
string Student::getMajor()const{
return major;
}
void Student::printMember()const{
Member::printMember();
cout<<" Major : "<<major;
}
void Student::readWriteMembers(ifstream &ifs,ofstream &ofs){
//ifs.seekg(0,ifs.beg);
if(ifs.is_open()){
  if(ofs.is_open()){
   char ch;
   string fn;
   string ln;
   int idf;
   double sal;
   string maj;
   ifs>>ch;
   while(!ifs.eof()){
    if(ch == 'f'){
     ifs>>fn>>ln>>idf>>sal;
    }else{
     ifs>>fn>>ln>>idf>>maj;
     fname = fn;
     lname = ln;
     id = idf;
     major = maj;
     ofs<<" Student Name : "<<fn<<" "<<ln<<" ID: "<<idf<<" Major: "<<maj;
     break;
    }
    ifs>>ch;
   }
  }else{
   cout<<" Output File Not Open";
   return;
  }
}else if(ofs.is_open()){
  ofs<<" Student Name : "<<fname<<" "<<lname<<" ID: "<<id<<" Major: "<<major;
}else{
  cout<<" Output File Not Open";
  return;
}
}

studentDriver.cpp : ---------->>>>>>>>>>

#pragma once
#include "student.cpp"

int main(){
ifstream ifs;
ofstream ofs1;
ofstream ofs2;
string file;
cout<<" Enter the Input File";
cin>>file;
ifs.open(file.c_str());
ofs1.open("StudentOutput.txt");
ofs2.open("FacultyOutput.txt");
Student stu[10];
for(int i = 0;i<10;i++){
  stu[i] = Student();
}
Faculty fct[10];
for(int i = 0;i<10;i++){
  fct[i] = Faculty();
}
for(int i =0;i<10;i++){
  stu[i].readWriteMembers(ifs,ofs1);
}
ifs.clear();
ifs.seekg(0,ios::beg);
for(int i = 0;i<10;i++){
  fct[i].readWriteMembers(ifs,ofs2);
}
cout<<"Students : ";
for(int i = 0;i<10;i++){
  stu[i].printMember();
  cout<<endl;
}
cout<<"Faculty : ";
for(int i = 0;i<10;i++){
  fct[i].printMember();
  cout<<endl;
}

return 0;
}