Question

In c++ create a class to maintain a GradeBook. The class should allow information on up...

In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the book does not have to be in alphabetical order), and to list all student records (name and associated grades) it contains.  To add a student to the end of the book, the user should not have to specify a position, (ie. your GradeBook should keep track of the last position and add to the end automatically). Your Student class should include at least the operations to allow entry of the last name and up to 5 grades, and to return the name and grades for that student.

You should write a main program that creates a grade book and presents a menu to the user that allows them to select either Add (A), or List (L), or Quit (Q). Add should allow the user to enter a student record (name and grades) and add it to the end of the Gradebook list. List should list all student records currently in the grade book. You should be able to add and list repeatedly, until you select Q to quit.

Use good coding style and principles for all code and input/output formatting. All data in a class must be private. Put each class declaration in its own header file and its implementation in a separate .cpp file.

Helpful hints on how to approach this lab

  1. In main():
    1. Prompt the user to enter a name for a gradebook.
    2. Create an object of the gradebook class, passing in the name of the gradebook as an argument to the constructor of the Gradebook class.
    3. Create a menu with “cout” statements.
    4. Create a switch statement that contains the cases that the user could enter.
    5. For the Add students case, prompt the user to enter a name for the student if the number of students already existing is less than 3.

1. Using the Gradebook object, call the function in the Gradebook class to add a student, passing in the name of the student that the user entered.

  1. For the List students case, call the function that prints student records, again by using the Gradebook object to call the function in the gradebook class.
  1. In the Gradebook class:
    1. Make sure you have a constructor that initializes the gradebook name by calling a Set function in the class. Remember that the name is passed in from main().
    2. For all of the data members you have in your class, be sure to have a Set and Get function for each.
    3. The Gradebook class contains the function to add a Student. In it, you will create a new student object (passing in the name of the student that came from main()), and add it to the vector of Student objects (which is a data member in the Gradebook class).
    4. As soon as you create a student object in the Gradebook class and add it to the vector, call the function in the Student Class that allows the user to enter up to 5 grades for that student.
    5. Include a function that will print each student object in the Gradebook class. That is, loop over all the student objects in the vector and for each object, call a function in the Student class that will print each student record. It’s like using Gradebook as a middleman… main() calls the Gradebook function to list the students. Gradebook contains the loop to iterate over each student object in its vector, then within the loop, each student object calls a function in the Student class that will print out the names and grades of a given student object.
  1. In the Student class:
    1. Make a constructor that initializes the student’s name to whatever was entered in main() and subsequently passed in to your Gradebook function that adds new students. Recall that this information will be passed in to the Student constructor from the Add Student function in Gradebook.
    2. Create a function that will allow the user to enter up to 5 grades for a student. This function will actually contain the cout and cin commands to prompt the user to enter each grade (Don’t worry about putting error checks in here because I won’t try to break it.)
    3. Naturally, this class will contain either an array or vector (your choice) of grades that the user will enter (no more than 5).
    4. This class will contain a function that displays the grades for a student. It will need to loop over all the grades in the array for the student and print them out. This function will be called from the function in the Gradebook class that prints out each student object.

Homework Answers

Answer #1

------Student Class - Student.h

#ifndef STUDENT_H_

#define STUDENT_H_

#include <iostream.h>

#include <cstring.h>

#define MAX_GRADES 5

using namespace std;

/**

* Student class

*/

class Student {

private:

   string studentLastName; //last name of string

   int grades[MAX_GRADES]; //grades of the student

   int numGrades; //number of grades given

public:

   Student();

   const int getGrade(int numGrade) const;

   void setGrade(int grade);

   const string& getStudentLastName() const;

   void setStudentLastName(const string& studentLastName);

   int getNumGrades() const;

};

#endif /* STUDENT_H_ */

-------Gradebook Class - Gradebook.h

#ifndef GRADEBOOK_H_

#define GRADEBOOK_H_

#include <iostream>

#include "Student.h"

#define MAX_STUDENTS 3

using namespace std;

/**

* GradeBook class

*/

class GradeBook {

private:

   Student students[MAX_STUDENTS]; //students in grade book

   int numStudents; //number of students in the grade book

public:

   GradeBook();

   void addStudent(Student student);

   void listStudents();

};

#endif /* GRADEBOOK_H_ */

--------Student.cpp

#include "Student.h"

/**

* Constructor

*/

Student::Student() {

   studentLastName="";

   numGrades=0;

}

/**

* returns grade of a specified number

*/

const int Student::getGrade(int numGrade) const {

   if(numGrade >= 0 && numGrade <= MAX_GRADES)

       return grades[numGrade];

   else

   {

       cerr<<"Can not return grade. Wrong input."<<endl;

       return -1;

   }

}

/**

* sets a given grade

*/

void Student::setGrade(int grade)

