In C Programming, Create the following Program: For this assignment we are going
ID: 3888655 • Letter: I
Question
In C Programming, Create the following Program:
For this assignment we are going to create the beginnings of a simple Grade Book. We will revisit this assignment again once we learn some new concepts For the purposes of this grade book you should first provide a menu with the following options: 1. Add a new course 2. Add a new student 3. Add a student to a course 4. Add grades for a student in a course 5. Print a list of all grades for a student in a course 6. Print a list of all students in a course 7. Compute the average for a student in a course 8. Print a list of all courses 9. Print a list of all students 10. Compute the average for a course Store Grade book (to a disk file) Load Grade book (from a disk file) 12. Each of these menu items should correspond to a function you will write For this basic program each student will be represented by an ID number and each course by a course number. No other date is required to represent a course or student at this time Grades will be whole numbers only (no fractional part) As indicated in the menu you will need to store and load using a disk file so that the data is retained Here are some limiting values to help you in defining your data Maximum Number of students (total) 100 Max number of courses 25 Max number of courses per student 4 Max number of grades per student per course 10Explanation / Answer
1. Completed first four parts and formatting of the function
2. Update the placeholders
Code:
/* <<Update below details>>
Name:
Email:
Address:
Description:
Program to manage data for courses, studemts amd grades
*/
#include <stdio.h>
// Define upper limits instead of hardcoding in the program
#define MAXSTUDENTS 100
#define MAXCOURSES 25
#define MAXCOURSESPERSTUDENT 4
#define MAXGRADESPERSTUDENTPERCOURSE 10
// A course is represented by a courseNumber
struct Course{
int courseNumber;
}courses[MAXCOURSES];
// A student is represented by a ID number
struct Student{
int ID;
}students[MAXSTUDENTS];
// A grade is represented by a whole number
struct Grade{
int score;
};
// Store information for a student, his enrolled course and the grades
struct GradeBook{
struct Student s;
struct Course c;
struct Grade g;
}gb[MAXSTUDENTS];
int stuCounter = 0; // Counter to maintain number of students
int couCounter = 0; // Counter to maintain number of courses
int gradeBookSize = 0; // Size of gradeBook
// Methods for each menu option
/*
Return index an integer number begin from start an array,
otherwise return -1.
*/
int indexOfStudent(int id) {
for (int i = 0; i < stuCounter; ++i) {
if (students[i].ID == id) {
return i;
}
}
return -1;
}
int indexOfCourse(int courseNumber) {
for (int i = 0; i < couCounter; ++i) {
if (courses[i].courseNumber == courseNumber) {
return i;
}
}
return -1;
}
// Add student to gradebook
void addStudent(){
int id;
printf("Enter student ID: ");
scanf("%d",&id);
students[stuCounter++].ID = id;
}
// Add course to the system
void addCourse(){
int num;
printf("Enter course number: ");
scanf("%d",&num);
courses[couCounter++].courseNumber = num;
}
// Count the number of courses for which student has enrolled
int numOfCoursesStudentEnrolled(int stuID){
int count = 0;
for (int i = 0; i < gradeBookSize; ++i) {
if (gb[i].s.ID == stuID) {
count++;
}
}
return count;
}
// Add student to course in gradebook
void addStudentToCourse(){
int id;
int num;
printf("Enter student ID: ");
scanf("%d",&id);
printf("Enter course number: ");
scanf("%d",&num);
if(gradeBookSize<MAXSTUDENTS){
// Save data for Student in gradebook if Student is added in student array and course is also added in the list
// Save data only if student has enrolled to courses less than MAXCOURSESPERSTUDENT
if(indexOfStudent(id)!= -1 && indexOfCourse(num)!= -1 && numOfCoursesStudentEnrolled(id)<MAXCOURSESPERSTUDENT){
gb[gradeBookSize].s.ID = id;
gb[gradeBookSize].c.courseNumber = num;
gradeBookSize++;
}else{
printf("Student not enrolled or has enrolled for more than 4 courses ");
}
}
}
// Add grades for a students in course
void addGradesForStudents(){
int id;
int num;
int grade;
int flag = 0;
printf("Enter student ID: ");
scanf("%d",&id);
printf("Enter course number: ");
scanf("%d",&num);
printf("Enter grade: ");
scanf("%d",&grade);
if(grade<MAXGRADESPERSTUDENTPERCOURSE){
for(int i =0; i<gradeBookSize ; i++){
if(gb[i].s.ID == id && gb[i].c.courseNumber == num){
gb[i].g.score = grade;
flag = 1;
}
}
if(flag == 0){
printf("Invalid student and course selection ");
}
}else{
printf("Grade value is more than %d ",MAXGRADESPERSTUDENTPERCOURSE);
}
}
int main()
{
int choice;
// Initial information about the owner of program <<update this information>>
printf("Starting gradebook program ");
printf("Department: Course: Program Number: Name: Email: ");
do{ // Use do while loop to take input from user atleast once
// Display menu
printf(" ================Menu=============== ");
printf("1. Add a new course ");
printf("2. Add a new student ");
printf("3. Add a new student to course ");
printf("4. Add grades for student in a course ");
printf("5. Print a list of all grades for a student in a course ");
printf("6. Print a list all students in a course ");
printf("7. Compute the average for a student in a course ");
printf("8. Print a list all courses ");
printf("9. Print a list all students ");
printf("10. Compute the average for a course ");
printf("11. Store Grade book (to a disk file) ");
printf("12. Load Grade book (from disk file) ");
scanf("%d",&choice);
// Use switch case to invoke function as per the selection
switch(choice){
case 1: addCourse(); break;
case 2: addStudent(); break;
case 3: addStudentToCourse(); break;
case 4: addGradesForStudents(); break;
case 5: break;
case 6: break;
case 7: break;
case 8: break;
case 9: break;
case 10: break;
case 11: break;
case 12: break;
}
}while(choice>=1 && choice<=12); // Choice should be one out of the 12 options else quit
return 0;
}