Question: USE C++ Project 1 will utilize a Sequential List class included below. The Sequential List class creates a list of items of any data type
USE C++
Project 1 will utilize a Sequential List class included below. The Sequential List class creates a list of items of any data type that is defined for use by the class. The Sequential List class contains list modification methods Insert, Delete, and Clear, as well as list access methods Find, GetData, ListSize and ListEmpty.
The Sequential List class can maintain a list of any class. The project will require you to create a class called Employee that will be used by the Sequential List class. The following outlines the requirements for the project, it must contain all of these requirements.
Step 1) Use the definition and implementation for the Sequential List class that is contained in the file aseqlist.h under these instructions.
- Change the typedef in the file from type int to Employee (the typedef is set to int so that the file will compile until you have your Employee class code complete)
Step 2) Create a declaration for a class named Employee
Include the following data members:
- EmployeeNumber
- LastName
- FirstName
- Age
- Gender only male or female (m or f) values should be allowed Include the following methods:
- 2 constructors
- One which initializes all data members of the class with given values.
- One which sets all data members to a blank or zero initial state.
- Include appropriate methods to access and store values to each data member.
- Overload the == operator. Define equivalence for the Employee class where the last name for each object are the same
- This operator will be used in methods of the aseqlist class
- A member function PrintEmployee to print the employees data
- A ReadEmployee member function to assign values to the data members
Step 3) Create the implementation of the Employee class (5pts)
Step 4) Create a function PrintByGender in the main program which will traverse a Sequential List object and print out the instances of Employee objects in the Sequential List for a given gender. The function should be declared as follows (5 pts):
Void PrintByGender (const SeqList& L, char gender)
The function should print out the name, employee number, age and gender of each employee found to match the given gender. (Hint you need to use the ListSize method to be able to traverse the entire list)
Step 5) Create a function InList in the main program which will determine whether an Employee object with the last name passed through the parameter lname exists in the Sequential Listobject. The function should be declared as follows (5 pts):
int InList (const SeqList& L, string lname, Employee& Emp)
If the name is found, the name and employee number is printed. If the name is not found, print Employee Not Found
- Emp is an Employee object that should be declared prior to the function call to InList() you will to assign the lname value to the Emp object
- You can use the Find method of the SeqList class to determine if a match exists the Emp object can be used as the parameter to the Find() method
- You will need to overload the = = operator of the Employee class to utilize the = = operator as it is used in the Find() method (5 pts)
Step 6) Set the Listitem array in the Sequential List class to a value of 6. The program should correctly manage that the list can hold no more than 6 employee objects. Note that if the list is full and an object is deleted, additional objects can be added up to a total of 6 objects (5 pts)
Step 7) Write a main program that will use the SeqList and Employee classes as follows.
- Create a menu that will prompt the user with 5 choices
1) Enter Employee Information the user will enter the data for an employee into the program up to the maximum of 6 that the Listitem data member is set to. Make sure to include the appropriate data validation in the data entry (5 pts)
2) Delete Employee the user will enter the employee last name and if this employee is found, the employee object will be deleted from the sequential list. You can utilize the InList function to determine if the employee is in the list. Then use the Delete() method of the Sequential List class to delete the object (5 pts)
- Note that if the list is full and an object is deleted from the list, another object can be added to the list
3) Print Employees by Gender user will input agender (M or F) and all employees of that gender will be printed. You will use the PrintByGender() function for this menu choice (5 pts)
4) Search for Employee user will input the last name and if found, the employee name and number will be printed. You will use the InList() function for this menu choice (5 pts).
5) Print all Employees print all employees from the sequential list (5 pts)
6) Exit
***** aseqlist.h file *****
#include
using namespace std;
const int MaxListSize = 50;
// You will need to change the typedef in the following line
// from the data type int to Employee
typedef int DataType;
class SeqList
{
private:
// list storage array and number of current list elements
DataType listitem[MaxListSize];
int size;
public:
// constructor
SeqList(void);
// list access methods
int ListSize(void) const;
int ListEmpty(void) const;
int Find (DataType& item) const;
DataType GetData(int pos) const;
// list modification methods
void Insert(const DataType& item);
void Delete(const DataType& item);
DataType DeleteFront(void);
void ClearList(void);
};
// Class Definition:
// constructor. set size to 0
SeqList::SeqList (void): size(0)
{}
// return number of elements in list
int SeqList::ListSize(void) const
{
return size;
}
// tests for an empty list
int SeqList::ListEmpty(void) const
{
return size == 0;
}
// clears list by setting size to 0
void SeqList::ClearList(void)
{
size = 0;
}
// Take item as key and search the list. return True if item
// is in the list and False otherwise. if found,
// assign the list element to the reference parameter item
int SeqList::Find(DataType& item) const
{
int i = 0;
if (ListEmpty())
return 0; // return False when list empty
while (i < size && !(item == listitem[i]))
i++;
if (i < size)
{
item = listitem[i]; // assign list element to item
return 1; // return True
}
else
return 0; // return False
}
// insert item at the rear of the list. terminate the program
// if the list size would exceed MaxListSize.
void SeqList::Insert(const DataType& item)
{
// will an insertion exceed maximum list size allowed?
if (size+1 > MaxListSize)
{
cout << "Maximum list size exceeded" << endl;
exit(1);
}
// index of rear is current value of size. insert at rear
listitem[size] = item;
size++; // increment list size
}
// search for item in the list and delete it if found
void SeqList::Delete(const DataType& item)
{
int i = 0;
// search for item
while (i < size && !(item == listitem[i]))
i++;
if (i < size) // successful if i < size
{
// shift the tail of the list to the left one position
while (i < size-1)
{
listitem[i] = listitem[i+1];
i++;
}
size--; // decrement size
}
}
// delete element at front of list and return its value.
// terminate the program with an error message if the list is empty.
DataType SeqList::DeleteFront(void)
{
DataType frontItem;
// list is empty if size == 0
if (size == 0)
{
cout << "Attempt to delete the front of an empty list!" << endl;
exit(1);
}
frontItem = listitem[0]; // get value from position 0.
Delete(frontItem); // delete the first item and shift terms
return frontItem; // return the original value
}
// return value at position pos in list. if pos is not valid
// list position, teminate program with an error message.
DataType SeqList::GetData(int pos) const
{
// terminate program if pos out of range
if (pos < 0 || pos >= size)
{
cout << "pos is out of range!" << endl;
exit(1);
}
return listitem[pos];
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