{

   if(grade > 0 && grade <=100)

   {

       if(numGrades == MAX_GRADES)

       {

           cerr<<"Cannot add the grade. Max. grades already alloted."<<endl;

           return;

       }

       grades[numGrades]=grade;

       numGrades++;

   }

}

/**

* returns student last name

*/

const string& Student::getStudentLastName() const {

   return studentLastName;

}

/**

* sets student last name

*/

void Student::setStudentLastName(const string& studentLastName) {

   this->studentLastName = studentLastName;

}

/**

* returns number of grades alloted to the student

*/

int Student::getNumGrades() const {

   return numGrades;

}

------Gradebook.cpp

#include "GradeBook.h"

/**

* constructor

*/

GradeBook::GradeBook() {

   numStudents=0;

}

void GradeBook::addStudent(Student student) {

   if(numStudents==MAX_STUDENTS)

   {

       cerr<<"Cannot add the student. Max. students already alloted."<<endl;

       return;

   }

   students[numStudents]=student;

   numStudents++;

}

void GradeBook::listStudents() {

   if(numStudents==0)

   {

       cerr<<"No student in grade book as of now."<<endl;

       return;

   }

   for(int i=0;i<numStudents;i++)

   {

       Student student=students[i];

       cout<<"Student record "<<(i+1)<<":"<<endl;

       cout<<"Last name:"<<student.getStudentLastName()<<endl;

       for(int j=0;j<student.getNumGrades();j++)

       {

           cout<<"Grade "<<(j+1)<<":"<<student.getGrade(j)<<endl;

       }

   }

}

-----gradebookdemo.cpp

#include <iostream.h>

#include <cstdlib.h>

#include <cstdio.h>

#include "GradeBook.h"

using namespace std;

/**

* main function - demo of GradeBook

*/

int main() {

   GradeBook gradebook; //create object  of grade book

   char choice; //takes users choice

   string name; //takes name of student given by user

   int grade, numGrades; //grade of student given by user

   Student* student; //  student to be added to grade book

   //create a loop to read 3 students data

   while(1)

   {

       fflush(stdin);

       //list of options

       cout<<"List of Options:"<<endl;

       cout<<"Add(A):"<<endl;

       cout<<"List(L):"<<endl;

       cout<<"Quit(Q):"<<endl;

       cout<<"Choice:";

       cin>>choice;

       //Process the requirement of user based on choice

       switch(choice)

       {

       case 'A':

           student = new Student;

           cout<<"Enter last name:";

           cin>>name;

           student->setStudentLastName(name);

           cout<<"How many grades (Max 10)?";

           cin>>numGrades;

           cout<<"Enter grades:";

           for(int i=0;i<numGrades;i++)

           {

               cout<<"Enter grade "<<(i+1)<<":";

               cin>>grade;

               student->setGrade(grade);

           }

           gradebook.addStudent(*student);

           break;

       case 'L':

           gradebook.listStudents();

           break;

       case 'Q':

           cout<<"Thank you! Quitting..."<<endl;

           exit(1);

       default:

           cerr<<"Wrong choice! Re-enter."<<endl;

           break;

       }

   }

   return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Create a stadium class. The class header file content (.h file) can go in this question,...
Create a stadium class. The class header file content (.h file) can go in this question, the class implementation (.cpp file) can go in the following question, and the main.cpp content can go in the third question. static data members: starting seat number next seat number data members: stadium name name of home team current opponent seats sold (vector of seat numbers) member functions: custom constructor - take input of stadium name default constructor get next seat number (static) change...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
For this assignment, you'll create a Player class that captures information about players on a sports...
For this assignment, you'll create a Player class that captures information about players on a sports team. We'll keep it generic for this assignment, but taking what you learn with this assignment, you could create a class tailored to your favorite sport. Then, imagine using such a class to track the stats during a game. Player Class Requirements Your class should bet set up as follows: Named Player Is public to allow access from other object and assemblies Has a...
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
Part 1 - LIST Create an unsorted LIST class ( You should already have this code...
Part 1 - LIST Create an unsorted LIST class ( You should already have this code from a prior assignment ). Each list should be able to store 100 names. Part 2 - Create a Class ArrayListClass It will contain an array of 27 "list" classes. Next, create a Class in which is composed a array of 27 list classes. Ignore index 0... Indexes 1...26 correspond to the first letter of a Last name. Again - ignore index 0. index...
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions:...
Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions: 1. Fully parametrized Constructor (to initialize class variables) 2. Getter (getBalance()) and Setter (setBalance()) for the float balance, must be greater than zero. In Account.java Methods: checkBalance( ) to print CURRENT BALANCE. deposit(int added_amount) should add add_amount to balance withdraw(int withdraw_amount) should deduct withdraw_amount balance display( ) will print all the information (account number, name, balance). Class 2: AccountTest.java Create an object account1 and...