Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 11, Programming Challenge 12: Course Grade Write a program that uses a s

ID: 3823857 • Letter: C

Question

Chapter 11, Programming Challenge 12: Course Grade

Write a program that uses a structure to store structure data as describe in

Program template:

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

// Declaration of Student structure
struct Student
{
// TODO: structure for
// 1) Student name,
// 2) Student ID number,
// 3) Pointer to array of test scores
// 4) Average test score
// 5) Course grade
};

// Function prototypes
Student *initArrays(int, int);
void getInfo(Student[], int, int);
void showInfo(Student[], int, int);

int main()
{
int numStudents; // Number of students
int numTests; // Number of tests
Student *list = nullptr; // Pointer to Student array

// Get the number of students.
cout << "How many students? ";
cin >> numStudents;

// Get the number of tests per student.
cout << "How many tests per student? ";
cin >> numTests;

// TODO: Create an array of Students
list = initArrays(numStudents, numTests);

// TODO: Populate the array with data.
getInfo(list, numStudents, numTests);

// TODO: Display the data.
showInfo(list, numStudents, numTests);

return 0;
}

//**************************************************
// Function initArrays *
// This function dynamically allocates an array *
// of Student structures and for each element in *
// the array, allocates an array of ints to hold *
// tests scors. The parameter s is the number of *
// element to allocate for the array of structures *
// and the parameter t is the number of elements *
// allocate for each array of ints. *
//**************************************************
Student *initArrays(int s, int t)
{
Student *ptr = nullptr;

// Allocate the array of Student structures.
ptr = new Student[s];

// TODO: Allocate an array of ints (to hold test scores)
// for each element of the array of Student structures.

// Return a pointer to the array of structures.
return ptr;
}

//*****************************************************
// Function getInfo *
// This function populates the Student array s with *
// data entered by the user. The paramater ns is the *
// number of students and nt is the number of tests. *
//*****************************************************

void getInfo(Student s[], int ns, int nt)
{
int total;

//TODO: Get the data for each student.
}

//*****************************************************
// Function showInfo *
// This function displays all of the data in the *
// array s. The paramater ns is the number of *
// students and nt is the number of tests. *
//*****************************************************
void showInfo(Student s[], int ns, int nt)
{
// TODO: Displays all of the data in the array s
}

12. Course Grade Write a program that uses a structure to store the following data: Description Member Name Student name Name Student ID number Idnum Pointer to an array of test scores Tests Average test score Average Course grade Grade The program should keep a list of test scores for a group of students. It should ask the user how many test scores there are to be and how many students there are. It should then dynamically allocate an array of structures. Each structure's Tests member should point to a dynamically allocated array that will hold the test scores. After the arrays have been dynamically allocated, the program should ask for the ID number and all the test scores for each student. The average test score should be cal- culated and stored in the average member of each structure. The course grade should be computed on the basis of the following grading scale: Course Grade Average Test Grade 91-100 81-90 71-80 61-70 60 or below The course grade should then be stored in the Grade member of each structure. Once all this data is calculated, a table should be displayed on the screen listing each student's name, ID number, average test score, and course grade. Input Validation: Be sure all the data for each student is entered. Do not accept negative numbers for any test score.

Explanation / Answer

Here is the code update for you:

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
// Declaration of Student structure
struct Student
{
   // TODO: structure for
   // 1) Student name,
   string name;
   // 2) Student ID number,
   int ID;
   // 3) Pointer to array of test scores
   int* testScores;
   // 4) Average test score
   double avgTest;
   // 5) Course grade
   char grade;
};
// Function prototypes
Student *initArrays(int, int);
void getInfo(Student[], int, int);
void showInfo(Student[], int, int);
int main()
{
int numStudents; // Number of students
int numTests; // Number of tests
Student *list = nullptr; // Pointer to Student array
// Get the number of students.
cout << "How many students? ";
cin >> numStudents;
// Get the number of tests per student.
cout << "How many tests per student? ";
cin >> numTests;
// TODO: Create an array of Students
list = initArrays(numStudents, numTests);
// TODO: Populate the array with data.
getInfo(list, numStudents, numTests);
// TODO: Display the data.
showInfo(list, numStudents, numTests);
return 0;
}
//**************************************************
// Function initArrays *
// This function dynamically allocates an array *
// of Student structures and for each element in *
// the array, allocates an array of ints to hold *
// tests scors. The parameter s is the number of *
// element to allocate for the array of structures *
// and the parameter t is the number of elements *
// allocate for each array of ints. *
//**************************************************
Student *initArrays(int s, int t)
{
Student *ptr = nullptr;
// Allocate the array of Student structures.
ptr = new Student[s];
// TODO: Allocate an array of ints (to hold test scores)
// for each element of the array of Student structures.
for(int i = 0; i < s; i++)
   ptr[i].testScores = new int[t];
// Return a pointer to the array of structures.
return ptr;
}
//*****************************************************
// Function getInfo *
// This function populates the Student array s with *
// data entered by the user. The paramater ns is the *
// number of students and nt is the number of tests. *
//*****************************************************
void getInfo(Student s[], int ns, int nt)
{
int total;
//TODO: Get the data for each student.
for(int i = 0; i < ns; i++)
{
    cout << "Enter the name of student # " << i+1 << ": ";
    cin >> s[i].name;
    cout << "Enter the ID of student # " << i+1 << ": ";
    cin >> s[i].ID;
    cout << "Enter " << nt << " test scores: ";
    for(int j = 0; j < nt; j++)
    {
       cin >> s[i].testScores[j];
       while(s[i].testScores[j] < 0 || s[i].testScores[j] > 100)
       {
          cout << "Test scores should be in range [0 - 100]" << endl;
          j--;
          s[i].testScores[j] = 0;
       }
       total += s[i].testScores[j];
    }
    s[i].avgTest = (double)total / nt;   
    if(s[i].avgTest > 90)
        s[i].grade = 'A';
    else if(s[i].avgTest > 80)  
        s[i].grade = 'B';
    else if(s[i].avgTest > 70)  
        s[i].grade = 'C';
    else if(s[i].avgTest > 60)  
        s[i].grade = 'D';
    else
        s[i].grade = 'F';  
}
}
//*****************************************************
// Function showInfo *
// This function displays all of the data in the *
// array s. The paramater ns is the number of *
// students and nt is the number of tests. *
//*****************************************************
void showInfo(Student s[], int ns, int nt)
{
// TODO: Displays all of the data in the array s
for(int i = 0; i < ns; i++)
{
    cout << "Name: " << s[i].name << endl;
    cout << "ID: " << s[i].ID << endl;
    cout << "Test scores: ";
    for(int j = 0; j < nt; j++)
        cout << s[i].testScores[j] << " ";
    cout << endl;
    cout << "Average: " << s[i].avgTest << endl;
    cout << "Grade: " << s[i].grade << endl;  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote