OOP PROGRAMMING LANGUAGE: C++ In main program, ask user for the number of students whose records must be inserted in file. Afterwards, take records from user, calculate grade of students and store all records in a file. Code: #include #include using namespace std; #define MAX 10
SUBJECT: OOP
In main program, ask user for the number of students whose records must be inserted in file. Afterwards, take records from user, calculate grade of students and store all records in a file.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
#define MAX 10
class student
{
private:
char name[30];
char sec[30];
char sem[30];
int course1M, course2M, course3M;
int EnrollNo;
int total;
float avg;
char Grade;
public:
student()
{
EnrollNo = 0;
course1M = 0;
course2M = 0;
course3M = 0;
total = 0;
avg = 0;
}
void SetDetails();
void GetDetails();
float grade(float avg);
};
void student::SetDetails()
{
cout << "Enter student name: ";
cin >> name;
cout << "Enter Enrollment number: ";
cin >> EnrollNo;
cout << "Enter semester: ";
cin >> sem;
cout << "Enter Section: ";
cin >> sec;
cout << "Enter course 1 mark out of 100: ";
cin >> course1M;
cout << "Enter course 2 mark out of 100: ";
cin >> course2M;
cout << "Enter course 3 mark out of 100: ";
cin >> course3M;
total = course1M + course2M + course3M;
avg = total / 3;
Grade = grade(avg);
}
float student::grade(float avg)
{
if (avg >= 90 && avg <= 100)
return 'A';
else if (avg >= 80 && avg <= 89)
return 'B';
if (avg >= 70 && avg <= 79)
return 'C';
if (avg >= 60 && avg <= 69)
return 'D';
if (avg >= 50 && avg <= 59)
return 'E';
if (avg <= 49)
return 'F';
}
void student::GetDetails(){
cout << "\nStudent details:";
cout << "\nName:" << name;
cout << "\nEnrollment Number:" << EnrollNo;
cout << "\nSection:" << sec;
cout << "\nSemester:" << sem;
cout << "\nTotal:" << total;
cout << "\nAverage:" << avg;
cout << "\nGrade: " << Grade;
}
int main()
{
student stu[MAX];
int n;
cout << "Enter total number of students: ";
cin >> n;
for (int i = 0; i< n; i++){
cout << "Enter details of student " << i + 1 << ":\n";
stu[i].SetDetails();
}
cout << endl;
for (int i = 0; i< n; i++){
cout << "Details of student " << (i + 1) << ":\n" << endl;
stu[i].GetDetails();
}
_getch();
return 0;}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)