Gradebook Program Help?

I'm trying to make a program that'll add students and their ID's as well as courses. I'm stuck on the part of putting students into courses. I was thinking of using a 2D Array of strings but I don't know how to approach it. Any help would be appreciated. Here's my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <string>
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;

const int max_students = 25;
const int max_courses = 10;

int main()
{

	string courses[max_courses]; //Array of strings for the courses
	string course_id[max_courses]; //Array of strings for the course id
	string student[max_students]; //Array of strings for the student names
	string student_id[max_students]; //Array of strings for the students id
	string major[max_students]; //Array of strings for the student majors
	string addstutocourse[100][10] = {}; //2D array to store students to courses

	int choice = 0;
	
	



	do //Loop to keep the decision going if you need to repick
	{
		cout << "Please make a decision..." << endl;
		cout << "1.) Add course. " << endl;
		cout << "2.) Add student. " << endl;
		cout << "3.) Add student to course. " << endl;
		cout << "4.) Add grades for student in a course. " << endl;
		cout << "5.) Show all courses. " << endl;
		cout << "6.) Show all students. " << endl;
		cout << "7.) Show all students in a course. " << endl;
		cout << "8.) Find the average for a student. " << endl;
		cout << "9.) Quit. " << endl;
		cin >> choice;
		/*switch statement for every situation you pick.*/
		
		switch (choice) 
		{
			case 1: 
				int i;
				cout << "How many courses have you entered so far? (i.e. if you haven't entered a course yet, then you've entered 0 courses.)" << endl;
				cin >> i; //Sets the beginning of the array 
				if(i >= max_courses) //Checks to see if there are already the maximum number of classes inputted. (10 is the max)
				{
					cout << "I'm sorry, but you've already entered too many courses. Shutting down..." << endl;
					return 0;
				}
				cout << "Whats the name of the course?" << endl;
				cin.ignore();
				getline(cin, courses[i]); //Uses the array of the courses
				cout << "Whats the ID number of the course?" << endl;
				cin >> course_id[i];
				cout << "Course " << courses[i] << " " << course_id[i] << " was added!" << endl;
			break;
			case 2:
				int student_num;
				cout << "How many students have you entered so far? (If none then please select 0)" << endl;
				cin >> student_num;
				if(i >= max_students)
				{
					cout << "I'm sorry but you've already entered too many students. Shutting down..." << endl;
					return 0;
				}
				cout << "What's the student's last name?" << endl;
				cin >> student[student_num];
				cout << "What's the student's ID number?" << endl;
				cin >> student_id[student_num];
				cout << "What's the student's major? (i.e. CSCE, English, Math.)" << endl;
				cin >> major[student_num];
				cout << "Student has been added!" << endl;
			break;
			case 3:
				
			break;
			case 4:;
			break;
			case 5:
				cout << "All the courses entered so far." << endl;
				for(int i = 0; i < 10; i++)
				{
					cout << courses[i] << " " << course_id[i] << endl;
				}
			break;
			case 6:
				cout << "All students entered so far along with their majors." << endl;
				for(int i = 0; i < 25; i++)
				{
					cout << student[i] << " " << student_id[i] << " " << major[i] << endl;
				}
			break;
			case 7:;
			break;
			case 8:;
			break;
		};
	}while (choice != 9); //quits the loop

	return 0;
}
Last edited on
Ok,
Make a string array of all possible courses to take. In each Student, have a string array that contains the name of the courses that they are enrolled in. Then add a AddCourse() function to the Student class.
You should be all set.
Good luck!
okay guys I got it to added students to a course and show how many are in the course. i'm having trouble with the grades. here is my updated code. Please help ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <string> 
#include <cstring>
#include <iostream>
#include <cstdlib>
using namespace std;

const int max_students = 25; //Global constant to display the max students
const int max_courses = 10;  //Global constant to display max courses

