Question

Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students...

Help with C++ please

Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students in a class.

The class has the following member variables:
int numStudents // holds the number of students in the class
double* grades // to point to a dynamically allocated array of grades

The class has the following public functions:
+default constructors //set numStudents = 0; and grades = nullptr;
+parameterized constructors //accepts numStudents and creates an array with size = numStudents;
+AcceptGrades // accept grades from end user using cin and stores them in grades array.
+CalculateAverage //calculate and returns the average of the class.
+Destructor to free the dynamically allocated array.
+Any setters/getters needed. Note that a setter for the numStudents should also initialize grades array.

Main:
Create an object of the ClassQuiz class.
Call AcceptGrades to accept grades from user.
Call CalculateAverage to calculate the average of the class.
Print the class average.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, here is the complete code in C++. I have used a do while loop to keep on asking the user if he wants t oadd a new grade or not and finally it will display the average grades.

thanks a lot, let me know for any help with any other questions, and please do give a thumbs up : )

====================================================================

#include <iostream>

using namespace std;

class ClassQuiz{

                private:

                                int numStudent;

                                double* grades;

                                int count;

                public:

                                ClassQuiz();

                                ClassQuiz(int);

                                void AcceptGrades();

                                double CalculateAverage();

                                ~ClassQuiz();

                                void setNumberOfStudent(int);

};

ClassQuiz::ClassQuiz(): numStudent(0), grades(NULL){count=0;}

ClassQuiz::ClassQuiz(int num) :numStudent(num), grades(new double[num]), count(0){}

void ClassQuiz::AcceptGrades(){

                if(count<numStudent){

                                cout<<"Enter grade: "; cin >> *(grades+count++);

                }else{

                                cout<<"Max grade reached, no more space available\n";

                }

}

double ClassQuiz::CalculateAverage(){

                double total =0;

                for(int i=0; i<count;i++) total+= *(grades+i);

                if(count!=0) return total/count;

                else return 0.0;

}

ClassQuiz::~ClassQuiz(){

                delete[] grades;

}

void ClassQuiz::setNumberOfStudent(int num){

                delete[] grades;

                numStudent = num;

                grades = new double[numStudent];

}

int main(){

               

               

                int num;

                cout<<"Enter number of students: " ; cin >> num;

               

                ClassQuiz quiz(num);

                cout<<"Class Average: "<<quiz.CalculateAverage() << endl;

                char repeat ;

                do{

                                quiz.AcceptGrades();

                                cout<<"Do you want to enter another grade (y/n): " ; cin >> repeat; cin.ignore(256,'\n');

                               

                }while(repeat=='y');

               

                cout<<"Class Average: "<<quiz.CalculateAverage() << endl;

               

}

====================================================================

Add a comment
Know the answer?
Add Answer to:
Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and...

    C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and parameterized constructors Write getters and setters for each variable. Declare 2 instances of the person class P1 and P2, one for both default and parm constructors Declare ptrPerson1 and ptrPerson2. Assign ptrPerson1 address of P1 Assign ptrPerson2 address of P2 Call all the getters and setters using the ARROW notation to test the class. Example:    ptrP1à getFirstName()

  • Create the program in C++ please. The new operator as outlined in 10.9 . Create a...

    Create the program in C++ please. The new operator as outlined in 10.9 . Create a Test class that includes the following Data members • First Name, last name, test1, test2, test3 o Methods • Accessor methods for each of the data members' • Mutator methods for each of the data members . A Default Constructor . A constructor that will accept arguments for each of the 5 data members • A method that will calculate the average of the...

  • In this assignment, you are asked to: 1. create a Matrix class that stores and operate...

    In this assignment, you are asked to: 1. create a Matrix class that stores and operate on a dynamic two-dimensional array. The class has the following structure: Private member variables: - int ** mat; - int rows; - int cols; Public member functions: +Default constructor: sets both rows and cols to 3 and creates 3x3 matrix dynamically +Parameterized constructor: sets the rows and cols to the values passed to the constructor and create a matrix with the given dimensions. +Destructor:...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Language: C++ Write a program that will allow the instructor to enter the student's names, student...

    Language: C++ Write a program that will allow the instructor to enter the student's names, student ID, and their scores on the various exams and projects. A class has a number of students during a semester. Those students take 4 quizzes, one midterm, and one final project. All quizzes weights add up to 40% of the overall grade. The midterm exam is 25% while the final project 35%. The program will issue a report. The report will show individual grades...

  • help 6. (15 points) Define class GradeStat to describe the grades of all people in a...

    help 6. (15 points) Define class GradeStat to describe the grades of all people in a group. (1) Declare data member grades as an array of integers (we can declare it as a double type, but use int type can be simpler). (2) Write a constructor taking an array of int as input parameter. Use it to initialize data member. Note that each element in the array should be a non- negative int not larger than 100, that is, an...

  • Need helps on C++ attach. Thanks Pointers with classes a) A user-defined class named Timer has...

    Need helps on C++ attach. Thanks Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour and minute data members. Write a single C++ statement to create an object of the Timer class using dynamic memory allocation and assign it to a pointer variable named timePt r. It should call the constructor with two parameters. Use values of 10 and 20 for hour and minute respectively. b) Write the definition...

  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT