Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the code in C++ language 9. [40 marks] (The Course class) Implement the classes Student and Course which are defined as follows, // Course.h

write the code in C++ language

9. [40 marks] (The Course class) Implement the classes Student and Course which are

defined as follows,

// Course.h

#ifndef COURSE_H

#define COURSE_H

#include

#include

using namespace std;

class Student

{

public:

// Default constructor

Student();

// Creates a student with the specified name and id.

Student(const string& name, int student_id);

// Returns the student name.

string get_name() const;

// Returns the student id.

int get_student_id () const;

// Sets the student name.

void set_name(const string& name);

// Sets the student id.

void set_student_id(int student_id);

// Prints the student name and id.

void print_student() const;

private:

// student name

string name;

// student id

int student_id;

};

class Course

{

public:

// Creates a course with the specified name and maximum

number of students allowed.

Course(const string& course_name, int capacity);

// Destructor, destory the dynamic array

~Course();

// Returns the course name.

string get_course_name() const;

// Adds a new student to the course if the array

capacity is not exceeded.

void add_student(const Student& new_student);

// Drops the student with the specified id from the

course.

void drop_student(int drop_student_id);

// Returns the array of students for the course.

Student* get_students() const;

// Returns the number of students for the course.

int get_number_of_students() const;

// Prints the course name and the added students.

void print_course() const;

private:

// The name of the course

string course_name;

//An array of students who take the course. students is

a pointer for the array.

Student* students;

// The number of students (default: 0).

int number_of_students;

// The maximum number of students allowed for the

course.

int capacity;

};

#endif

Write a test program that creates a course (prompt the user to enter the course name

and capacity), adds students (prompt the user to enter the student name and ID, stop

adding the students when the user enter "exit" as student name), removes one (prompt

the user to enter the student ID to be removed), and displays the course name and

students added in the course.

There will be at least four files need to be submitted for this program question. 1) a

header file Course.h which contains the definition of Student class and Course

class, 2) an implementation file Course.cpp which contains the implementation of

Student class and Course class, 3) a client test file a2q9.cpp containing main()

function, 4) a script file a2q9result containing result.

Here are the sample runs:

Enter the course name: CSE202

Enter the course capacity: 20

Enter the student name: Taylor

Enter the student id: 1001

The student is added

Enter the student name: Jim

Enter the student id: 1002

The student is added

Enter the student name: Alice

Enter the student id: 1003

The student is added

Enter the student name: exit

Enter the student ID that will be removed: 1002

The student is removed

The course information:

CSE202

1001, Taylor

1003, Alice

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago