Please Write the program in C++ language using simple terms that can be understo
ID: 3718488 • Letter: P
Question
Please Write the program in C++ language using simple terms that can be understood by beginners. Thank you!?
PLEASE DON'T GOOGLE IT !!
12. Course Grade Write a program that uses a structure to store the following data: Member Name Name Idnum Tests Average Grade Description Student name Student ID number Pointer to an array of test scores Average test score Course grade er 11 Structured Data 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 culated and stored in the average member of each structure. The course grade should be computed on the basis of the following grading scale: and all the test scores for each student. The average test score should be cal- Average Test Grade Course 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 stu- dent'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 nega tive numbers for any test score.Explanation / Answer
//Student.cpp
#include <iostream> // Header file imports
using namespace std; // adding namespace
//Creating structure of student
struct Student
{
char sname[100];
int idnum;
int *tests;
float average;
char grade;
};
//main function
int main()
{
int ts,sts; // variable declaration
int i,j,k,marks,sum;
cout<<"Enter number of tests:"<<endl;
cin>>ts;
cout<<"Enter number of students"<<endl;
cin>>sts;
struct Student st[sts]; // Number of students
// For each student
for(i=0;i<sts;i++){
sum=0;
cout<<"Enter Student Name:"<<endl;
cin>>st[i].sname;
cout<<"Enter Student Id Number:"<<endl;
cin>>st[i].idnum;
st[i].tests =(int*) malloc(ts*sizeof(int)); //Allocating memory for pointer array
for(j=0;j<ts;j++){
cout<<"Enter the student test marks:"<<(j+1)<<endl;
cin>>marks;
if(marks>0){ //Input validation for non-negative values
st[i].tests[j] = marks; //Storing each mark in pointer array
}else{
cout<<"Please enter valid test score:"<<endl;
j=j-1;
}
}
for(k=0;k<ts;k++){
sum = sum+st[i].tests[k]; //Summation of each student marks
}
st[i].average = sum/ts; // Finding average
// Finding grade
if(st[i].average>=91 && st[i].average<=100){
st[i].grade='A';
}else if(st[i].average>=81 && st[i].average<=90){
st[i].grade='B';
}else if(st[i].average>=71 && st[i].average<=80){
st[i].grade='C';
}else if(st[i].average>=61 && st[i].average<=70){
st[i].grade='D';
}else{
st[i].grade='F';
}
}
//Printing results of each students
cout<<"NAME ID AVERAGE GRADE ";
for(i=0;i<sts;i++){
cout<<st[i].sname<<" "<<st[i].idnum<<" "<<st[i].average<<" "<<st[i].grade<<endl;
}
return 0;
}
Output:
Enter number of tests:
2
Enter number of students
2
Enter Student Name:
jack
Enter Student Id Number:
101
Enter the student test marks:1
89
Enter the student test marks:2
98
Enter Student Name:
john
Enter Student Id Number:
102
Enter the student test marks:1
67
Enter the student test marks:2
78
NAME ID AVERAGE GRADE
jack 101 93 A
john 102 72 C
Output-2:
Enter number of tests:
2
Enter number of students
1
Enter Student Name:
jack
Enter Student Id Number:
101
Enter the student test marks:1
89
Enter the student test marks:2
-89
Please enter valid test score:
Enter the student test marks:2
67
NAME ID AVERAGE GRADE
jack 101 78 C
Output-3:
Enter number of tests:
3
Enter number of students
2
Enter Student Name:
jack
Enter Student Id Number:
101
Enter the student test marks:1
78
Enter the student test marks:2
76
Enter the student test marks:3
-65
Please enter valid test score:
Enter the student test marks:3
89
Enter Student Name:
john
Enter Student Id Number:
102
Enter the student test marks:1
65
Enter the student test marks:2
54
Enter the student test marks:3
-34
Please enter valid test score:
Enter the student test marks:3
89
NAME ID AVERAGE GRADE
jack 101 81 B
john 102 69 D
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.