Starting from:

$30

CS 201 Homework Assignment 1 Simple Registration System Using Dynamic Memory Management Solved

You will implement a simple registration system by using dynamic memory management. The registration system stores information about students and courses. For each student, the system stores an id, first name, last name, and a list of her/his course enrollments. Each course is represented by its id and title. This system MUST use a dynamically allocated array to store the students, and for each student, another dynamically allocated array to store the course enrollments for that student. The students are stored in ascending order of their ids. The courses are stored in an unsorted array. The arrays must be allocated dynamically and must use memory only as much as needed (in other words, you cannot assume a maximum size for students and courses to allocate arrays that are larger than needed).

The registration system will have the following functionalities; the details of these functionalities are given below:

•    Add a student

•    Delete a student

•    Add a course for a student

•    Withdraw a student from a course

•    Cancel a course

•    Show detailed information about a particular student

•    Show detailed information about a particular course

•    Show all students

This assignment has two parts, whose requirements will be explained below.

PART A: To take the final exam, you MUST submit at least this part and MUST get at least half of its points.

This part includes the following four functionalities:

•    Add a student

•    Delete a student

•    Show detailed information about a particular student

•    Show all students

The details of these four functionalities will be given below. Note that this part does not involve any course information for the students. Therefore, in this part, the “Show detailed information about a particular student”or the “Show all students” functionalities will not be expected to display the list of the courses enrolled by the student(s).

PART B: In this part, you will complete the implementation of the entire registration system (all of the 8 functionalities listed above).

The details of all of the functionalities are given below:

Add a student: The registration system will allow to add a new student indicating her/his student id, first name, and last name. Since the student ids are unique positive integers, the system should check whether or not the specified student id already exists (i.e., whether or not it is the id of an existing student), and if the student id exists, it should not allow the operation and display a warning message. Moreover, if the first name or the last name are empty, it should not allow the operation and display a warning message. The array must remain sorted by student id after this operation.

Delete a student: The registration system will allow to delete an existing student indicating her/his student id. If the student does not exist (i.e., if there is no student with the specified id), the system should display a warning message. Note that this operation will also drop all courses in which the student was enrolled.

Add a course for a student: The registration system will allow to add a new course for a particular student. For that, the student id, the course id, and the course name have to be specified. The system should check whether or not this student exists; if she/he does not, it should prevent to add a course and display a warning message. If the student exists and the student is not already enrolled in this course, the given course is added to student’s course array. If the student is already enrolled in this course, it should display an appropriate message and the given course should not be added again. The courses are stored unsorted.

Withdraw a student from a course: The registration system will allow to delete an existing course indicating its course id from a student’s course enrollment array. If the student does not exist (i.e., if there is no student with the specified id) or the student is not enrolled in this course (i.e., if there is no course with the specified id), the system should display a warning message.

Cancel a course: The registration system will allow to delete an existing course indicating its course id. Note that this operation will remove the course from the course enrollment arrays for all students. If the course does not exist (i.e., if there is no course with the specified id), the system should display a warning message.

Show detailed information about a particular student: The registration system will allow to specify a student id and display detailed information about that particular student. This information includes the student id, the student name, the list of courses enrolled by this student including the course id and the course name for each course. If the student does not exist (i.e., if there is no student with the specified student id), the system should display a warning message.

Show detailed information about a particular course: The registration system will allow to specify a course id and display detailed information about that particular course. This information includes the course id, the course name, the list of students enrolled in this course including the student id and the student name for each student. If the course does not exist (i.e., if there is no course with the specified course id), the system should display a warning message.

Show the list of all students: The registration system will allow to display a list of all the students. This list includes the student id, the student name, and the list of courses enrolled by each student.

Below is the required public part of the RegistrationSystem class that you must write in this assignment. The name of the class must be RegistrationSystem, and must include these public member functions. We will use these functions to test your code. The interface for the class must be written in a file called RegistrationSystem.h and its implementation must be written in a file called RegistrationSystem.cpp. You can define additional public and private member functions and data members in this class. You can also define additional classes in your solution.

class RegistrationSystem { public:

RegistrationSystem(); ~RegistrationSystem();

void addStudent( const int studentId, const string firstName, const string lastName ); void deleteStudent( const int studentId );

void addCourse( const int studentId, const int courseId, const string courseName ); void withdrawCourse( const int studentId, const int courseId ); void cancelCourse( const int courseId );

void showStudent( const int studentId ); void showCourse( const int courseId ); void showAllStudents();

};

Here is an example test program that uses this class and the corresponding output. We will use a similar program to test your solution so make sure that the name of the class is RegistrationSystem, its interface is in the file called RegistrationSystem.h, and the required functions are defined as shown above. The example test code provided below is just a sample. You must test your program with different inputs as well.

Example test code:

#include "RegistrationSystem.h" int main() {

RegistrationSystem rs;

rs.showAllStudents(); cout << endl;

rs.addStudent( 2000, "Esra", "Kara" ); rs.addStudent( 1000, "Mehmet", "Celik" ); rs.addStudent( 4000, "Ahmet", "Akcay" ); rs.addStudent( 3000, "Fatih", "Isler" ); rs.addStudent( 4000, "Can", "Uzun" ); rs.addStudent( 6000, "Can", "Uzun" ); rs.addStudent( 5000, "Ali", "Akdere" ); rs.addStudent( 7000, "Berrak", "Tosun" ); cout << endl;

