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

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 8E
icon
Related questions
Question

SUBJECT: 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 <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;}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr