Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++, Implement a template List ADT using an array representation of a list. You will start with linkedList.h, main.cpp, Employee.h, Employee.cpp, sample.txt and makefile.

IN C++, Implement a template List ADT using an array representation of a list. You will start with linkedList.h, main.cpp, Employee.h, Employee.cpp, sample.txt and makefile. You will create linkedList.cpp in Part I and use linkedList.h, main.cpp and makefile

linkedList.h template  class LinkedList { public: List(); bool isEmpty() const; int getSize() const; void insert(const LISTTYPE newItem); LISTTYPE remove(int index); void retrieve(int index) const; void print() const; void sort(); private: LISTTYPE items[MAX_SIZE]; int size; };

main.cpp

#include "linkedList.h" #include "Employee.h" #include #include

using namespace std; ostream & operator<<(ostream &out, Employee emp);

int main(int argc, char** argv) {

//declare list List testList;

//check if list is empty if(testList.isEmpty()==0) cout<< "List is not empty"<

//insert values testList.insert(10); testList.insert(15); testList.insert(33); testList.insert(86); testList.insert(92); testList.insert(42); testList.insert(44); testList.insert(76); testList.retrieve(0); cout<<"The "<

List employeeList; ifstream input("sample.txt"); string fname, lname, department,id; int salary;

if(input.is_open()){ while(input>>fname>>lname>>department>>id>>salary){ Employee temp(id, fname, lname, department, salary); employeeList.insert(temp); } input.close(); } employeeList.print(); employeeList.sort(); employeeList.print(); return 0; }

Employee.h

#ifndef EMPLOYEEH #define EMPLOYEEH #include #include using namespace std;

class Employee { public: Employee (); Employee (string id, string name, string surname, string department, float salary); string getName (); string getSurname (); float getSalary (); void printInfo (); string getDepartment (); string getId (); private: string department; float salary; string id; string name; string surname; };#endif

Employee.cpp

#ifndef EMPLOYEECPP #define EMPLOYEECPP #include "Employee.h"

Employee::Employee () { this->id = "x1234"; this->name = "Brad"; this->surname = "Smith"; this->department = "None"; this->salary = 0.0; }

Employee::Employee (string id, string name, string surname, string department, float salary) { this->id = id; this->name = name; this->surname = surname; this->department = department; this->salary = salary; }

string Employee::getDepartment () { return (department); }

float Employee::getSalary () { return (salary); }

void Employee::printInfo () { cout << getId () << ": " << getName () << " " << getSurname () << "\t"; cout << getDepartment () << "\t"; cout << getSalary () << endl; }

string Employee::getId () { return (id); }

string Employee::getName () { return (name); }

string Employee::getSurname () { return (surname); } #endif

Sample.txt

Danny Thomas BIOL f223018244 120000 John Smith BIOL f009382731 900000 Bill Nye CPSC f987654321 23000 Albert Einstein CHEM s483726364 100100 Micky Mouse CPSC s230324832 118000 Isaac Newton PSYCG s999384625 99000

Makefile

a.out: main.cpp Employee.o linkedList.o g++ -std=c++11 lab4.cpp Employee.o linkedList.o Employee.o: Employee.cpp Employee.h g++ -std=c++11 -c Employee.cpp linkedList.o: linkedList.cpp linkedList.h g++ -std=c++11 -c linkedList.cpp clean: rm *.o *gch a.out

PART I

After creating the linkedList.cpp methods run main.cpp with the second part of the lab commented out. That part of the lab is based on overloaded operators. Output for this portion is as follows:

List is empty 99 has been inserted 55 has been inserted 32 has been inserted 11 has been inserted 78 has been inserted 40 has been inserted 18 has been inserted 94 has been inserted item at position 0 is: 99 The 40 was removed size is: 7 The item deleted: 18 List contains: 99 55 11 78 40 94 Sorting .......... List contains: 11 40 55 78 94 99

PART II

Once you have main.cpp working with integers move onto the second part of the lab. This requires overload operators. You will be using Employee.h, Employee.cpp and sample.txt.

Step 1:

  1. Create an overloaded operator << for output.
    1. Create friend statement inside the Employee.h
    2. Create prototype for operator<< overload in main.cpp above main
    3. Create body for operator<< overload in main.cpp below main. The output must following the following guidelines
  • output << ID << ": " << FIRSTNAME << " " << LASTNAME <<"\t ";
  • output << DEPARTMENT << "\t ";
  • output << SALARY ;

Step 2:

In main.cpp uncomment the following code

List employeeList; ifstream input("sample.txt"); string fname, lname, department,id; int salary; if(input.is_open()){ while(input>>fname>>lname>>department>>id>>salary){ Employee temp(id, fname, lname, department, salary); employeeList.insert(temp); } input.close(); } employeeList.print();

Make sure this works before moving onto the next step, the output for this portion is

f223018244: Danny Thomas BIOL 120000 has been added f009382731: John Smith BIOL 900000 has been added f987654321: Bill Nye CPSC 23000 has been added s483726364: Albert Einstein CHEM 100100 has been added s230324832: Micky Mouse CPSC 118000 has been added s999384625: Isaac Newton PSYCG 99000 has been added List is filled with: f223018244: Danny Thomas BIOL 120000 f009382731: John Smith BIOL 900000 f987654321: Bill Nye CPSC 23000 s483726364: Albert Einstein CHEM 100100 s230324832: Micky Mouse CPSC 118000 s999384625: Isaac Newton PSYCG 99000 

Step 3: Overload the Boolean operators

  1. Put the prototypes in Employee.h under public
  2. Put the bodies in Employee.cpp
  3. Uncomment
 employeeList.sort(); employeeList.print();
  1. The output for this final portion is:
Sorting .......... List contains: s483726364: Albert Einstein CHEM 100100 s230324832: Micky Mouse CPSC 118000 s999384625: Isaac Newton PSYCG 99000 f987654321: Bill Nye CPSC 23000 f009382731: John Smith BIOL 900000 f223018244: Danny Thomas BIOL 120000 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

What is the meaning and definition of E-Business?

Answered: 1 week ago