Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ ONLY PLEASE You will be building a structure named Course that will hold the following information about a course at a University: Name of

C++ ONLY PLEASE

You will be building a structure named Course that will hold the following information about a course at a University:

  • Name of the course
  • Location of the course
  • The number of sections & an array of the section names
  • The number of credit hours

Then you will implement functions to create a course, destroy (delete) a course, and print a course.

Last, you will implement a driver that will use the Course structure and functions.

Course Structure

The structure tag should be Course and should be defined in Course.h

  • Name (string)
  • Location (string)
  • Sections (pointer to an array of strings)
  • Number of sections (integer)
  • Number of credit hours (integer)

functions

Function prototypes should go in Course.h and function definitions should go in Course.cpp

createCourse function

Purpose:

This is a function that will (dynamically) create a new Course structure variable and then enter the given data into the Course structure members. This function will also have to dynamically create the sections array containing the number of elements as there are sections of the course. Then the function will return the memory address of the Course structure variable from this function.

Function Prototype:

Course* createCourse(string, string, int, int);

Parameters:

  • a string containing the name of the course
  • a string containing the location of the course
  • an integer containing how many sections the course has
  • an integer containing how many credit hours the course has

Returns:

  • a pointer to the Course variable just created with all the given data

DestroyCourse Function

Purpose:

This is a function that will delete (release) both the dynamically created sections array and the course so that there are no memory leaks.

Function Prototype:

void destroyCourse(Course* myCourse);

PrintCourse Function

Purpose:

This function will print all the data in the members of the sent Course structure variable, including all the sections of the course. The data must be printed in a neat easy-to-read format so that the program is user friendly.

Function Prototype:

void printCourse(Course* myCourse);

DRIVER

You are given most of the Driver.cpp code (called Driver_given_lab1.cpp and you will need to copy the contents and place in your Driver.cpp), but you will need to add only FIVE LINES of code in all the places indicated by the comments.

After you add the necessary code, you need to test all the code to make sure you get the same output as below! The user input is highlighted in yellow.

given driver file is as follows:

#include "course.h" #include

using namespace std;

int main () { //LOOK! //Create a pointer to an array of Course pointers called myCourses here

int numCourses, numSections; string name, location; int numHours; cout << " How many courses are you taking this semester? "; cin >> numCourses; cin.ignore(); //LOOK!! //Dynamically allocate a new array of pointers to Courses of size numCourses and assign this array to myCourses for (int i=0; i< numCourses; i++) { cout << " COURSE NAME:\t\t"; getline(cin, name); cout << " COURSE LOCATION:\t"; getline(cin, location); cout << " COURSE HOURS:\t\t"; cin >> numHours; cout << " NUMBER OF SECTIONS?\t"; cin >> numSections; cin.ignore(); //LOOK!! //Call the createCourse function and make sure to assign the returned value to myCourses[i]

for(int x=0; x { cout << " SECTION " << x+1 << ":\t\t"; //LOOK!! //Read in the string from the user and put in the correct array element of the sections array

} cout << " ******************************* "; } cout << " The following are the courses you entered: "; for(int i=0; i { cout << "******************************* COURSE " << (i+1) << "******************************* "; printCourse(myCourses[i]); } for(int i=0; i< numCourses; i++) { destroyCourse(myCourses[i]); } delete [] myCourses; cout << endl << endl; return 0; }

SAMPLE OUTPUT:

How many courses are you taking this semester?

3

COURSE NAME: CSC 1300

COURSE LOCATION: CLEM 215

COURSE HOURS: 4

NUMBER OF SECTIONS? 3

SECTION 1: 001

SECTION 2: 002

SECTION 3: 003

***************************************

COURSE NAME: CSC 1310

COURSE LOCATION: FNDH 238

COURSE HOURS: 4

NUMBER OF SECTIONS? 2

SECTION 1: 001

SECTION 2: 002

***************************************

COURSE NAME: CSC 2400

COURSE LOCATION: BRUN 406

COURSE HOURS: 3

NUMBER OF SECTIONS? 3

SECTION 1: 001

SECTION 2: 002

SECTION 3: 003

***************************************

The following are the courses you entered:

*************************************** COURSE 1 ***************************************

COURSE NAME: CSC 1300

COURSE LOCATION: CLEM 215

COURSE HOURS: 4

COURSE SECTIONS:

001

002

003

*************************************** COURSE 2 ***************************************

COURSE NAME: CSC 1310

COURSE LOCATION: FNDH 238

COURSE HOURS: 4

COURSE SECTIONS:

001

002

*************************************** COURSE 3 ***************************************

COURSE NAME: CSC 2400

COURSE LOCATION: BRUN 406

COURSE HOURS: 3

COURSE SECTIONS:

001

002

003

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Group Size and Communication

Answered: 1 week ago

Question

Understanding Group Roles

Answered: 1 week ago