Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Exercise (50 points) You are given a partially completed project containing: 4 header files: Container.h student.h undergrad.h grad.h 5 C++ files: Container.cpp student.cpp grad.cpp

Programming Exercise (50 points)

You are given a partially completed project containing:

4 header files: Container.h

student.h undergrad.h grad.h

5 C++ files: Container.cpp

student.cpp grad.cpp undergrad.cpp hw10.cpp

The diagram shows the inheritance and relationships between the classes and the linked list formed.

Your job is to follow the instructions given in comments in these files to complete the missing parts of the project so that the program executes properly. Tasks are included below.

CSE240 Introduction to Programming Language 2 | PageHomework 10

Q1: Create Undergrad and Grad subclasses of Student class (Inheritance) (10 points)

In undergrad.h: // Q1a: Create Undergrad class (5 points) // Part 1: Create a child class of the Student class named 'Undergrad' // Part2: Declare constructor which accepts the same 3 parameters as the parent class Student's constructor. Pass the 3 parameters to the super constructor of the Student class. // Part 3: Re-declare the method displayInfo (virtual method found inside of parent class Student)

In grad.h: // Q1b: Create Grad class (5 points) // Part 1: Create a child class of the Student class named 'Grad' // Part2: Declare constructor which accepts the same 3 parameters as the parent class Student's constructor. Pass the 3 parameters to the super constructor of the Student class. // Part 3: Re-declare the method displayInfo (virtual method found inside of parent class Student)

Q2: Define displayInfo() for child classes (Polymorphism) (10 points)

In undergrad.cpp // Q2a: Define displayInfo() for Undergrad class (5 points) // Define the function displayInfo() that you declared within the Undergrad class in the header file. See expected output in question file

In grad.cpp // Q2b: Define displayInfo() for Grad class (5 points) // Define the function displayInfo() that you declared within the Grad class in the header file // See expected output in question file.

Q3: Add Friend function changeRollNo() (5 points)

In student.h: // Q3a: Declare Friend Function changeRollNo() (1 point) // Declare a friend function named changeRollNo() which has 2 parameters and no return value. // The first parameter is a pointer to Student class, and the second is an integer which is the new roll number. // You need to define this function in hw10.cpp and call this function in case 'c' of executeAction() in hw10.cpp file

CSE240 Introduction to Programming Language 3 | PageHomework 10

In hw10.cpp: // Q3b: Define Friend Function changeRollNo() (3 points) // Define the function changeRollNo()that is declared in student.h file. // This function sets the new roll number of the student. The student and new roll number is to be passed as function arguments. // Use 'd' display option after using 'c' option to verify whether the new roll number is set.

A friend function allows you to access the private variables of a class (ex: student->rollNo)

Q4 - Q7 are used to implement a menu-driven program. Its implementation is in hw10.cpp. The menu gives the following options to user:

a) Add a new student to the list. You need not check if the student exists in the list because that is already implemented in executeAction(). You may add the new student to head or tail of the list. (sample solution adds it to the tail)

b) Display the list of students along with their details (roll number, type (grad/undergrad)).

c) Change the roll number of a student. This options uses the friend function

changeRollNo() to access private data member rollNo of the student and change it to the one entered by the user.

You need to implement save() that writes the list of students to a file list.txt while exiting the program and load() that reads the file to form the list at the beginning of the program. During first execution of the program, there will be no list.txt, so load() would not form a list. Once list.txt is saved, load() can read it. You may remove the list.txt from your project directory if you do not want to load that list (maybe while testing your code).

The following is one way to store the list in list.txt file. The format here is: student name student roll number student type (0 for undergrad, 1 for grad)

You may store it in another format if you wish. Notice that the 3 at the beginning is the number of students stored in the file.

CSE240 Introduction to Programming Language 4 | PageHomework 10

Expected output: addStudent:

displayList:

CSE240 Introduction to Programming Language 5 | PageHomework 10

changeRollNo:

(Tonys roll number was 1 previously. Using c option it was changed to 10. Use d option to verify that the roll number is really changed)

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago