Question

For C++ program Your program should first prompt the user for the number of students they...

For C++ program

Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have their name, list of test scores displayed.

Your program must have at least the following functions:

int inputData(string*&, double**&);

     The inputData function accepts a string pointer and a pointer to a double pointer, both passed by reference. Inside the function, the user will be prompted to enter how many students they will input. For each student, the user will input the student’s name and a list of the student’s test scores. The function will return the number of students that have been entered.

After the function call, the string pointer should point to an array of every student name and the pointer to a double pointer should point to an array where each array entry contains an array of that student’s test scores. Remember that you do not know beforehand how many students will be entered or the number of test scores each student will have.

void displayData(string*, double**, int);

The displayData function accepts a pointer to the array of student names, a pointer to the array of student test scores, and the number of students. The function should output the following to the console:

The number of students,

and for each student

  • the student’s name
  • a list of the student’s test scores

void cleanHeap(string*, double**, int);

The cleanHeap function accepts a pointer to the array of student names, a pointer to the array of student test scores, and the number of students. Inside the function, anything that was dynamically-allocated should be cleaned up appropriately.

Additionally,

  • You must validate the user’s input
    • The number of students and the number of test scores must be a positive value
    • Each test score must be between 0 and 100, inclusive

Sample Run:

How many students do you have in the system? 3

Enter the student's name: John Doe

Enter how many tests John Doe took: 4

Enter grade # 1: 95.5

Enter grade # 2: 84.3

Enter grade # 3: 80

Enter grade # 4: 88.8

Enter the student's name: Anna Mull

Enter how many tests Anna Mull took: 3

Enter grade # 1: 60

Enter grade # 2: 55.9

Enter grade # 3: 77.4

Enter the student's name: Paige Turner

Enter how many tests Paige Turner took: -1

Please enter a positive number of tests taken

Enter how many tests Paige Turner took: 2

Enter grade # 1: 75.6

Enter grade # 2: -10.3

Please enter a grade between 0 and 100

Enter grade # 2: 50.5

You have 3 students in the system.

Name of student #1: John Doe

Grades for student #1: 95.5 84.3 80 88.8

Name of student #2: Anna Mull

Grades for student #2: 60 55.9 77.4

Name of student #3: Paige Turner

Grades for student #3: 75.6 50.5

// end of sample run.

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

C++ Program:

#include <iostream>
#include <string>

using namespace std;

//Function prototypes
int inputData(string*&, double**&);
void displayData(string*, double**, int);
void cleanHeap(string*, double**, int);

//Array that holds number of scores for each student
int *scoreLength;

//Main function
int main()
{
string *names;
double** scores;
int n;

//Calling functions
n = inputData(names, scores);
displayData(names, scores, n);
cleanHeap(names, scores, n);

cout << endl;
return 0;
}

//Function that reads the data from user
int inputData(string* &names, double** &scores)
{
int i, j, nStudents, nScores;

//Prompting for number of students
cout << "How many students do you have in the system? ";
cin >> nStudents;

//Allocating memory
names = new string[nStudents];
scores = new double*[nStudents];
scoreLength = new int[nStudents];

//Iterating over each student
for(i=1; i<=nStudents; i++)
{
cout << "Enter the student's name: ";
cin.ignore();
getline(cin, names[i-1]);

while(1)
{
//Reading number of scores
cout << "Enter how many tests " << names[i-1] << " took: ";
cin >> nScores;

if(nScores < 0)
{
cout << "Please enter a positive number of tests taken" << endl;
}
else
{
break;
}
}

//Storing score length
scoreLength[i-1] = nScores;

//Allocating memory
scores[i-1] = new double[nScores];

//Iterating over scores
for(j=1; j<=nScores; j++)
{
while(1)
{
cout << "Enter grade # " << j << ":";
cin >> scores[i-1][j-1];

if(scores[i-1][j-1] < 0 || scores[i-1][j-1] > 100)
{
cout << "Please enter a grade between 0 and 100" << endl;
}
else
{
break;
}
}
}
}
return nStudents;
}

//Displaying student info
void displayData(string* names, double** scores, int nStudents)
{
int i, j;

cout << endl << "You have " << nStudents << " students in the system." << endl;

//Iterating over students
for(i=0; i<nStudents; i++)
{
cout << "Name of student #" << (i+1) << ": " << names[i] << endl << "Grades for student #" << (i+1) << ": ";

for(j=0; j<scoreLength[i]; j++)
{
cout << " " << scores[i][j];
}
cout << endl;
}
}

//Deleting memory
void cleanHeap(string* names, double** scores, int nStudents)
{
int i;

delete[] names;

//Iterating over students
for(i=0; i<nStudents; i++)
{
delete[] scores[i];
}

delete[] scores;
}

_____________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
For C++ program Your program should first prompt the user for the number of students they...
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
  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • Create a C# program that will first prompt the instructors to enter the number of students...

    Create a C# program that will first prompt the instructors to enter the number of students they currently have in their classes. Use this value for the size of the row dimension of your multidimensional array. Next, prompt the instructors to type in the number of scores they would like to enter. This variable will be used to designate the column size dimension of your multidimensional array. Then, use a loop to prompt the user to enter the number of...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write a c/c++ program to read a list of students from a file and create a...

    Write a c/c++ program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • C++ Data Structure Write a program to read a list of students from a file and...

    C++ Data Structure Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.

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