Question

In: Computer Science

Write a program that uses a structure to store the following data: (Remember to use proper...

Write a program that uses a structure to store the following data:

(Remember to use proper formatting and code documentation)

Member Name Description
name student name
idnum Student ID number
Scores [NUM_TESTS] an array of test scores
Average Average test score
Grade Course grade

Declare a global const directly above the struct declaration

const int NUM_TESTS = 4; //a global constant

The program should ask the user how many students there are and should then dynamically allocate an array of structures.

The Student struct includes a fixed size scores array to store a list of four test scores for a group of students .

After the array of struct has been dynamically allocated, the program should ask for the name, ID number and four test scores for each student. The average test score should be calculated and stored in the average member of each structure.

The course grade should be computed on the basis of the following grading scale:

Average Test Grade Course Grade
91-100 A
81-90 B
71-80 C
61-70 D
60 or below F

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.

Simple Screen Output

How many students? 3

Student name: Sandy Shell
ID Number: 12345
        Test # 1: 100
        Test # 2: 56
        Test # 3: 78
        Test # 4: 66
Student name: Timothy Moriarty
ID Number: 23456
        Test # 1: 90
        Test # 2: 78
        Test # 3: 45
        Test # 4: 56
Student name: Joice Smith
ID Number: 54321
        Test # 1: 100
        Test # 2: 98
        Test # 3: 67
        Test # 4: 75

===========================
Course Grade Report
===========================
Student name: Sandy Shell
ID number: 12345
Average test score: 75.0
Grade: C

Student name: Timothy Moriarty
ID number: 23456
Average test score: 67.2
Grade: D

Student name: Joice Smith
ID number: 54321
Average test score: 85.0
Grade: B


Process returned 0 (0x0)   execution time : 94.219 s
Press any key to continue.

___________________________________________________________________________________________

Please make sure to declare the global constant and your struct above any function prototypes and include appropriate function documentation as needed.

Here is a sample of function prototypes that you may consider implementing...

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

You may use pointers or constant reference parameters when passing the structure to the functions mentioned above.

*EXTRA CREDIT COMPONENT FOR ASSIGNMENT#7 (5 points) - Select only one and insert as a multiline comment in your source code submitted.

1. How would you modify the program that you wrote for Programming Challenge 7a (monthly budget) so it defines an enumerated data type with enumerators for the months (JANUARY, FEBRUARY, so on). Provide a code snippet on how the program may use the enumerated type to step through each months expense and budget comparison for a full year.

or

2. How would you modify the program that you wrote for Programming Challenge 7b (course grades) so it defines struct member scores as a pointer to an array of test scores. What additional program statements will be needed so that each structure's score member should point to a dynamically allocated array that will hold the test scores.

Solutions

Expert Solution

/***************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;
const int NUM_TESTS = 4;

// create Student structure
struct Student
{
// Declaring variables
string name;
int idnum;
int Scores[NUM_TESTS];
double Average;
char Grade;
};

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

int main()
{
// Declaring variables
int noOfStudents;

// Getting the input entered by the user
cout << "How many students ? ";
cin >> noOfStudents;
cout << endl;

// calling the functions
Student* array = initArrays(noOfStudents);
getInfo(array, noOfStudents);
showInfo(array, noOfStudents);
return 0;
}


// Thuis function will create struct array dynamically
Student* initArrays(int n)
{
// Creating array dynamically
Student* studs = new Student[n];
return studs;
}

/*
* This function will read the inputs entered by the user
* and populate those values into array
*/
void getInfo(Student s[], int n)
{

for (int i = 0; i < n; i++)
{
cin.ignore();
cout << "Student name :";
getline(cin, s[i].name);
cout << "ID Number : ";
cin >> s[i].idnum;
for (int j = 0; j < NUM_TESTS; j++)
{
cout << "\tTest # " << (j + 1) << ": ";
cin >> s[i].Scores[j];
}
}
}

/*
* This function will display the report
*/
void showInfo(Student s[], int n)
{
// setting the precision to two decimal places
std::cout << std::setprecision(1) << std::fixed;

double average = 0.0, sum = 0.0;
char gradeLetter;
cout << "===========================================" << endl;
cout << "Course Grade Report" << endl;
cout << "===========================================" << endl;
for (int i = 0; i < n; i++)
{
sum = 0.0;
cout << "Student name :" << s[i].name << endl;
cout << "ID number :" << s[i].idnum << endl;
for (int j = 0; j < NUM_TESTS; j++)
{
sum += s[i].Scores[j];
}
average = (sum / NUM_TESTS);
if (average >= 90 && average <= 100)
gradeLetter = 'A';
else if (average >= 80 && average < 90)
gradeLetter = 'B';
else if (average >= 70 && average < 80)
gradeLetter = 'C';
else if (average >= 60 && average < 70)
gradeLetter = 'D';
else if (average < 60)
gradeLetter = 'F';
cout << "Average test score: " << average << endl;

cout << "Grade " << gradeLetter << endl;
cout << endl;
}
}

/***************************************************/

/***************************************************/

Output:

/***************************************************/


Related Solutions

Write a program that uses a structure to store the following weather data for a particular...
Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature. The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average...
Write a program that uses a structure to store the following data about a customer account:...
Write a program that uses a structure to store the following data about a customer account: Name Address City, State and Zip Telephone number Account balance Date of last payment The program should use an array of at least 5 structures. It should let the user enter data into the array, change the contents of any element and display all the data stored in the array. The program should have a menu-driven interface and use functions as appropriate. Input validation:...
11.7: Customer Accounts Write a program that uses a structure to store the following data about...
11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Prompts And...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a program using multiple functions. Make use of an array to store data Make use...
Write a program using multiple functions. Make use of an array to store data Make use of searching techniques Read data from a file Write data to a file Instructions: In this lab, you will be examining a set of stock collected over a twenty four day period. Be sure to make use of an array to store these stocks. You will be required to read in the data points from a file. Write a function to read in the...
Write a program for a beauty store that uses an InputBox to ask the guest for...
Write a program for a beauty store that uses an InputBox to ask the guest for a membership code. Embed this in a Do loop so that the user has to keep trying until the result is a valid membership code that starts with “Beauty” (case insensitive) and is followed by 4 digits with the final digit equal to either 6 or 8. Then use a message box to display the input promotion code and inform the user that the...
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Write a program that uses the defined structure and all the above functions. Suppose that the...
Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT