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

Need help with c++ code. Can someone update the code below for input validation

ID: 3568790 • Letter: N

Question

Need help with c++ code.

Can someone update the code below for input validation for cout << "Enter student name: "; If the user presses enter without typing a name. It should say "Invalid Please try again"

Thanks!

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

struct student_data
{
string Student_name; // Student name
int id; // Student ID
int *tests;//     Pointer to an array of test scores
double average;//     Average test score
char grade;//     Course Grade
};
//The program should keep a list of test scores for a goup of students.
int main()
{
int no_of_students,test_scores;
//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.
cout <<"Enter number of students :";
cin >> no_of_students;
cout << endl;
cout <<"Enter number of test scores :";
cin >> test_scores;
cout << endl;
student_data *pointer_to_array = new student_data[no_of_students];
for(int i=0; i<no_of_students; i++)
{
pointer_to_array[i].tests = new int[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.
for(int i=0; i<no_of_students; i++)
{
cout <<"Enter Student Name. :";
cin >> pointer_to_array[i].Student_name;
cout <<endl;
cout <<"Enter Student ID. :";
cin >> pointer_to_array[i].id;
cout <<endl;
for(int j=0; j<test_scores; j++)
{
cout <<"Enter Student " << (i+1) << " Test Score " << (j+1) << " : ";
//Be sure all the data for each student are entered. Do no accept negative numbers for any test score.
cin >> pointer_to_array[i].tests[j];
cout <<endl;
while(pointer_to_array[i].tests[j]<0 || pointer_to_array[i].tests[j]>100)
{
cout <<"Invalid value entered. Re-Enter Score :";
cin >> pointer_to_array[i].tests[j];
cout <<endl;
}
}
}
// 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
for(int i=0; i<no_of_students; i++)
{
double sum = 0;
for(int j=0; j<test_scores; j++)
sum = sum + pointer_to_array[i].tests[j];
pointer_to_array[i].average = sum/test_scores;
//The course grade should then be stored in the "grade" member of each structure. Once all these data are calculated,
if(pointer_to_array[i].average >=91 && pointer_to_array[i].average<=100)
pointer_to_array[i].grade = 'A';
else if(pointer_to_array[i].average >=81 && pointer_to_array[i].average<=90)
pointer_to_array[i].grade = 'B';
else if(pointer_to_array[i].average >=71 && pointer_to_array[i].average<=80)
pointer_to_array[i].grade = 'C';
else if(pointer_to_array[i].average >=61 && pointer_to_array[i].average<=70)
pointer_to_array[i].grade = 'D';
else if(pointer_to_array[i].average <60)
pointer_to_array[i].grade = 'F';
}
//a table should be displayed on the screen listing each student's name, ID number, average test score, and course grade.
cout <<"Student Name    Student ID   Averagae Test score   Grade " << endl;
for(int i=0; i<no_of_students; i++)
{
cout << setw(19) << left<< pointer_to_array[i].Student_name <<
setw(19) << pointer_to_array[i].id <<
setw(15) << pointer_to_array[i].average <<
setw(15) << pointer_to_array[i].grade << endl;
}
return 0;
}

Explanation / Answer

1.use strcmp(string a,string b) to compare whether the user has eneterd blank or not.... if he has entered blank the decrement i ..... use the keyword continue; ....it will be prompted again.....

2.Regarding input cout does not allow white spaces to be entered and hence use scanf ....that would be effective

3.regarding output .. your code is full of errors ... i think it would take much tym to debugg it