Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program: This project is a continuation from Project 2. The program should accept the same input data file and support the same list and

C++ program:

This project is a continuation from Project 2. The program should accept the same input data file and support the same list and find operations. You will implement a Queue template to store all the Student objects. A queue is a dynamic data structure, that maintains the first-in-first-out policy. You will use this Queue to manage all the Student objects. The student.h header file, declared below is the same as in Project 2. The course.h header file needs to be modified to use the Queue template and Student*. You should create Queue.h and Node.h for your queue template definition and implementation. Your student.cpp should be the same as Project 2, expect if you need to make corrections. You need to update your course.cpp to work with the Queue data structure. Develop a program, name proj03.cpp, to use the Course object to read from the input student record file and create a list of student objects. This program can perform 2 functions List: to list all the student records read from the input file Find: to lookup a specific student record by the input student id. Student ID read from command line is character string. It needs to be converted to an integer before calling the find function. Use the atoi() function in header for the conversion. Your program will read all input from the command line, no prompting for user input and hardcoding for input file name. The required program output is provided below

Declaration of Student class:

// @file student.h

#ifndef STUDENT_H

#define STUDENT_H

#include

using namespace std;

class Student {

/** * @param is the input stream

* @param course the student object reference

* @return the input stream

*/

friend istream& operator >> (istream& is, Student& student);

/** * @param os the output stream

* @param course the student object reference

* @return the output stream

*/

friend ostream& operator << (ostram& os, const Student& student);

public:

Student();

Student(string firstName, string lastName, int id, char grade);

void setFirstName(string firstName);

String getFirstName();

/** add all the setter and getter methods **/

Private: string firstName; string lastName; int id; char grade; };

#endif /* STUDENT_H */

Declaration of Queue Template class:

// @file Queue.h

#ifndef QUEUE_H

#define QUEUE_H

#include Node.h

template class Queue { public: Queue(); ~Queue();

// method to add a value to the end of the queue

bool enqueue (const T& value);

// method to remove a value from the beginning of the queue

bool dequeue (T& value);

int length() const;

Private: Node* head_; Node* tail_; int length_; };

#endif /* QUEUE_H */

Declaration of Course class:

// @file course.h

#ifndef COURSE_H

#define COURSE_H

#include Queue.h

#include Student.h class Course {

/** * @param is the input stream

* @param course the course object reference

* @return the input stream

*/

friend istream& operator >> (istream& is, Course& course);

/** * @param os the output stream

* @param course the course object reference

* @return the output stream

*/

friend ostream& operator << (ostream& os, const Course& course);

public: Course();

/** * @param id the student id to search for

* @return pointer to the matched student object. NULL if not found.

*/

Student* find (int id) const;

private: /* extra credit */ void sort_();

private: Queue students; int studentCount; };

#endif /* COURSE_H */

Example Output:

% cat students.dat

John Doe 123456789 A

Bob Smith 598765432 B

Bill Jones 898745792 C

George Roberts 128920740 D

% ./proj03

./proj03 find

./proj03 list

% ./proj03 students.dat list

ID: 123456789

First Name: John

Last Name: Doe

Grade: A

ID: 598765432

First Name: Bob

Last Name: Smith

Grade: B

ID: 898745792

First Name: Bill

Last Name: Jones

Grade: C

ID: 128920740

First Name: George

Last Name: Roberts

Grade: D

% ./proj03 students.dat find 898745792

ID: 898745792

First Name: Bill

Last Name: Jones

Grade: C

Extra Credit: Implement an internal sort_ method for the Course class to sort the list of Student objects stored in the Courses internal list. This method should be call one time in the Courses operator >> method after the list of student objects is read from the file.

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

Step: 3

blur-text-image

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

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago