C++ This group assignment is designed to test your ability to use classes, frien
ID: 3595970 • Letter: C
Question
C++
This group assignment is designed to test your ability to use classes, friend function(s), assignment operators, and dynamic allocation. Please note, you will need to use all of the following to receive full credit. Failure to do so will result in point deductions.
You and your group are tasked to generate a list of students each with a random grade. From there, depending on the user’s input, you are to divide the students into groups and calculate the group’s average grades.
You are to ask the user how many students they would like to enter. You should test for 6 students at first, then try 10 students. Lastly try a total of 12 students.
You should ask the user how many people are in each group. Valid answers are 2, 3, and 4 people per group. You should include some error checking incase user inputs anything other than 2-4.
If you have not already noticed, having 6 or 10 students and if the user tries to divide them into groups of 4, would result in an error since they cannot be split evenly. Therefore you should make sure to use create error check to check for if such a case arises. Print out an error.
You should create a class called Student. In this class, you should have the following:
Private member variables: int studentID and intstudentGrade
Public member functions: constructor with 1 parameter to store studentID and to generate a random studentGrade. You can use rand() to generate a grade from 1-100.
A friend function print(Student temp) to print out the student’s ID and grade
int assignment operator + (const Student& next) where you add 2 student object’s grades together
Another int assignment operator +(const int& first, const Student& next). This will be explained in the next portion.
You should create the friend function outside of the class. (THIS MEANS THE LOGIC IS NOT IN STUDENT.CPP or in STUDENT.H). You should still initialize the friend function inside Student class so that you can access its member functions.
You should create 3 functions outside of the class to add up the respective objects.
A function called avgOf2 with 2 parameters (Student a, Student b) to add up both student’s grades
You will only need to use 1 operator+ function forthis
A function called avgOf3 with 3 parameters (Student a, Student b, Student c) to add up all three student grades.
You will need to use both operator+ functions for this
A function called avgOf4 with 4 parameters (Student a, Student b, Student c, Student d) to add up all four student grades.
You will need to use both operator+ functions forthis
You should create a main function to:
Ask the user for number of students
Generate a dynamic array of Students (size of either 6, 10, 12 depending oninput)
Ask the user for the group size
Loop each group to print out the averages
If group size is 2, use avgOf2 function, print out group membersand average
If group size is 3, use avgOf3 function, print out group membersand average
If group size is 4, use avgOf4 function, print out group membersand average
The assignment operator serves to add up object member variables. Here, we want to take each studentGrade and add them together. The reason we use 2 assignment operator+ is that they accept different parameters. The first one serves simply to add only 2 objects together. You should return an int that is the average of the 2 grades. You can look at operator notes for more details and examples. (Or from the book, google, etc.)
The second assignment operator+ takes 2 parameters, one int and one object. Ex: (const int& first, const Student& next). This will be used for avgOf3 and avgOf4 functions.
The friend function to print simply serves to test if you know how to use friend functions properly.
Adding Objects
In your avgOf2 function, you simply only need to add 2 objects together. If you have already assigned the ‘+’ operator to add grades together, this function simply returns (Student a + Student b) / 2.
Your avgOf3 function will first add the 2 objects together (Student a + Student b) then use the second assignment operator to take the total from that and add it to the third object. (Student c). Then simply return the result/3.
Your avgOf4 function is similar to the avgOf3 function except there’s one more addition step needed and you should make sure to return the result/4.
Student ID is simply be a counter 1-6, 1-10, or 1-12. Student Grade will be randomized from 1-100. When you split a group, you can just go down the line. Meaning, take for example 10 students. If group size is 2, then student ID (1,2) are a group and so on… (3,4) (5,6) (7,8)(9,10).
Since we are using ints not doubles, the averages will be truncated. This is ok. We will accept double type averages as well.
We are aware you don’t need 3 separate functions to add up objects. Adding up 4 objects is the same as adding 2 objects twice then adding those 2 together. You are free to use less functions if you feel inclined.
You can put the logic for random number generation in either the constructor or by creating a new function for the constructor to invoke.
Output
Pass Case:
Enter the number of students: 10
Enter the number of students in each group: 2
---
Student 1: Grade 70
Student 2: Grade 80 Group Average = 75
Student 3: Grade 34
Student 4: Grade 97 Group Average = 66
Student 5: Grade 100
Student 6: Grade 66 Group Average = 83
Student 7: Grade 48
Student 8: Grade 86 Group Average = 67
Student 9: Grade 88
Student 10: Grade 91 Group Average = 90
Fail Case:
Enter the number of students: 6
Enter the number of students in each group: 4
---
ERROR: CANNOT SPLIT STUDENTS EVENLY INTO GROUPS
Text Box: ASSIGNMENT BACKGROUNDExplanation / Answer
//main.cpp
================================================================================
//Student.cpp
===============================================================================
//Student.h
=============================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.