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

C++ programming Course Grade Project Write a program that uses a structure to st

ID: 3810730 • Letter: C

Question

C++ programming

Course Grade Project

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

Data file name: CIT237StudentGrades.txt

*If a data file exists, the program should read the existing data and store in the structures.

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 in addition to any that have been read (if any). It should then dynamically allocate an array of structures. Each structure’s testArrayPtrmember 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 names and ID numbers for all the students. It should loop through the students and ask for the 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:


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.

*At the end of the program, the data should be stored in a file.

Your program should have:

comments

header file

functions

input validation

Input Validation: Be sure all the data for each student is entered. Do not accept negative numbers for any test score. Make sure the first letter of the student first and last names are capitalized.

Member Name Description Name Student name (a structure) idNum Student ID number testArrayPtr Pointer to an array of test scores average Average test score grade Course grade

Explanation / Answer


// C++ code
#include <iostream>
#include <string>
#include <iomanip>
#include <stdio.h>
using namespace std;

//structure to hold data for each student
struct StudentData
{
string name;
int idNum;
double *testArrayPtr; //pointer to an array of test scores
double average; //calculated average test score
char grade; //calculated course letter grade (A-F)
};


//function prototypes
string getName();
int getID();
double getScore(int count);
char calcGradeLetter(double *average);
void displayData (StudentData allStudents[], int sCount);

int main()
{
/*
   cout << "Reading from the file" << endl;
ifstream a_file ( "CIT237StudentGrades.txt" );

if ( !a_file.is_open() ) {
// The file could not be opened
}
else {
// Safely use the file stream
}

a_file.close(); // closing the file
*/
cout << " Welcome to the Test Score Storer. This program will gather test ";
cout << "scores for a given student name/id#. We'll start with some questions. ";

int numTests;
cout << "How many test scores per student? : ";
cin >> numTests;

int numStudents;
cout << "How many students? : ";
cin >> numStudents;

cout << "Creating Database...";
//create array to hold all studentData structs
StudentData *allStudents;
allStudents = new StudentData[numStudents];
cout << "...";
//create a tests member array for each student struct
double *testArrayPtr;
for (int i=0; i < numStudents; i++)
{
allStudents[i].testArrayPtr = new double[numTests];
}
cout <<"...Done! ";


//TRYING
for (int i=0; i < numStudents; i++)
{
cout << "Student " << i+1 << " of " << numStudents << endl;
cout << "================================= ";
allStudents[i].name = getName();
allStudents[i].idNum = getID();
double testTotal = 0.0;
for (int j=0; j < numTests; j++)
{
allStudents[i].testArrayPtr[j] = getScore(j);
testTotal += allStudents[i].testArrayPtr[j];
allStudents[i].average = testTotal/numTests;
}
//calculate letter grade
allStudents[i].grade = calcGradeLetter(&allStudents[i].average);
cout << "Student, " << allStudents[i].name << ", completed. ";
}

//Display all collected student data in chart form
displayData(allStudents, numStudents);


delete [] allStudents;
return (0);
}


//===========FUNCTIONS===========FUNCTIONS===========FUNCTIONS
string getName()
{
string name;
cin.ignore();
cout << "Student Name : ";
getline(cin,name);
return name;
}

int getID()
{
int IDnum;
cout << "Student ID : ";
cin >> IDnum;
return IDnum;
}

double getScore(int count)
{
double score;
score = -500;
while (score <0)
{ cout << "Test Score #" << count+1 <<" : ";
cin >> score;
if (score < 0)
{
cout << "Scores cannot be less than 0, try again. ";
}
}
return score;
}


char calcGradeLetter(double *average)
{
if (*average >= 90) return 'A';
else if (*average >= 80) return 'B';
else if (*average >= 70) return 'C';
else if (*average < 70) return 'F';
else return ('X');
}


FILE *f = fopen("file.txt", "w");

void displayData(StudentData allStudents[], int sCount)
{
cout << "Student Data Chart: ";
cout << "================================================= ";
cout << "NAME ID# TEST AVE. GRADE ";
for (int i = 0; i < sCount; i++)
{

cout << left << setw(18) << allStudents[i].name << " "
<< left << setw(12) << allStudents[i].idNum << " "
<< left << setw(11) << setprecision(4) << allStudents[i].average << " "
<< allStudents[i].grade << endl;

fprintf(f, "name: %s ",allStudents[i].name.c_str());
fprintf(f, "idNum : %d ", allStudents[i].idNum);
fprintf(f, "average : %f ", allStudents[i].average );
fprintf(f, "grade : %c ",allStudents[i].grade );
fprintf(f," " );
}
cout << " Table complete. ";


fclose(f);


}

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