Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I\'m a blind student. I need help. I have this assignment due in three days a

ID: 3789299 • Letter: H

Question

Hi I'm a blind student. I need help. I have this assignment due in three days and I have no idea how to start it.

In enrollment.cpp, declare a struct named Course with three data members, one being a string containing the course name, an int containing the max enrollment of that course, and a second int containing the current enrollment in that course.

Rewrite the enrollment.cpp code to make use of your new structured type. The //** markers in the code are hints as to what needs to be changed.

Test your code carefully before submitting. Although a set of sample input files have been provided, you should also create your own for further testing/

Use the button below to submit your completed program.

Top of Form

Bottom of Form

2 Problem Description

Course Registration

Consider the development of a program to help manage university course registrations. Input consists of two files, whose names will be specified as command line parameters. The first file describes the courses available and the maximum enrollment that is permitted in each course. The second file contains requests for enrollment by various students. To simplify this assignment, we will assume that no student requests multiple enrollments in the same course.

Enrollment requests are accepted on a first-come, first-served basis, until the desired course is full. The program must therefore track the total number of enrollment requests accepted for each course.

The program will produce two sets of output. The first, written to standard output, is a log of how each enrollment request is handled. The second, written to a file, is a report on the total enrollment of each course. The name of the file to which this report should be written will be specified as a command line parameter.

Hence the program will be invoked with three command line parameters, e.g.,

./enrollment courseList.txt requests.txt outputReport.csv

The actual program name (shown in italics) will vary depending on how you compile the code and what operating system on which you are running it. If you are running your program from inside an IDE (e.g., Code::Blocks), you will need to specify the command line parameters when you run your tests.

2.1 Input Format

The first file named in the command line describes the courses available and looks like:

47

CS100 50

CS101 30

MATH241 25

The first line of input contains a non-negative integer indicating how many courses are being offered. After that will be that number of additional lines, each describing a single course, giving the course name and the maximum enrollment for that course. Course names are a mixture of alphabetic and numeric characters but will not contain any internal blank spaces. The maximum enrollment for each course will be a positive number no larger than 250.

The second file contains student enrollment requests and looks like this:

ART150 Doe, John

CS100 Doe, John

MATH241 Smith, Jane

CS100 Smith, Jane

MATH241 Doe, John

Each line has a single request, consisting of a course name followed by a student name.

2.2 Output Format

As each enrollment request is processed, the program will print to standard output (cout) one of two messages:

student-name has enrolled in course-name student-name cannot enroll in course-name

with the appropriate substitutions for “student-name” and “course-name”. The “has enrolled” message is printed if the student’s enrollment request is for an existing course that is not yet full. The “cannot enroll” message is printed if the requested course was not in the original list of courses or if the course is full.

After all enrollment requests are processed, the program will print a report listing the total enrollment in each course.

The actual output format will be Comma-Separated Values (CSV) format. In this format, all non-numeric outputs are enclosed in double quotes (“… ”) and successive values are separated by a comma or a line break. You should produce one line for each course. Each line will contain the course name and its total enrollment. The courses should be listed in the order in which they occur in the first input file.

CSV is a popular format for data because it can be loaded into most spreadsheets. You might try loading your output into a spreadsheet to be certain that it is correctly formatted.

2.3 Example

If the program is run like this:

./enrollment courses1.dat requests1.dat report1.csv

where the input file courses1.dat contains

4

CS100 50

CS150 3

MATH241 25

HIST300A 5

and requests1.dat contains:

CS150 Doe, John

ART421 Doe, John

CS150 Jones, Jenna

MATH241 Jones, Jenna

CS150 Smith, Stanley

CS150 Ford, Henry

the output on the screen should be:

Doe, John has enrolled in CS150

Doe, John cannot enroll in ART421

Jones, Jenna has enrolled in CS150

Jones, Jenna has enrolled in MATH241

Smith, Stanley has enrolled in CS150

Ford, Henry cannot enroll in CS150

and the output in file report1.csv should be

"CS100",0

"CS150",3

"HIST300A",0

"MATH241",1

All of the files for this program can be found here: https://www.dropbox.com/sh/vdo3ijv3m4t1y8j/AADcTm8vhOuWD3SBbk9vlWo3a?dl=0

I don't know how I overlooked this assignment, but I need a miracle.

Explanation / Answer

----------------------------------- Enrollment.cpp ----------------------------------------------

