#include #include #include using namespace std; //function prototypes //structure for course struct course { string name; string *days; int numDays; }; bool numGood(string); void popCourses(course * courses, int numCourses); void printCourses(course * courses, int numCourses); int main() { //initialize local variables course *courses; string numCourses; int num; bool inGood = false; //ask how many couses the user wants while(inGood == false) { cout << "How many courses do you want?: "; cin >> numCourses; inGood = numGood(numCourses); } //convert string to int num = atoi(numCourses.c_str()); courses = new course[num]; //populate the courses in the array popCourses(courses, num); //print the courses printCourses(courses, num); //free memory for(int u = 0; u < num; u++) { delete [] courses[u].days; } delete [] courses; return 0; } //check if user input is a good positive integer ////precondition:user has inputed a string for the number specified ////postcondition: the number is a valid floating point number or is not ////return:true if number is good, false if number is not good bool numGood(string input) { for(int x = 0; x < input.size(); x++) { if(input[x] < 48 || input[x] > 57) { cout << "Bad input, enter a new guess" << endl; return false; } } return true; } //populate the courses array void popCourses(course * courses, int numCourses) { for(int i = 0; i < numCourses; i++) { int days = 0; //get the name of the course cout << "Enter the name of this couse: "; cin >> courses[i].name; //get the days of the week of the course cout << "How many days a week is this class?: "; cin >> days; courses[i].numDays = days; courses[i].days = new string [days]; for(int j = 0; j < days; j++) { cout << "Enter day " << j+1 << ": "; cin >> courses[i].days[j]; } } } //print out the courses and info in them void printCourses(course *courses, int numCourses) { for(int l = 0; l < numCourses; l++) { cout << "Course: "; cout << courses[l].name; cout << "\n"; cout << "Days of the class: "; for(int h = 0; h < courses[l].numDays; h++) { cout << courses[l].days[h] << " "; } cout << endl; } }