Question
In the attached incomplete file, please complete the load and print functions using C++, as well as the 's' case of the switch in main.
In the attached incomplete file, please complete the load and print functions using C++, as well as the 's' case of the switch in main.
Please don't add any header file.
--------------------------------------------------------------------------
#include
#include
#include
using namespace std;
struct Student {
string firstName;
string lastName;
int id;
};
class Course {
private:
string name;
int crn;
int section;
Student students[100];
int numStudents;
public:
Course() {
}
Course(string n, int c, int s) {
name = n;
crn = c;
section = s;
numStudents = 0;
}
void modifyInfo(string n, int c, int s) {
name = n;
crn = c;
section = s;
numStudents = 0;
}
int getCrn() {
return crn;
}
void addStudent(Student stu) {
students[numStudents].firstName = stu.firstName;
students[numStudents].lastName = stu.lastName;
students[numStudents].id = stu.id;
numStudents++;
}
};
void load(Course schedule[100], int& numCourses);
void print(Course schedule[100], int numCourses);
int main() {
// init vars
Course schedule[100];
int numCourses = 0;
char sc = 'a';
// menu loop
while(sc != 'e') {
// prompt and get menu choice
cout << endl << endl << endl
<< "Would you like to load, print, add a student, add a course, or exit (l/p/s/c/e): ";
cin >> sc;
// choose function based on user input
switch(sc) {
case 'e':
cout << "Thanks for using the roster program!";
break;
case 'l':
load(schedule, numCourses);
break;
case 'p':
print(schedule);
break;
case 'c':
string name;
int crn, section;
cout << "Please enter the course name, crn and section: ";
cin >> name >> crn >> section;
schedule[numCourses].modifyInfo(name, crn, section);
numCourses++;
break;
case 's':
// get the crn of the course
cout << "Please enter the crn of the course you'd like to add a student to: ";
int crn;
cin >> crn;
// find which course in the array that corresponds to that crn
// create the student and add the student that course
break;
default:
cout << "That was not a valid option, please try again!";
}
}
return 0;
}
// this function gets the file path from the user
// then opens the file, reads it with a loop,
// and saves the data read from the file into the array
void load(Course schedule[100], int numCourses) {
// does course exist already?
// if so, add student to it
// if not, create the course and add the student
}
// this function prints the contents of the array
// prettily using the setw function (#include
void print(Course schedule[100], int numCourses) {
}
--------------------------
enrollment.txt
-------------------------
Carson HILL 3818467 CS140U 46123 1
Ryder GREEN 3819169 CS140U 46123 1
Aria BENNETT 3829358 CS161 49372 2
Evelyn COOPER 3805705 CS140U 47263 2
Alexa REYES 3816827 CS161 48793 1
Skylar POWELL 3802995 CS161 49372 2
Jace ROBINSON 3805436 CS161 48793 1
Aaron BROWN 3803902 CS133G 42761 1
Camila SULLIVAN 3812382 CS161 48793 1
Angel MOORE 3819718 CS140U 47263 2
Kayden PHILLIPS 3821726 CS161 48793 1
Jason BAKER 3801869 CS161 49372 2
Ella BELL 3826299 CS140U 47263 2
Paisley ORTIZ 3828703 CS161 48793 1
Gavin LEE 3830333 CS133G 42761 1
Evelyn COOPER 3815141 CS161 48793 1
Ava EDWARDS 3806868 CS260 40293 1
Ezra MITCHELL 3832662 CS260 40293 1
Mateo GREEN 3812859 CS133G 42761 1
Carson HILL 3827529 CS160 42938 3
Angel MOORE 3803035 CS160 42093 1
Xavier RAMIREZ 3800288 CS160 43870 2
Zachary NELSON 3808942 CS140U 46123 1
Blake EVANS 3827446 CS140U 47263 2
Nora MORALES 3806729 CS160 42093 1
Emma TORRES 3815006 CS161 48793 1
Anna RUSSELL 3803548 CS133U 43875 1
Nolan GONZALEZ 3824084 CS140U 46123 1
Abigail MORRIS 3811840 CS160 43870 2
Natalie WATSON 3813931 CS160 42938 3
Ezra MITCHELL 3832439 CS160 43870 2
Nolan GONZALEZ 3805537 CS160 42938 3
Lincoln JACKSON 3802082 CS133U 43875 1
Carson HILL 3804833 CS140U 47263 2
Ayden ADAMS 3829658 CS140U 46123 1
Easton HALL 3813977 CS160 43870 2
Addison DIAZ 3822386 CS161 48793 1
Bentley ROBERTS 3826924 CS161 49372 2
Aubrey HOWARD 3805829 CS260 40293 1
Addison DIAZ 3805097 CS161 49372 2
Audrey LONG 3813290 CS161 48793 1
Jaxson SCOTT 3822355 CS260 40293 1
Mia FLORES 3815574 CS161 48793 1
Sophia COLLINS 3827350 CS160 42093 1
Carson HILL 3821724 CS160 43870 2
Easton HALL 3831107 CS161 48793 1
Jeremiah DAVIS 3811337 CS260 40293 1
Savannah FOSTER 3827753 CS133G 42761 1
Bentley ROBERTS 3808909 CS133U 43875 1
Charlotte MURPHY 3824221 CS160 42938 3
Gavin LEE 3824946 CS160 43870 2
Easton HALL 3816413 CS160 42938 3
Ryder GREEN 3832591 CS161 49372 2
Mia FLORES 3817410 CS133U 43875 1
Parker HARRIS 3820537 CS160 42938 3
Penelope HUGHES 3827595 CS161 48793 1
Elias JOHNSON 3824350 CS161 48793 1
Jaxson SCOTT 3809374 CS160 42093 1
Ellie GUTIERREZ 3824021 CS160 42938 3
Violet BARNES 3819668 CS140U 46123 1
Alexa REYES 3804734 CS133G 42761 1
Violet BARNES 3826418 CS160 42938 3
Ryder GREEN 3803788 CS260 40293 1
Ella BELL 3803728 CS133G 42761 1
Blake EVANS 3822483 CS260 40293 1
Austin LOPEZ 3814310 CS260 40293 1
Brayden TAYLOR 3809514 CS133U 43875 1
Angel MOORE 3818935 CS161 48793 1
Ryder GREEN 3805249 CS133U 43875 1
Abigail MORRIS 3822798 CS133G 42761 1
Parker HARRIS 3811008 CS140U 46123 1
Josiah RODRIGUEZ 3814989 CS161 49372 2
Ariana JENKINS 3820485 CS133G 42761 1
Leo CAMPBELL 3830523 CS260 40293 1
Nicholas THOMAS 3809503 CS160 42938 3
Ryder GREEN 3813458 CS160 42938 3
Brooklyn JAMES 3819796 CS160 42938 3
Alexa REYES 3819589 CS160 42938 3
Josiah RODRIGUEZ 3827157 CS161 49372 2
Gavin LEE 3818538 CS161 49372 2
Jason BAKER 3824179 CS160 42093 1
Emily NGUYEN 3807958 CS161 48793 1
Robert HERNANDEZ 3822888 CS160 43870 2
Colton MARTINEZ 3816202 CS140U 46123 1
Zoey COX 3820055 CS160 42938 3
Sawyer CARTER 3826362 CS160 43870 2
Lillian WOOD 3828433 CS133U 43875 1
Xavier RAMIREZ 3823844 CS160 43870 2
Alexa REYES 3831998 CS161 49372 2
Olivia PARKER 3810021 CS133U 43875 1
Emily NGUYEN 3828476 CS161 49372 2
Samantha ROSS 3805075 CS161 49372 2
Ryder GREEN 3802510 CS133G 42761 1
Victoria KELLY 3817861 CS160 42938 3
Theodore SMITH 3809789 CS140U 47263 2
Nolan GONZALEZ 3805002 CS140U 47263 2
Zoe CRUZ 3810285 CS160 42938 3
Chase LEWIS 3828617 CS260 40293 1
Jose ALLEN 3830932 CS133U 43875 1
Isabella STEWART 3825721 CS133U 43875 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started