Write a C++ program to Create a class student using function overloading

Write a C++ program to Create a class student using function overloading

Assignment
21

Create a class student containing data members:

a. Roll_no      b. name          c. marks1, marks2, marks3.
           Write necessary member functions:
                a. to accept details
of one students
                b. to accept
details of all students
                c. to display details
of one student
                d. to display details
of all students
                (Use Function
overloading).

Program Code for run:

#include
<iostream>

using
namespace std;

class
Student

{

            int Roll_no, marks1, marks2, marks3;

            float per;

            char name[50];

    public:

            void accept();

            void accept(Student *s, int n);

            void display();

            void display(Student *s, int n);

};

void
Student :: accept()

{

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t \t Enter one
student details \n”;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t Enter Roll
Number of Student ” << endl << ” \t “;

            cin >> Roll_no;

            cout << ” \t Enter Name
of Student ” << endl << ” \t “;

            cin >> name;

            cout << ” \t \t Enter
marks of Three Subject ” << endl;

            cout << ” \t Enter Mark
of Subject 1 ” << endl << ” \t “;

            cin >> marks1;

            cout << ” \t Enter Mark
of Subject 2 ” << endl << ” \t “;

            cin >> marks2;

            cout << ” \t Enter Mark
of Subject 3 ” << endl << ” \t “;

            cin >> marks3;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            per = (marks1 + marks2 + marks3) /
3;

}

void
Student :: accept(Student s[], int n)

{

     for ( int i = 1 ; i <= n ; i++)

     {

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t \t Enter
” << i << ” student details \n”;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t Enter Roll
Number of Student ” << endl << ” \t “;

            cin >> s[i].Roll_no;

            cout << ” \t Enter Name
of Student ” << endl << ” \t “;

            cin >> s[i].name;

            cout << ” \t \t Enter
marks of Three Subject ” << endl;

            cout << ” \t Enter Mark
of Subject 1 ” << endl << ” \t “;

            cin >> s[i].marks1;

            cout << ” \t Enter Mark
of Subject 2 ” << endl << ” \t “;

            cin >> s[i].marks2;

            cout << ” \t Enter Mark
of Subject 3 ” << endl << ” \t “;

            cin >>             s[i].marks3;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            s[i].per = (s[i].marks1 +
s[i].marks2 + s[i].marks3) / 3;

     }

}

 

void
Student :: display()

{

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t \t One
student details \n”;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t Roll Number
” << Roll_no;

            cout << ” \t \t Name :
” << name << endl;

            cout << ” \t \t \t Mark
Sheet” << endl;

            cout << ” \t \t Subject
\t Mark ” << endl;

            cout << ” \t \t Subject 1
\t ” << marks1 << endl;

            cout << ” \t \t Subject 2
\t ” << marks2 << endl;

            cout << ” \t \t Subject 3
\t ” << marks3 << endl;

            cout << ” \t \t \t
Percentage : ” << per << endl;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

}

 

void
Student :: display(Student s[], int n)

{

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t \t ”
<< n << ” student details \n”;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t RNo \t Name
\t Sub1 \t Sub2 \t Sub3 \t Per ” << endl;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

     for ( int i = 1 ; i <= n ; i++)

     {

            cout << ” \t ”
<< s[i].Roll_no << ” \t ” << s[i].name <<
” \t ” << s[i].marks1 ;

            cout << ” \t “<<
s[i].marks2 << ” \t ” << s[i].marks3 << ” \t
” << s[i].per ;

cout << endl;

     }

     cout << ” * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * ” << endl;

}

 

int
main()

{

   Student s, s1[10];

   //Enter maximum 10 student information

   int n;

   while(1)

   {

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << ” \t \t \t Student Details ” << endl;

            cout << ” \t One Student
: 1 \t\t More than One Student : 2 \n”;

            cout << ” \t \t \t Exit :
Other \n”;

            cout << ” \t\t Choose
Appropriate option \n”;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            cout << “\t”;

            cin >> n;

            cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;

            switch(n)

            {

                        case 1: s.accept();

                                    s.display();

                                    break;

                        case 2: cout<<“\tHow
many Student details accept “<<endl<<” \t “;

                                    cin >>
n;

                                    s.accept(s1,
n);

                                    s.display(s1,
n);

                                    break;

                        default: cout <<
” Thank You to Use this Program !”;

                                    exit(0);

            }

   }

}

Output
of Program:

*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                                     Student Details 
             One Student : 1                    More than
One Student : 2
                                     Exit : Other
                         Choose Appropriate option
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
            1
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         Enter one student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             Enter Roll Number of Student
             101
             Enter Name of Student
             Yogi
                         Enter marks of Three Subject
             Enter Mark of Subject 1
             78
             Enter Mark of Subject 2
             87
             Enter Mark of Subject 3
             98
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         One student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             Roll Number 101                  Name : Yogi
                                     Mark Sheet
                         Subject           Mark
                         Subject 1       78
                         Subject 2       87
                         Subject 3       98
                                     Percentage : 87
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                                     Student Details 
             One Student : 1                    More than
One Student : 2
                                     Exit : Other
                         Choose Appropriate option
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
            2
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             How many Student details accept
             3
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         Enter 1 student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             Enter Roll Number of Student
             1010
             Enter Name of Student
             Kavya
                         Enter marks of Three Subject
             Enter Mark of Subject 1
             87
             Enter Mark of Subject 2
             88
             Enter Mark of Subject 3
             89
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         Enter 2 student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             Enter Roll Number of Student
             1011
             Enter Name of Student
             Deepa
                         Enter marks of Three Subject
             Enter Mark of Subject 1
             67
             Enter Mark of Subject 2
             78
             Enter Mark of Subject 3
             79
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         Enter 3 student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
             Enter Roll Number of Student
             1012
             Enter Name of Student
             RAM
                         Enter marks of Three Subject
             Enter Mark of Subject 1
             54
             Enter Mark of Subject 2
             57
             Enter Mark of Subject 3
             98
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                         3 student details
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 RNo    Name         
Sub1  Sub2   Sub3     Per
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 1010  Kavya             87        88        89        88
 1011  Deepa            67        78        79        74
 1012  RAM              54        57        98        69
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
                                     Student Details 
             One Student : 1                    More than
One Student : 2
                                     Exit : Other
                         Choose Appropriate option
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
            3
 * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
 Thank You to Use this Program !

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top