Create a C++ class for a student with member function accepting marks and display all information using of manipulators


Assignment 17

 Create a C++ class for a student object with the following attributes—roll no, name, number of subjects, marks of subjects. Write member function for accepting marks and display all information of student along with total and Percentage. Display mark list with using of manipulators.

Program Code for run:

#include <iostream>

using namespace std;

#include<iomanip>

class Student

{

            private:

                        int Roll_Number, Marks[5];

                        char Stud_Name[80], Class;

                        float Per;

            public:

                        void accept();

                        void display();

};

void Student :: accept()

{

            cout << " Accept Student Roll Number "<< endl;

            cin >> Roll_Number;

            cout << " Accept Student Name"<< endl;

            cin >> Stud_Name;

            cout << " Accept Student Marks "<< endl;

            float total = 0;

            for( int i = 0; i < 5; i++)

            {

                        cout << " \t Subject "<< i + 1 << endl;

                        cin >> Marks[i];

                        total = total + Marks[i];

            }

            Per = total / 5; // calculate Percentage

            if(Per < 60)

                        Class='B';

            if((Per >= 60)&&(Per < 70))

                        Class='A';

            if(Per >= 70)

                        Class='O';

}

void Student :: display()

{

               cout << setw(7) << Roll_Number << setw(7) << Stud_Name << setw(7);

               for( int i = 0; i < 5; i++)

                        cout<< Marks[i] << setw(7);

               cout << setw(7) << setprecision(2) << Per << "    " << Class << "\n";

}

 

int main()

{

            int n, i;

            Student p[20];

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            cout << " \t How many Student data to enter " << endl;

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            cin >> n;

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            cout << " \t Enter Student Details " << endl;

            for ( i = 0 ; i < n ; i ++)

            {

                cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

                cout<<"\t Enter Student Details of Student := " << i + 1 << endl;

                cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

                p[i].accept();

            }

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            cout << " Display Student Details " << endl;

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            cout << setw(7) << "RNO" << setw(7) << "SName" << setw(7) << "Sub1";

            cout << setw(7) << "Sub 2"<< setw(7) << "Sub 3" << setw(7) << "Sub4";

          cout<< setw(7) << "Sub 5" << setw(7) << "Per" << setw(7) << "Class" <<endl;

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            for ( i = 0 ; i < n ; i ++)

                        p[i].display();

            cout << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " << endl;

            return 0;

}

Output of Program:

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             How many Student data to enter

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

5

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details of Student := 1

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Accept Student Roll Number

1

 Accept Student Name

RAM

 Accept Student Marks

             Subject 1

54

             Subject 2

55

             Subject 3

56

             Subject 4

57

             Subject 5

58

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details of Student := 2

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Accept Student Roll Number

2

 Accept Student Name

RAJ

 Accept Student Marks

             Subject 1

65

             Subject 2

64

             Subject 3

67

             Subject 4

68

             Subject 5

69

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details of Student := 3

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Accept Student Roll Number

3

 Accept Student Name

YOGI

 Accept Student Marks

             Subject 1

98

             Subject 2

97

             Subject 3

99

             Subject 4

97

             Subject 5

98

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details of Student := 4

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Accept Student Roll Number

4

 Accept Student Name

KAVYA

 Accept Student Marks

             Subject 1

84

             Subject 2

86

             Subject 3

88

             Subject 4

82

             Subject 5

65

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

             Enter Student Details of Student := 5

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Accept Student Roll Number

5

 Accept Student Name

DEEPA

 Accept Student Marks

             Subject 1

91

             Subject 2

92

             Subject 3

93

             Subject 4

94

             Subject 5

95

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Display Student Details

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    RNO     SName   Sub1  Sub 2  Sub 3   Sub4  Sub 5    Per  Class

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

      1       RAM      54     55     56     57     58     56     B

      2        RAJ      65     64     67     68     69     67      A

      3      YOGI      98     97     99     97     98     98     O

      4   KAVYA      84     86     88     82     65     81     O

      5    DEEPA      91     92     93     94     95     93     O

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Comments