So I have this program that I am struggling heavily with and have no clue on what to do. Below is what i have thus far as well as the assignment, i was hoping to get some sort of help with it or at least get pointed in the right direction. Thanks!
Assignment:
Create a program that allows a user to view and alter a class schedule. To make the class
schedule, you’ll need to use two string vectors: courseCodes and courseNames.
Note: Throughout the lab, you can assume the user will enter the correct data type you’re
expecting. So, if you’re asking for an integer, assume they will correctly always enter an integer.
Your program should utilize four functions:
● main
○ Parameters: none
○ Return value: 0
○ Purpose: Loop through the user menu letting the user choose options until they’d
wish to stop
● viewSchedule
○ Parameters: codes and class names (both by reference)
○ Return value: none
○ Purpose: display all the items in the vectors. Keep each course code in line with
the corresponding course name
● addClass
○ Parameters: codes and class names (both by reference)
○ Return value: 0 on successful add, 1 on unsuccessful add
○ Purpose: add a course to the vectors. Course codes should be checked for being
exactly four characters long -- if it’s not, return 1 and end function. If it is, add to
the code vector, query for the course name and add to the name vector. Return 0
● removeClass
○ Parameters: codes and class names (both by reference)
○ Return value: 0 on successful remove, 1 on unsuccessful remove
○ Purpose: remove a course from the vectors. Should not display the vectors here.
Ask the user which item they’d like to remove … check to see if the number is
valid (0 < number <= vector size). Return 1 on invalid, remove vector positions
from both and return 0 on valid
The main function should contain a menu, as noted above. The menu should consist of four
options:
● Exit
○ Exit the menu
● View Schedule
○ Check to see if the vector contents aren’t empty
○ Call view schedule function if they aren’t
● Add Class
○ Call add class function
○ Check to see if 0 or 1 -- tell the user whether a successful addition occurred or
not
● Remove Class
○ Check to see if the vector contents aren’t empty
○ If they aren’t
■ Display vector contents
■ Call remove class function
■ Check to see if 0 or 1 -- tell the user whether a successful removal
occurred or not
● Incorrect menu option
○ Display an error to the user that the menu option isn’t valid
Hints:
For the course name, you will need to get the entire contents of the line. So, if they entered in
“Intermediate Programming” or “Introduction to Computer Programming”, make sure you get the
entire line.
The string function “getline” is very useful for this, as the vectors are string type. You’ll find, if
you try to mix the input types:
● cin << variable
● getline(cin, variable)
That a getline following a “cin << variable” line will be skipped. There are two solutions to this:
● Make all your variables strings (even menu option queries) and make every input a
getline statement
● Put the line “cin.ignore()” before you run your getline command if you’ve mixed “cin <<
variable” statements in your code
at this point it seems that you didn't either read the assignment
`addClass()' the only function that you code
addClass
○ Parameters: codes and class names (both by reference)
○ Return value: 0 on successful add, 1 on unsuccessful add
○ Purpose: add a course to the vectors. Course codes should be checked for being
exactly four characters long
it should be
1 2 3 4 5 6 7 8 9 10 11 12 13
int //error code
addClass(std::vector<std::string> &codes, std::vector<std::string> &names){
std::string code;
//¿do you need to do input here?
if(code.length() == 4){
//...
return 0; //success
}
else{
//...
return 1;
}
}
so, remove your global obj1 and respect the prototypes