rs.showAllStudents(); cout << endl;

rs.addCourse( 2000, 555, "CS555" ); rs.addCourse( 2000, 540, "CS540" ); rs.addCourse( 2000, 513, "CS513" ); rs.addCourse( 2000, 524, "CS524" );

rs.addCourse( 3000, 524, "CS524" ); rs.addCourse( 3000, 540, "CS540" );

rs.addCourse( 1000, 540, "CS540" ); rs.addCourse( 1000, 524, "CS524" );

rs.addCourse( 4000, 524, "CS524" ); rs.addCourse( 4000, 510, "CS510" ); rs.addCourse( 4000, 540, "CS540" ); rs.addCourse( 4000, 513, "CS513" ); rs.addCourse( 5000, 510, "CS510" ); rs.addCourse( 5000, 513, "CS513" ); rs.addCourse( 5000, 540, "CS540" ); rs.addCourse( 6000, 540, "CS540" );

rs.addCourse( 7000, 510, "CS510" ); rs.addCourse( 7000, 513, "CS513" ); rs.addCourse( 7000, 540, "CS540" );

rs.addCourse( 3000, 524, "CS524" ); cout << endl;

rs.deleteStudent( 5000 ); rs.deleteStudent( 5000 ); cout << endl;

rs.showStudent( 1000 ); rs.showStudent( 3000 ); rs.showStudent( 5000 ); cout << endl;

rs.showAllStudents(); cout << endl;

rs.withdrawCourse( 3000, 524 ); rs.withdrawCourse( 2000, 555 ); rs.withdrawCourse( 2000, 550 ); rs.withdrawCourse( 10000, 510 ); cout << endl;

rs.cancelCourse( 540 ); rs.cancelCourse( 201 ); cout << endl;

rs.showCourse( 524 ); rs.showCourse( 540 ); rs.showStudent( 7000 ); cout << endl;

rs.deleteStudent( 7000 ); cout << endl;

rs.showStudent( 3000 ); cout << endl;

rs.showAllStudents(); cout << endl;

return 0;

}

Output of the example test code:

There are no students in the system

Student 2000 has been added

Student 1000 has been added

Student 4000 has been added

Student 3000 has been added

Student 4000 already exists

Student 6000 has been added

Student 5000 has been added

Student 7000 has been added

Student id First name Last name

1000
Mehmet
Celik
2000
Esra
Kara
3000
Fatih
Isler
4000
Ahmet
Akcay
5000
Ali
Akdere
6000
Can
Uzun
7000
Berrak
Tosun
Course 555 has been added to student 2000

Course 540 has been added to student 2000

Course 513 has been added to student 2000

Course 524 has been added to student 2000

Course 524 has been added to student 3000

Course 540 has been added to student 3000

Course 540 has been added to student 1000

Course 524 has been added to student 1000

Course 524 has been added to student 4000

Course 510 has been added to student 4000

Course 540 has been added to student 4000

Course 513 has been added to student 4000

Course 510 has been added to student 5000

Course 513 has been added to student 5000

Course 540 has been added to student 5000

Course 540 has been added to student 6000

Course 510 has been added to student 7000

Course 513 has been added to student 7000

Course 540 has been added to student 7000

Student 3000 is already enrolled in course 524

Student 5000 has been deleted

Student 5000 does not exist

Student id First name Last name

1000                 Mehmet             Celik

                  Course id         Course name

                 540                   CS540

                 524                   CS524

Student id First name Last name

3000                   Fatih                  Isler

                  Course id         Course name

                 524                   CS524

                 540                   CS540

Student 5000 does not exist

Student id First name Last name

1000
Mehmet
Celik
 
Course id
Course name
 
540
CS540
 
524
CS524
2000
Esra
Kara
 
Course id
Course name
 
555
CS555
 
540
CS540
 
513
CS513
 
524
CS524
3000
Fatih
Isler
 
Course id
Course name
 
524
CS524
 
540
CS540
4000
Ahmet
Akcay
 
Course id
Course name
 
524
CS524
 
510
CS510
 
540
CS540
 
513
CS513
6000
Can
Uzun
 
Course id
Course name
 
540
CS540
7000
Berrak
Tosun
 
Course id
Course name
 
510
CS510
 
513
CS513
 
540
CS540
Student 3000 has been withdrawn from course 524

Student 2000 has been withdrawn from course 555

Student 2000 is not enrolled in course 550

Student 10000 does not exist

Course 540 has been cancelled

Course 201 does not exist

Course id           Course name

524           CS524

Student id First name Last name

                 1000                Mehmet              Celik

                 2000                  Esra                  Kara

                 4000                 Ahmet             Akcay

Course 540 does not exist

Student id First name Last name

7000                  Berrak                Tosun

                  Course id         Course name

                 510                   CS510

                 513                   CS513

Student 7000 has been deleted

Student id First name Last name

3000                   Fatih                  Isler

Student id First name Last name

1000
Mehmet
Celik
 
Course id
Course name
 
524
CS524
2000
Esra
Kara
 
Course id
Course name
 
513
CS513
 
524
CS524
3000
Fatih
Isler
4000
Ahmet
Akcay
 
Course id
Course name
 
524
CS524
 
510
CS510
 
513
CS513
6000
Can
Uzun

More products