int main()
{
	
	string courses[max_courses]; //Array of strings for the courses
	string course_id[max_courses]; //Array of strings for the course id
	string student[max_students]; //Array of strings for the student names
	string student_id[max_students]; //Array of strings for the students id
	string major[max_students]; //Array of strings for the student majors
	string addstutocourse[max_courses][11]; //2D array to store students with their courses
	int grades[5]; //1D array for grades for each course

	int choice = 0;
	
	



	do //Loop to keep the decision going if you need to repick
	{
		cout << "Please make a decision..." << endl;
		cout << "1.) Add course. " << endl;
		cout << "2.) Add student. " << endl;
		cout << "3.) Add student to course. " << endl;
		cout << "4.) Add grades for student in a course. " << endl;
		cout << "5.) Show all courses. " << endl;
		cout << "6.) Show all students. " << endl;
		cout << "7.) Show all students in a course. " << endl;
		cout << "8.) Find the average for a student. " << endl;
		cout << "9.) Quit. " << endl;
		cin >> choice;
		/*switch statement for every situation you pick.*/
		
		switch (choice) 
		{
			case 1: 
			{
				int i;
				cout << "How many courses have you entered so far? (i.e. if you haven't entered a course yet, then you've entered 0 courses.)" << endl;
				cin >> i; //Sets the beginning of the array 
				if(i >= max_courses) //Checks to see if there are already the maximum number of classes inputted. (10 is the max)
				{
					cout << "I'm sorry, but you've already entered too many courses. Shutting down..." << endl;
					return 0;
				}
				cout << "Whats the name of the course?" << endl;
				cin.ignore();
				getline(cin, courses[i]); //Uses the array of the courses
				cout << "Whats the ID number of the course?" << endl;
				cin >> course_id[i];
				addstutocourse[i][0] = courses[i]; //Adds the course to the full roster for students
				cout << "Course " << courses[i] << " " << course_id[i] << " was added!" << endl; //Displays a confirmation message
			}
			break;
			case 2:
			{
				int student_num; //Number of students so far
				cout << "How many students have you entered so far? (If none then please select 0)" << endl;
				cin >> student_num; //Enter the amount of students you've entered so far
				if(student_num >= max_students) //Checks to see if you already added the max number of students
				{
					cout << "I'm sorry but you've already entered too many students. Shutting down..." << endl;
					return 0; //Will shut down the program
				}
				cout << "What's the student's last name?" << endl; //Grabs the student's name
				cin >> student[student_num];
				cout << "What's the student's ID number?" << endl; //Grab the student's ID number
				cin >> student_id[student_num];
				cout << "What's the student's major? (i.e. CSCE, English, Math.)" << endl; //Grab the student's major
				cin >> major[student_num];
				cout << "Student " << student[student_num] << " " << student_id[student_num] << " " << major[student_num] << " has been added!" << endl; //Confirmation message
			}
			break;
			case 3:
			{
				string name; //Ask for the student name
				string cname; //Ask for the course name
				cout << "Student name: ";
				cin >> name;
				for (int x = 0; x < max_students; x++) //For loop to go through array to see if there is a student with this name already
				{
						if(student[x] == name)
						{
							cout << "Which course would you like to add " << student[x] << " too?" << endl;
							cin.ignore();
							getline(cin, cname);
							for(int y = 0; y < max_courses; y++) //For loop to go through the courses to see if this course has been added already
							{
								if(courses[y] == cname) //If the course is there then this will add the student
								{
									int num;
									cout << "How many students do you have in " << courses[y] << "?" << endl;
									cin >> num;
									addstutocourse[y][num + 1] = name;
									cout << "Process complete!" << endl;
									
								}
							}
						}
				}
			}
			break;
			case 4:
			/*{
				string stu_name;
				cout << "Which student would you like to see the grades of?" << endl;
				cin >> stu_name;
				for (int a = 0; a < max_students; a++)
				{
					if(student[a] == stu_name)
					{
						cout << "Which course would you like to see the grades for?" << endl;
						string cour_name;
						for (int b = 0; b < max_courses; b++)
						{
							if(courses[b] == cour_name)
							{
								
							}
						}
					}
				}
			}*/;
			break;
			case 5:
			{
				cout << "All the courses entered so far." << endl;
				for(int i = 0; i < 10; i++) //A for loop to display all of the courses you've added along with their ID numbers
				{
					cout << courses[i] << " " << course_id[i] << endl;
				}
			}
			break;
			case 6:
			{
				cout << "All students entered so far along with their majors." << endl;
				for(int i = 0; i < 25; i++) // A for loop to display all student names along with their majors
				{
					cout << student[i] << " " << student_id[i] << " " << major[i] << endl;
				}
			}
			break;
			case 7:
			{
				string see_course; //String variable to see which course you would like to see the roster of.
				cout << "Which course would you like to see?" << endl;
				cin.ignore();
				getline(cin, see_course); //Gets the line of the course you entered
				for (int m = 0; m < max_courses; m++) //For loop to find the course that was entered to see the roster of
					if(courses[m] == see_course)
					{
						for (int n = 1; n < 11; n++) //For loop to display the roster of the course
						{
							cout << "Roster for " << endl;
							cout << addstutocourse[m][n] << endl;
						}
					}
			}
			break;
			case 8:;
			break;
		};
	}while (choice != 9); //Quits the loop

	return 0;
}
Topic archived. No new replies allowed.