Question: IN C++ PROGRAMMING: Define a struct that holds student information and has the member items of name (a string), and a pointer to dynamically allocated
IN C++ PROGRAMMING:
Define a struct that holds student information and has the member items of
name (a string), and a pointer to dynamically allocated grades (an array of
chars) as well. Assume that there can be any number of grades. Next, write a
function called gradeIt that will accept the address of a c-string of grades and
a string with the name. Each call to your function creates an instance of the
struct on the heap and populates it with the grades and names. Then the
function calls another function, printIt, passing the pointer to the struct. Print
it should print the name and grades for each student by using the pointer to
the struct, and then return back to gradeIt. GradeIt should clean up before
returning back to taskB. Global constant for array size SIZE should be used as
the size when allocating the letter grades array of chars.
This code is used:
void taskB() { // allocate first student data and fill in student data char student1Grades[] = {'A', 'B', 'A', 'C', 'B', 'C', 'A', 'A', 'A', 'B'}; std::string studentName = "John"; gradeIt(student1Grades, studentName);
// allocate second student data and fill in student data char student2Grades[] = {'B', 'B', 'A', 'A', 'C', 'A', 'A', 'B', 'A', 'B'}; studentName = "Susan"; gradeIt(student2Grades, studentName);
// allocate third student data and fill in student data char student3Grades[] = {'B', 'C', 'B', 'A', 'A', 'A', 'A', 'B', 'B', 'B'}; studentName = "Alice"; gradeIt(student3Grades, studentName);
cout << "end of task B" << endl; cin.get(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
