In: Computer Science
This project requires the student to create a record (in C++ called a struct). The record should contain several fields of different data types and should allow the user to search the records to find the student with the highest grade. In this project the student should gain an understanding of the nature of records with multiple data types, how to save the records, search the records and retrieve them. The special problems of maintaining records of multiple data types on a digital machine will be seen.
#include<iostream>
using namespace std;
//structure for a student
struct Student{
//name, id and grade can be stored
string name;
int id;
double grade;
};
int main() {
//reading number of students
int n;
cout << "Enter number of students: ";
cin >> n;
//array of n students
Student students[n];
//poupulating data in array of struct
for(int i = 0 ; i < n ; i ++) {
cout << "\nEnter details of
student " << (i+1) << ": \n";
cout << "Enter Name: "
;
cin >>
students[i].name;
cout << "Enter student Id:
";
cin >> students[i].id;
cout << "Enter grade:
";
cin >>
students[i].grade;
}
//printing data stored in array
cout << "\nStudent Details are: \n";
for(int i = 0 ; i < n ; i ++)
{
cout << "\n\nDetails of
student " << (i+1) << ": \n";
cout << "Name: " <<
students[i].name << endl;
cout << "Student Id: "
<< students[i].id << endl;
cout << "Grade: " <<
students[i].grade << endl;
}
//finding out the student having maximum grade
Student max = students[0];
for(int i = 1 ; i < n ; i++) {
if(students[i].grade >
max.grade){
max =
students[i];
}
}
cout << "\n\nStudent with Highest grade:
\n";
cout << "Name: " << max.name <<
endl;
cout << "Student Id: " << max.id <<
endl;
cout << "Grade: " << max.grade <<
endl;
}
IF THERE IS ANYTHING THAT YOU DO NOT UNDERSTAND, OR NEED
MORE HELP THEN PLEASE MENTION IT IN THE COMMENTS SECTION.