Question

For this assignment you will write a simple class hierarchy and use functions to carry out common tasks across all child classes.
The assignment problem:

A file called “input.txt” contains all the faculty and students’ data. Each line in this file starts with one of the following letters (‘s’, ‘f’). If the line starts with ‘s’, that means this line represents a student (first name, last name, id, major). Otherwise, a faculty member (first name, last name, id, salary).

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.

Derived classes:

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.

Flow Control:

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();

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

include "members.h"
#include <iostream>

using namespace std;

Members::Members() {

}

Members::Members(const string &firstName, const string &lastName, int idNum) {
    this->firstname = firstName;
    this->lastname = lastName;
    this->id = idNum;
}

void Members::setFirstName(const string &firstName) {
    this->firstname = firstName;
}

void Members::setLastName(const string &lastName) {
    this->lastname = lastName;
}

void Members::setId(int id) {
    this->id = id;
}

void Members::readWriteMembers(ifstream &instream, ofstream &outstream) {

}

void Members::printMember() const {
    cout << "The member name is: " << this->firstname << " " << this->lastname
            << ". ID is: " << this->id;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Data Manipulation Using C++ Arrays
Homework Solution
$50.00
Computer Science
C++ Programming
Data Manipulation
Arrays
Student Records
Objects
Letters
Grades
Scores
Grading Rules
Statements
Variables
Pascal Programming Problems
Homework Solution
$30.00
Computer Science
Pascal Programming
Cars
Records
Attributes
Fields
Strings
Definitions
Terminal Values
Functions
Arrays
Procedures
Memory Management Simulation
Homework Solution
$68.00
Computer Science
C++ Programming
Memory Management
Processes
Operating Systems
Data Structures
Lists
Transactions
ASCII Art in C++
Homework Solution
$23.00
Computer Science
C++ Programming
ASCII Art
Learning Algebra
Random Values
Buildings
Floors
Equations
Games
Winning
Lines
C Programming Problems
Homework Solution
$60.00
Computer Science
C Programming
Global Variables
Pointers
Painting
Text
Recursion
Command Line Arguments
Numbers
Directions
Get help from a qualified tutor
Live Chats