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
11. Store Grade book (to a disk file)
12. Load Grade book (from a disk file)
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 10 Be s
The following is the required programs as per the requirements in the question.
Code to copy is given at the end. Get back to me if you have any doubt.
Screenshot of the Program Code:
Header.h:
FunDef.cpp
main.cpp:
Screenshot of the Sample Output:
Code to Copy:
Header.h:
#pragma once
//header.h
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <fstream>
struct student
{
std::string lname;
std::string fname;
int id;
float grades1[10];
float grades1_avg;
float grades2[10];
float grades2_avg;
float grades3[10];
float grades3_avg;
float grades4[10];
float grades4_avg;
int class_count;
};
struct course
{
std::string name;
int id;
float *enrolled_students[20];
int roll;
};
// add a course
void add_course(student* s, course* c);
// add a student
void add_student(student* s, course* c);
//Add a student to a course
void student_to_course(student* s, course* c);
//Add grades for a student in a course
void add_grades(student* s, course* c);
//Print a list of all grades for a student in a course
void print_grades(student* s, course* c);
//Print a list of all students in a course
void print_students_in_course(student* s, course* c);
//Compute the average for a student in a course
void student_avg(student* s, course* c);
//Print a list of all courses
void print_courses(student* s, course* c);
//Print a list of all students
void print_students(student* s, course* c);
//Compute the average for a course
void course_avg(student* s, course* c);
//Store gradebook
void save_stream(std::ofstream& out_file, student* s, course* c);
//Load gradebook
void load_stream(std::ifstream& in_file, student* s, course* c);
FunDef.cpp
//== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
//FunDef.cpp
#include "stdafx.h"
#include "header.h"
using namespace std;
int num_courses = 0, num_students, COURSES = 25, STUDENTS = 100,
ENROLLMENT = 20, MAXCLASSES = 4, MAXGRADES = 10;
// add courses to grade book
void add_course(student* s, course* c)
{
string name;
int number, i;
cout << "\n********************************************************\n";
cout << "This option allows you to add a course to the catalog.\n";
cout << "********************************************************\n\n";
cout << "What is the course name? "; cin >> name;
cout << "What is the course number? "; cin >> number;
for (int i = 0; i < (num_courses); i++)
{
// if course does exist
if (number == c[i].id && name == c[i].name)
{
cout << "\n******************************\n";
cout << "Course already exists.\n";
cout << "******************************\n";
return;
}
}
// if grade book is full
if (num_courses == COURSES)
{
cout << "\n**************************************************************\n";
cout << "You have reached the course limit. Please select a new option.\n";
cout << "**************************************************************\n";
return;
}
// add course to grade book
c[num_courses].name = name;
c[num_courses].id = number;
// confirm course addition
cout << endl << c[num_courses].name << " "
<< c[num_courses].id << " added as a course.\n";
// increment grade book course counter
num_courses++;
return;
}
void add_student(student* s, course* c)
{
int number;
string fname, lname;
cout << "\n***********************************************************\n";
cout << "This option allows you to add a student to the student body.\n";
cout << "************************************************************\n\n";
cout << "What is the student's name(Last, First)? "; cin >> lname >> fname;
cout << "What is the student's ID? "; cin >> number;
// search existing students for repeat
for (int i = 0; i < num_students; i++)
{
// if student already exists
if (number == s[i].id)
{
cout << "\n******************************\n";
cout << "Student already exists.\n";
cout << "******************************\n";
return;
}
}
// if grade book is full
if (num_students == STUDENTS)
{
cout << "\n***************************************************************\n";
cout << "You have reached the student limit. Please select a new option.\n";
cout << "***************************************************************\n";
return;
}
// add student to grade book
s[num_students].id = number;
s[num_students].lname = lname;
s[num_students].fname = fname;
// confirm addition of student
cout << endl << s[num_students].lname << ", " << s[num_students].fname << " "
<< s[num_students].id << " added as a student.\n\n";
// increment grade book student counter
num_students++;
return;
}
void student_to_course(student* s, course* c)
{
float *pstudent = nullptr;
string cname;
int snumber, cnumber, student_name, student_enrollment, course_enrollment = 0;
cout << "\n******************************************\n";
cout << "This option enrolls a student in a course.\n";
cout << "******************************************\n";
cout << "\nWhat is the student's ID#? "; cin >> snumber;
cout << "\n************************\n\n";
cout << "What is the course name? "; cin >> cname;
cout << "What is the course number? "; cin >> cnumber;
// search for student in grade book
for (int i = 0; i < num_students; i++)
{
// if student is found in gradebook
if (snumber == s[i].id)
{
student_enrollment = s[i].class_count;
// check number of classes student is enrolled in
switch (student_enrollment)
{
case 0:
pstudent = &s[i].grades1[0];
// increment student enrollment counter
s[i].class_count++;
break;
// if student is enrolled in one class
case 1:
// get address of second student grade book
pstudent = &s[i].grades2[0];
// increment student enrollment counter
s[i].class_count++;
break;
// if student is enrolled in two classes
case 2:
// get address of second student grade book
pstudent = &s[i].grades3[0];
// increment student enrollment counter
s[i].class_count++;
break;
// if student is enrolled in three classes
case 3:
// get address of third student gradebook
pstudent = &s[i].grades4[0];
// increment student enrollment counter
s[i].class_count++;
break;
default:
// student cannot be enrolled in any more classes
cout << "Student enrolled in maximum classes.\n";
return;
}
}
// if student cannot be found
else if (i == num_students)
{
cout << "\n******************\n";
cout << "Student not found.\n";
cout << "******************\n";
return;
}
}
// search for class
for (int i = 0; i < num_courses; i++)
{
// found class
if (cname == c[i].name && cnumber == c[i].id)
{
// get course enrollment counter
course_enrollment = c[i].roll;
// check course enrollment counter
switch (course_enrollment)
{
// if no one is enrolled in the class
case 0:
// point class roll to the student grade book address
c[i].enrolled_students[0] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if one person is enrolled in the class
case 1:
// point class roll to the student grade book address
c[i].enrolled_students[1] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if two people are enrolled in the class
case 2:
// point class roll to the student grade book address
c[i].enrolled_students[2] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if three people are enrolled in the class
case 3:
// point class roll to the student grade book address
c[i].enrolled_students[3] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if four people are enrolled in the course
case 4:
// point class roll to the student grade book address
c[i].enrolled_students[4] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if five people are enrolled in the course
case 5:
// point class roll to the student grade book address
c[i].enrolled_students[5] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if six people are enrolled in the course
case 6:
// point class roll to the student grade book address
c[i].enrolled_students[6] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if seven people are enrolled in the course
case 7:
// point class roll to the student grade book address
c[i].enrolled_students[7] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if eight people are enrolled in the course
case 8:
// point class roll to the student grade book address
c[i].enrolled_students[8] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if nine people are enrolled in the course
case 9:
// point class roll to the student grade book address
c[i].enrolled_students[9] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if ten people are enrolled in the course
case 10:
// point class roll to the student grade book address
c[i].enrolled_students[10] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if eleven people are enrolled in the course
case 11:
// point class roll to the student grade book address
c[i].enrolled_students[11] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if twelve people are enrolled in the class
case 12:
// point class roll to the student grade book address
c[i].enrolled_students[12] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if thirteen people are enrolled in the class
case 13:
// point class roll to the student grade book address
c[i].enrolled_students[13] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// point class roll to the student grade book address
case 14:
// point class roll to the student grade book address
c[i].enrolled_students[14] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if fifteen people are enrolled in the class
case 15:
// point class roll to the student grade book address
c[i].enrolled_students[15] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if sixteen people are enrolled in the class
case 16:
// point class roll to the student grade book address
c[i].enrolled_students[16] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if seventeen people are enrolled in the class
case 17:
// point class roll to the student grade book address
c[i].enrolled_students[17] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if eighteen people are enrolled in the course
case 18:
// point class roll to the student grade book address
c[i].enrolled_students[18] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if nineteen people are enrolled in the course
case 19:
// point class roll to the student grade book address
c[i].enrolled_students[19] = pstudent;
// increment class counter
c[i].roll++;
cout << "\n******************************\n";
cout << "Student successfully enrolled.\n";
cout << "******************************\n";
break;
// if no more room is left in the class
default:
cout << "\n***************\n";
cout << "Course is full.\n";
cout << "***************\n";
return;
}
}
}
return;
}
void add_grades(student* s, course* c)
{
char ans;
string cname;
int snumber, cnumber, student_grading = 0;
float *pstudent1 = nullptr, *pstudent2 = nullptr, *pstudent3 = nullptr, *pstudent4 = nullptr;
cout << "\n***************************************************\n";
cout << "This option inputs grades for a student in a course.\n";
cout << "***************************************************\n\n";
cout << "What is the student's ID number? "; cin >> snumber;
// search student grade book
for (int i = 0; i < STUDENTS; i++)
{
// if student is found
if (snumber == s[i].id)
{
// get addresses and location of student and their grade books
student_grading = i;
pstudent1 = &s[i].grades1[0];
pstudent2 = &s[i].grades2[0];
pstudent3 = &s[i].grades3[0];
pstudent4 = &s[i].grades4[0];
break;
}
// if student cannot be found
else if (i == STUDENTS - 1)
{
cout << "\n******************\n";
cout << "Student not found.\n";
cout << "******************\n";
return;
}
}
cout << "What is the course name? "; cin >> cname;
cout << "What is the course number? "; cin >> cnumber;
// search courses
for (int i = 0; i < COURSES; i++)
{
// if course is found
if (cname == c[i].name && cnumber == c[i].id)
{
// search enrollments
/*
I could have written this part better. I could have checked the
enrollment counter and confined my search to only enrolled slots.
*/
for (int j = 0; j < ENROLLMENT; j++)
{
// if students first grade book is enrolled in course
if (c[i].enrolled_students[j] == pstudent1)
{
// enter grades for student in student grade book
for (int k = 0; k < MAXGRADES; k++)
{
cout << "Please enter a numerical grade: ";
cin >> s[student_grading].grades1[k];
}
}
// if students second grade book is enrolled in course
else if (c[i].enrolled_students[j] == pstudent2)
{
// enter grades for student in student grade book
for (int k = 0; k < MAXGRADES; k++)
{
cout << "Please enter a numerical grade: ";
cin >> s[student_grading].grades2[k];
}
}
// if students third grade book is enrolled in course
else if (c[i].enrolled_students[j] == pstudent3)
{
// enter grades for student in student grade book
for (int k = 0; k < MAXGRADES; k++)
{
cout << "Please enter a numerical grade: ";
cin >> s[student_grading].grades3[k];
}
}
// if students third grade book is enrolled in course
else if (c[i].enrolled_students[j] == pstudent4)
{
// enter grades for student in student grade book
for (int k = 0; k < MAXGRADES; k++)
{
cout << "Please enter a numerical grade: ";
cin >> s[student_grading].grades4[k];
}
}
// if class is full
else if (j == ENROLLMENT)
{
cout << "Student not enrolled in class.\n";
return;
}
}
}
}
return;
}
void print_grades(student* s, course* c)
{
string cname;
int cnumber, snumber, student_grading = 0;
float *pstudent1 = nullptr, *pstudent2 = nullptr, *pstudent3 = nullptr, *pstudent4 = nullptr, *student_enrollment;
cout << "\n*********************************************************************\n";
cout << "This option allows you to print all grades for a student in a course.\n";
cout << "*********************************************************************\n\n";
cout << "What is the student's id number? "; cin >> snumber;
// search for student
for (int i = 0; i < STUDENTS; i++)
{
// if student is found
if (snumber == s[i].id)
{
// get position of student in grade book and addresses to student's grade books
student_grading = i;
pstudent1 = &s[i].grades1[0];
pstudent2 = &s[i].grades2[0];
pstudent3 = &s[i].grades3[0];
pstudent4 = &s[i].grades4[0];
break;
}
// if student is not found
else if (i == STUDENTS)
{
cout << "\n******************\n";
cout << "Student not found.\n";
cout << "******************\n";
return;
}
}
cout << "What is the course name? "; cin >> cname;
cout << "What is the course number? "; cin >> cnumber;
// search for course
for (int i = 0; i < MAXCLASSES; i++)
{
// if course is found
if (cname == c[i].name && cnumber == c[i].id)
{
/*
search enrollments. this is another section I could have written better.
I could have made use of the enrollment counter each class has, and only
searched within that range.
*/
for (int j = 0; j < ENROLLMENT; j++)
{
// get address that course enrollment points to
student_enrollment = c[i].enrolled_students[j];
// if address of course enrollment and student grade book match
if (student_enrollment == pstudent1)
{
// print grades
for (int k = 0; k < MAXGRADES; k++)
cout << s[student_grading].grades1[k] << " ";
}
// if address of course enrollment and student grade book match
else if (student_enrollment == pstudent2)
{
// print grades
for (int k = 0; k < MAXGRADES; k++)
cout << s[student_grading].grades2[k] << " ";
}
// if address of course enrollment and student grade book match
else if (student_enrollment == pstudent3)
{
// print grades
for (int k = 0; k < MAXGRADES; k++)
cout << s[student_grading].grades3[k] << " ";
}
// if address of course enrollment and student grade book match
else if (student_enrollment == pstudent4)
{
// print grades
for (int k = 0; k < MAXGRADES; k++)
cout << s[student_grading].grades4[k] << " ";
}
// if student cannot be found in course enrollment
else if (j == ENROLLMENT)
{
cout << "Student not enrolled in class.\n";
return;
}
}
}
}
return;
}
void print_students_in_course(student* s, course* c)
{
string cname;
int cnumber, num_courses = 0;
float *student_enrollment;
cout << "\n*****************************************************************\n";
cout << "This option allows you to view all enrolled students in a course.\n";
cout << "*****************************************************************\n\n";
cout << "Enter a course name: ";
cin >> cname;
cout << "Enter course number: ";
cin >> cnumber;
// search for course
// a "Search Courses" function would have been really useful here
// I jumped in to writing code too quickly. I need to take more
// time planning out the modules so I can write reusable code
for (int num_courses = 0; num_courses < COURSES; num_courses++)
{
// if course is found
if (cname == c[num_courses].name && cnumber == c[num_courses].id)
{
cout << "\nStudent Name\tStudent Number\n";
cout << "------------\t--------------\n";
// search enrolled students
// again, I should have used the course enrollment counter here
for (int j = 0; j < ENROLLMENT; j++)
{
student_enrollment = c[num_courses].enrolled_students[j];
if (student_enrollment != 0)
{
// search students
for (int i = 0; i < STUDENTS; i++)
{
// if address of student grade book and course enrollment match
if (student_enrollment == &s[i].grades1[0])
{
// print out student name and id
cout << s[i].lname << ", " << s[i].fname << "\t" << s[i].id << endl;
break;
}
// if address of student grade book and course enrollment match
else if (student_enrollment == &s[i].grades2[0])
{
// print out student name and id
cout << s[i].lname << ", " << s[i].fname << "\t" << s[i].id << endl;
break;
}
// if address of student grade book and course enrollment match
else if (student_enrollment == &s[i].grades3[0])
{
// print out student name and id
cout << s[i].lname << ", " << s[i].fname << "\t" << s[i].id << endl;
break;
}
// if address of student grade book and course enrollment match
else if (student_enrollment == &s[i].grades4[0])
{
// print out student name and id
cout << s[i].lname << ", " << s[i].fname << "\t" << s[i].id << endl;
break;
}
}
}
}
break;
}
}
// class can't be found
if (num_courses == COURSES)
{
cout << "*****************\n";
cout << "Course not found.\n";
cout << "*****************\n";
}
return;
}
void student_avg(student* s, course* c)
{
string cname;
int cnumber, snumber, student_grading = 0, sum = 0;
float *pstudent1 = nullptr, *pstudent2 = nullptr, *pstudent3 = nullptr, *pstudent4 = nullptr, *student_enrollment;
cout << "\n*********************************************************************\n";
cout << "This option allows you to print the average for a student in a course.\n";
cout << "*********************************************************************\n\n";
cout << "What is the student's id number? "; cin >> snumber;
// search for student
for (int i = 0; i < STUDENTS; i++)
{
// if student is found
if (snumber == s[i].id)
{
// get location of student in grade book and addresses of student grade books
student_grading = i;
pstudent1 = &s[i].grades1[0];
pstudent2 = &s[i].grades2[0];
pstudent3 = &s[i].grades3[0];
pstudent4 = &s[i].grades4[0];
break;
}
// if student cannot be found
else if (i == STUDENTS - 1)
{
cout << "\n******************\n";
cout << "Student not found.\n";
cout << "******************\n";
return;
}
}
cout << "What is the course name? "; cin >> cname;
cout << "What is the course number? "; cin >> cnumber;
cout << s[student_grading].lname << ", " << s[student_grading].fname << " has an average of: ";
// search courses
for (int i = 0; i < MAXCLASSES; i++)
{ // if course is found
if (cname == c[i].name && cnumber == c[i].id)
{
// search enrollments in course
for (int j = 0; j < ENROLLMENT; j++)
{
// get address that enrollment points too
student_enrollment = c[i].enrolled_students[j];
// if student's first grade book address matches address that course enrollment points to
if (student_enrollment == pstudent1)
{
// add all grades in grade book and divide by total
for (int k = 0; k < MAXGRADES; k++)
sum += s[student_grading].grades1[k];
// assign to student's first grade average
s[student_grading].grades1_avg = (float)sum / MAXGRADES;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << s[student_grading].grades1_avg << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
cout.precision(100);
break;
}
// if student's second grade book address matches address that course enrollment points to
else if (student_enrollment == pstudent2)
{
// add all grades in grade book and divide by total
for (int k = 0; k < MAXGRADES; k++)
sum += s[student_grading].grades2[k];
// assign to student's second grade average
s[student_grading].grades2_avg = (float)sum / MAXGRADES;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << s[student_grading].grades2_avg << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
cout.precision(100);
break;
}
// if student's third grade book address matches address that course enrollment points to
else if (student_enrollment == pstudent3)
{
// add all grades in grade book and divide by total
for (int k = 0; k < MAXGRADES; k++)
sum += s[student_grading].grades3[k];
// assign to student's third grade average
s[student_grading].grades3_avg = (float)sum / MAXGRADES;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << s[student_grading].grades3_avg << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
cout.precision(100);
break;
}
// if student's fourth grade book address matches address that course enrollment points to
else if (student_enrollment == pstudent4)
{
// add all grades in grade book and divide by total
for (int k = 0; k < MAXGRADES; k++)
sum += s[student_grading].grades4[k];
// assign to student's fourth grade average
s[student_grading].grades4_avg = (float)sum / MAXGRADES;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << s[student_grading].grades4_avg << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
cout.precision(100);
break;
}
// if student is not enrolled in course
else if (j == ENROLLMENT)
{
cout << "\n******************************\n";
cout << "Student not enrolled in class.\n";
cout << "******************************\n";
return;
}
}
}
}
return;
}
void print_courses(student* s, course* c)
{
cout << "\n\nCourse Name\tCourse Number\n";
cout << "-----------\t-------------\n";
// print names of all courses
for (int k = 0; k < num_courses; k++)
cout << c[k].name << "\t\t" << c[k].id << endl;
}
void print_students(student* s, course* c)
{
cout << "\n\nStudent Name\tStudent Number\n";
cout << "------------\t--------------\n";
// print names of all students
for (int k = 0; k < num_students; k++)
cout << s[k].lname << ", " << s[k].fname << "\t" << s[k].id << endl;
}
void course_avg(student* s, course* c)
{
string cname;
int cnumber, sum = 0, enrollment_count = 0, student_grading;
float *pstudent1, *pstudent2, *pstudent3, *pstudent4, *student_enrollment, avg = 0, course_avg = 0;
cout << "\n*********************************************************\n";
cout << "This option allows you to print the average for a course.\n";
cout << "*********************************************************\n\n";
cout << "What is the course name? "; cin >> cname;
cout << "What is the course number? "; cin >> cnumber;
// search courses
for (int i = 0; i < MAXCLASSES; i++)
{
// if course is found
if (cname == c[i].name && cnumber == c[i].id)
{
// search through enrollments
for (int j = 0; j < ENROLLMENT; j++)
{
// get address that course enrollment points to
student_enrollment = c[i].enrolled_students[j];
// search students
for (int k = 0; k < STUDENTS; k++)
{
// get location of student and address of student grade books
student_grading = k;
pstudent1 = &s[k].grades1[0];
pstudent2 = &s[k].grades2[0];
pstudent3 = &s[k].grades3[0];
pstudent4 = &s[k].grades4[0];
// if course enrollment points to student's first grade book
if (student_enrollment == pstudent1)
{
enrollment_count++;
// add up grades
for (int m = 0; m < MAXGRADES; m++)
{
sum += s[student_grading].grades1[m];
}
// get average
avg += (float)sum / MAXGRADES;
sum = 0;
break;
}
// if course enrollment points to student's second grade book
else if (student_enrollment == pstudent2)
{
enrollment_count++;
// add up grades
for (int m = 0; m < MAXGRADES; m++)
{
sum += s[student_grading].grades2[m];
}
// get average
avg += (float)sum / MAXGRADES;
sum = 0;
break;
}
// if course enrollment points to student's third grade book
else if (student_enrollment == pstudent3)
{
enrollment_count++;
// add up grades
for (int m = 0; m < MAXGRADES; m++)
{
sum += s[student_grading].grades3[m];
}
// get average
avg += (float)sum / MAXGRADES;
sum = 0;
break;
}
// if course enrollment points to student's fourth grade book
else if (student_enrollment == pstudent4)
{
enrollment_count++;
// add up grades
for (int m = 0; m < MAXGRADES; m++)
{
sum += s[student_grading].grades4[m];
}
// get average
avg += (float)sum / MAXGRADES;
sum = 0;
break;
}
}
}
}
break;
}
// divide sumed averages by enrollment total
course_avg = (float)avg / enrollment_count;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "The course average is: " << course_avg << endl;
cout.unsetf(ios::fixed);
cout.unsetf(ios::showpoint);
cout.precision(100);
return;
}
void save_stream(ofstream& out_file, student* s, course* c)
{
char output_file[20];
int enrollment_count = 0, num = 0;
cout << "File name: "; cin >> output_file;
// open file to save to
out_file.open(output_file);
// if opening fails
if (out_file.fail())
{
cout << "Failed to open file.\n";
exit(EXIT_FAILURE);
}
// number of courses to save
out_file << num_courses << endl;
// write course names and numbers
for (int i = 0; i < num_courses; i++)
out_file << c[i].name << " " << c[i].id << endl;
// number of students to save
out_file << num_students << endl;
// write names of students
for (int i = 0; i < num_students; i++)
{
out_file << s[i].lname << " " << s[i].fname
<< " " << s[i].id << endl;
// search all courses
// really inefficient
for (int j = 0; j < num_courses; j++)
{
// search all enrollments of course
for (int k = 0; k < ENROLLMENT; k++)
{
// if student is enrolled in course
if (c[j].enrolled_students[k] == &s[i].grades1[0])
{
enrollment_count++;
// write name of course student is enrolled in
out_file << c[j].name << " " << c[j].id << " ";
// grades for student in enrolled course
for (int m = 0; m < MAXGRADES; m++)
out_file << s[i].grades1[m] << " ";
out_file << endl;
}
// if student is enrolled in course
else if (c[j].enrolled_students[k] == &s[i].grades2[0])
{
enrollment_count++;
// write name of course student is enrolled in
out_file << c[j].name << " " << c[j].id << " ";
// grades for student in enrolled course
for (int m = 0; m < MAXGRADES; m++)
out_file << s[i].grades2[m] << " ";
out_file << endl;
}
// if student is enrolled in course
else if (c[j].enrolled_students[k] == &s[i].grades3[0])
{
enrollment_count++;
// write name of course student is enrolled in
out_file << c[j].name << " " << c[j].id << " ";
// grades for student in enrolled course
for (int m = 0; m < MAXGRADES; m++)
out_file << s[i].grades3[m] << " ";
out_file << endl;
}
// if student is enrolled in course
else if (c[j].enrolled_students[k] == &s[i].grades4[0])
{
enrollment_count++;
// write name of course student is enrolled in
out_file << c[j].name << " " << c[j].id << " ";
// grades for student in enrolled course
for (int m = 0; m < MAXGRADES; m++)
out_file << s[i].grades4[m] << " ";
out_file << endl;
}
}
}
// write zeros to file if student not enrolled in other courses
num = 4 - enrollment_count;
for (int i = 0; i < num; i++)
{
for (int j = 0; j < 12; j++)
{
out_file << 0 << " ";
}
out_file << endl;
}
enrollment_count = 0;
}
return;
}
void load_stream(ifstream& in_file, student* s, course* c)
{
float *pstudent;
string cname, temp;
char input_file[20];
int cnumber, grades[10], num = 0, student_enrollment = 0, course_enrollment = 0;
cout << "File name: "; cin >> input_file;
// open file to load
in_file.open(input_file);
// if opening failed
if (in_file.fail())
{
cout << "Failed to open file.\n";
exit(EXIT_FAILURE);
}
// get number of courses that are to be added
getline(in_file, temp);
// convert number from string to int
num = stoi(temp);
// for every course to be added
for (int i = 0; i < num; i++)
{
// get name of course
getline(in_file, temp, ' ');
c[i].name = temp;
// get course number
getline(in_file, temp);
// convert number from string to int
c[i].id = stoi(temp);
num_courses++;
}
// get number of students to be enrolled
getline(in_file, temp);
// convert number from string to int
num = stoi(temp);
// read student blocks from in_file
for (int i = 0; i < num; i++)
{
// read student lname, fname and id
getline(in_file, temp, ' ');
s[i].lname = temp;
getline(in_file, temp, ' ');
s[i].fname = temp;
getline(in_file, temp);
s[i].id = stoi(temp);
num_students++;
// read each enrolled class
for (int j = 0; j < 4; j++)
{
// check how many courses student is enrolled in
student_enrollment = s[i].class_count;
switch (student_enrollment)
{
// if not enrolled
case 0:
// get address to first student grade book
pstudent = &s[i].grades1[0];
// increment enrollment count
s[i].class_count++;
break;
// if enrolled in one course
case 1:
// get address to second student grade book
pstudent = &s[i].grades2[0];
// increment enrollment count
s[i].class_count++;
break;
// if enrolled in two courses
case 2:
// get address to first student grade book
pstudent = &s[i].grades3[0];
// increment enrollment count
s[i].class_count++;
break;
// if enrolled in three courses
case 3:
// get address to fourth student grade book
pstudent = &s[i].grades4[0];
// increment enrollment count
s[i].class_count++;
break;
}
// read each class
getline(in_file, temp, ' ');
cname = temp;
getline(in_file, temp, ' ');
cnumber = stoi(temp);
for (int n = 0; n < (MAXGRADES - 1); n++)
{
getline(in_file, temp, ' ');
grades[n] = stoi(temp);
}
getline(in_file, temp);
grades[MAXGRADES - 1] = stoi(temp);
// search for course
for (int k = 0; k <= num_courses; k++)
{
// if course is found
if (cname == c[k].name && cnumber == c[k].id)
{
// get course enrollment counter
course_enrollment = c[k].roll;
// check course enrollment counter
switch (course_enrollment)
{
// if no one is enrolled in the class
case 0:
// point class roll to the student grade book address
c[k].enrolled_students[0] = pstudent;
// increment class counter
c[k].roll++;
break;
// if one person is enrolled in the class
case 1:
// point class roll to the student grade book address
c[k].enrolled_students[1] = pstudent;
// increment class counter
c[k].roll++;
break;
// if two people are enrolled in the class
case 2:
// point class roll to the student grade book address
c[k].enrolled_students[2] = pstudent;
// increment class counter
c[k].roll++;
break;
// if three people are enrolled in the class
case 3:
// point class roll to the student grade book address
c[k].enrolled_students[3] = pstudent;
// increment class counter
c[k].roll++;
break;
// if four people are enrolled in the course
case 4:
// point class roll to the student grade book address
c[k].enrolled_students[4] = pstudent;
// increment class counter
c[k].roll++;
break;
// if five people are enrolled in the course
case 5:
// point class roll to the student grade book address
c[k].enrolled_students[5] = pstudent;
// increment class counter
c[k].roll++;
break;
// if six people are enrolled in the course
case 6:
// point class roll to the student grade book address
c[k].enrolled_students[6] = pstudent;
// increment class counter
c[k].roll++;
break;
// if seven people are enrolled in the course
case 7:
// point class roll to the student grade book address
c[k].enrolled_students[7] = pstudent;
// increment class counter
c[k].roll++;
break;
// if eight people are enrolled in the course
case 8:
// point class roll to the student grade book address
c[k].enrolled_students[8] = pstudent;
// increment class counter
c[k].roll++;
break;
// if nine people are enrolled in the course
case 9:
// point class roll to the student grade book address
c[k].enrolled_students[9] = pstudent;
// increment class counter
c[k].roll++;
break;
// if ten people are enrolled in the course
case 10:
// point class roll to the student grade book address
c[k].enrolled_students[10] = pstudent;
// increment class counter
c[k].roll++;
break;
// if eleven people are enrolled in the course
case 11:
// point class roll to the student grade book address
c[k].enrolled_students[11] = pstudent;
// increment class counter
c[k].roll++;
break;
// if twelve people are enrolled in the class
case 12:
// point class roll to the student grade book address
c[k].enrolled_students[12] = pstudent;
// increment class counter
c[k].roll++;
break;
// if thirteen people are enrolled in the class
case 13:
// point class roll to the student grade book address
c[k].enrolled_students[13] = pstudent;
// increment class counter
c[k].roll++;
break;
// point class roll to the student grade book address
case 14:
// point class roll to the student grade book address
c[k].enrolled_students[14] = pstudent;
// increment class counter
c[k].roll++;
break;
// if fifteen people are enrolled in the class
case 15:
// point class roll to the student grade book address
c[k].enrolled_students[15] = pstudent;
// increment class counter
c[k].roll++;
break;
// if sixteen people are enrolled in the class
case 16:
// point class roll to the student grade book address
c[k].enrolled_students[16] = pstudent;
// increment class counter
c[k].roll++;
break;
// if seventeen people are enrolled in the class
case 17:
// point class roll to the student grade book address
c[k].enrolled_students[17] = pstudent;
// increment class counter
c[k].roll++;
break;
// if eighteen people are enrolled in the course
case 18:
// point class roll to the student grade book address
c[k].enrolled_students[18] = pstudent;
// increment class counter
c[k].roll++;
break;
// if nineteen people are enrolled in the course
case 19:
// point class roll to the student grade book address
c[k].enrolled_students[19] = pstudent;
// increment class counter
c[k].roll++;
break;
}
// if enrollment address matches student's first grade book
if (pstudent == &s[i].grades1[0])
{
for (int n = 0; n < (MAXGRADES - 1); n++)
s[i].grades1[n] = grades[n];
s[i].grades1[MAXGRADES - 1] = grades[MAXGRADES - 1];
}
// if enrollment address matches student's second grade book
else if (pstudent == &s[i].grades2[0])
{
for (int n = 0; n < (MAXGRADES - 1); n++)
s[i].grades2[n] = grades[n];
s[i].grades2[MAXGRADES - 1] = grades[MAXGRADES - 1];
}
// if enrollment address matches student's third grade book
else if (pstudent == &s[i].grades3[0])
{
for (int n = 0; n < (MAXGRADES - 1); n++)
s[i].grades3[n] = grades[n];
s[i].grades3[MAXGRADES - 1] = grades[MAXGRADES - 1];
}
// if enrollment address matches student's fourth grade book
else if (pstudent == &s[i].grades4[0])
{
for (int n = 0; n < (MAXGRADES - 1); n++)
s[i].grades4[n] = grades[n];
s[i].grades4[MAXGRADES - 1] = grades[MAXGRADES - 1];
}
}
}
}
}
return;
}
main.cpp:
//main.cpp
#include "stdafx.h"
#include "header.h"
using namespace std;
int main()
{
course course_catalog[25];
student student_body[100];
int user_input = 0;
ifstream in_file;
ofstream out_file;
while (user_input != 13)
{
cout << "\n\n****************************************\n";
cout << "\tGrade Book Options\n";
cout << "****************************************\n";
cout << "\n\t1. Add a course\n";
cout << "\t2. Add a student\n";
cout << "\t3. Add a student to a course\n";
cout << "\t4. Add grades for a student in a course\n";
cout << "\t5. Print a list of all grades for a student in a course\n";
cout << "\t6. Print a list of all students in a course\n";
cout << "\t7. Compute the average for a student in a course\n";
cout << "\t8. Print a list of all courses\n";
cout << "\t9. Print a list of all students\n";
cout << "\t10. Compute the average for a course\n";
cout << "\t11. Store Grade Book (to a disk file)\n";
cout << "\t12. Load Grade book (from a disk file)\n";
cout << "\t13. Exit\n\n\n";
cout << "What would you like to do? ";
cin >> user_input;
switch (user_input)
{
case 1: add_course(student_body, course_catalog);
break;
case 2: add_student(student_body, course_catalog);
break;
case 3: student_to_course(student_body, course_catalog);
break;
case 4: add_grades(student_body, course_catalog);
break;
case 5: print_grades(student_body, course_catalog);
break;
case 6: print_students_in_course(student_body, course_catalog);
break;
case 7: student_avg(student_body, course_catalog);
break;
case 8: print_courses(student_bod
For this assignment we are going to create the beginnings of a simple Grade Book. We...
Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and his/her course names with grades. ? Your system should allow the user to input, update, delete, list and search students’ grades. ? Each student has a name (assuming no students share the same name) and some course/grade pairs. If an existing name detected, user can choose to quit or to add new courses to that student. ? Each student has 1 to 5 courses,...
Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...
Java This application will be menu driven. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course...
The application should be in JAVA and allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow the user to edit student ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique ID. The user should be able to view/edit an existing course information. User is...
In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...
PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...
Please draw a class diagram for the following classes and relationships We have classes: Instructor, Student, Main Menu, create account, login, create the student's passwords, create a course, view my courses, create an assignment, view my grades, create a new password And they have the following relations: 1. Instructor and Student can create an account 2. Instructor and student can login 3. Instructor must create the students' password Instructor can create a course, assignment, Instructor can view courses and grades...
In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...
Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...
In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...