#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct Course {
string courseName;
int maxEnrollment;
int currentEnrollment;
};

typedef struct Course Course; //** replace this!

/**
* Search through the array looking for a course whose name matches
* courseName.
*
* @param list[] list (array) of courses
* @param listLength number of courses in *list*
* @param courseName name for which to search
*
* @return int position of matching course, or -1 if no match is found.
*/
int search(const Course list[], int listLength, string courseName) {
int loc = 0;

//** replace list[loc] by *name* of course in list[loc]
while (loc < listLength && list[loc].courseName != courseName) {
++loc;
}

if (loc < listLength) {
return loc;
}
else {
return -1;
}
}

/**
* Read the course names and max enrollments. Keep the courses
* in alphabetic order by course name.
*
* @param courseFile input file stream from which to read the course listings
* @param numCourses number of courses
* @param courses list (array) of courses
*/
void readCourses (istream& courseFile, int numCourses, Course* courses) {
for (int i = 0; i < numCourses; ++i) {
string courseName;
int courseEnrollment = 0;
int courseMaxEnrollment;

courseFile >> courseName >> courseMaxEnrollment;

//** Replace the following line with two assignments,
//** one each for
//** - name of courses[i]
//** - max enrollement of courses[i]
courses[i].courseName = courseName;
courses[i].maxEnrollment = courseMaxEnrollment;
}
}

/**
* Read the enrollment requests, processing each one and tracking
* the number of students successfully enrolled into each course.
*
* @param enrollmentRequestsFile input file stream from which to read the
* student enrollment requests
* @param numCourses number of courses
* @param courses list (array) of courses
*/
void processEnrollmentRequests (istream& enrollmentRequestsFile, int numCourses, Course* courses) {
// Read the requests, one at a time, serving each one
string courseName;
enrollmentRequestsFile >> courseName;

while (enrollmentRequestsFile) {
enrollmentRequestsFile >> ws;
string studentName;
getline (enrollmentRequestsFile, studentName);

int pos = search (courses, numCourses, courseName);
if (pos >= 0) {
// Found a matching course
int currentEnrollment = courses[pos].currentEnrollment; //** replace by enrollment of courses[pos]
int maxEnrollment = courses[pos].maxEnrollment; //** replace by max enrollment of courses[pos]
  
if (currentEnrollment < maxEnrollment) {
cout << studentName << " has enrolled in " << courseName << endl;

++currentEnrollment
courses[pos].currentEnrollment = currentEnrollment; //** replace to update enrollment in the courses array
}
else {
// course is full
cout << studentName << " cannot enroll in " << courseName << endl;
}
}
else {
// course does not exist
cout << studentName << " cannot enroll in " << courseName << endl;
}

enrollmentRequestsFile >> courseName;
}
}

/**
* Write a CSV report listing each course and its enrollment.
*/
void generateReport (ostream& reportFile, int numCourses, Course* courses) {
for (int i = 0; i < numCourses; ++i) {
reportFile << '"'
<< courses[i].courseName //** replace by *name* of course #i
<< '"' << ","
<< courses[i].currentEnrollment //** replace by *enrollment* of course #i
<< endl;
}
}

/**
* Read all files, process all enrollments, and print a summary
*
* @param courseFile input file containing a listing of all courses
* @param enrollmentRequestsFile input file containing all enrollment requests
* @param reportFile output file into which will contain a CSV report
*/
void processEnrollments (istream& courseFile, istream& enrollmentRequestsFile, ostream& reportFile) {
int numCourses;
courseFile >> numCourses;

Course* courses = new Course[numCourses];

readCourses (courseFile, numCourses, courses);
processEnrollmentRequests (enrollmentRequestsFile, numCourses, courses);
generateReport (reportFile, numCourses, courses);
}

/**
* Main function
*
* @param argv[1] (input) course file
* @param argv[3] (input) enrollment file
* @param argv[4] (output) report file
*/
int main (int argc, char** argv) {
if (argc != 4) {
cerr << "Usage: " << argv[0] << " courseFile enrollmentFile reportFile" << endl;
return -1;
}

// Take input and output file names from the command line
ifstream coursesIn (argv[1]);
ifstream enrollmentIn (argv[2]);
ofstream reportOut (argv[3]);

processEnrollments (coursesIn, enrollmentIn, reportOut);

coursesIn.close();
enrollmentIn.close();
reportOut.close();

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote