Create a program that uses an array of structures of a user-defined type named student_record as shown in the declaration below.
struct student_record{
unsigned long id;
char name[20];
char subject[20];
double mt_grade;
double ft_grade;
double final_rating;
char remarks[20];
};
2. The program should ask how many student records to input (at least 4 records but not more than 20) and allow the user to input as many records of students as specified by the user except for the final rating and remarks. The values for the final rating and remarks should be based on the formula or conditions given below
final_rating = 40%mt_grade +50%ft_grade
remarks
EXCELLENT if the final_rating >=95%
VERY GOOD if the final_rating is between 85% and 94%
GOOD if final_rating is between 75% and 84%
NEEDS IMPROVEMENT if final_rating is below 75%
Display all the records with the computed final rating and remarks in a tabular format
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
struct student_record {
unsigned long id;
char name[20];
char subject[20];
double mt_grade;
double ft_grade;
double final_rating;
char remarks[20];
};
const int N=20;
int main() {
student_record students[N];
int n;
cout << "Enter number of students (no more then " << N << "): ";
cin >> n;
if ( n > N) {
cout << "The number is too big" << endl;
return 1;
}
for (int i=0; i<n; i++) {
cout << endl << "Enter data for " << i+1 << "th student." << endl;
cout << "ID: ";
cin >> students[i].id;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Name: ";
cin.getline(students[i].name, 20);
cout << "Subject: ";
cin.getline(students[i].subject, 20);
cout << "MT grade: ";
cin >> students[i].mt_grade;
cout << "FT grade: ";
cin >> students[i].ft_grade;
students[i].final_rating = 0.4*students[i].mt_grade + 0.5*students[i].ft_grade;
if (students[i].final_rating >= 0.95) {
strcpy(students[i].remarks, "EXCELLENT");
}
else if (students[i].final_rating >= 0.85) {
strcpy(students[i].remarks, "VERY GOOD");
}
else if (students[i].final_rating >= 0.75) {
strcpy(students[i].remarks, "GOOD");
}
else {
strcpy(students[i].remarks, "NEEDS IMPROVEMENT");
}
}
cout << setw(8) << "ID" << setw(20) << "Name" << setw(20) << "Subject"
<< setw(10) << "MT grade" << setw(10) << "FT grade" << setw(10) << "Final rt"
<< setw(20) << "Remarks" << endl;
cout << fixed;
for (int i=0; i<n; i++) {
cout << setw(8) << students[i].id;
cout << setw(20) << students[i].name;
cout << setw(20) << students[i].subject;
cout << setw(10) << setprecision(2) << students[i].mt_grade;
cout << setw(10) << setprecision(2) << students[i].ft_grade;
cout << setw(10) << setprecision(2) << students[i].final_rating;
cout << setw(20) << students[i].remarks;
cout << endl;
}
return 0;
}
Comments
Leave a comment