Write a C++ Program to enter student details using Class

By | 31.12.2016

Enter student details using Class


Write a C++ Program to enter student details by Passing parameters to constructors. Here’s a Simple C++ Program to enter student details using Class in C++ Programming Language.


What is Class and Objects in C++?


  • Class is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating instance of that class.
  • The variables inside class definition are called as data members and the functions are called member functions.
  • Class is just a blue print, which declares and defines characteristics and behavior, namely data members and member functions respectively. And all objects of this class will share these characteristics and behavior.

  • Objects are instances of class, which holds the data variables declared in class and the member functions work on these class objects.
  • Each object has different data variables. Objects are initialized using special class functions called Constructors.

Below is the source code for C++ Program to enter student details using Class which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C++ Program to enter student details using Class  */

#include<iostream>
using namespace std;

class Student
{
    private:
        int marks;
        char grade;
    public:
        Student(int m, char g)
        {
            marks= m;
            grade= g;
        }

        void show()
        {
            cout<<"\nMarks ="<<marks<<endl;
            cout<<"\nGrade = "<<grade<<endl;
        }
};

int main()
{
    Student s1(730, 'A'), s2(621,'B');
    cout<<"Record of student 1 :: -----------------"<<endl;
    s1.show();
    cout<<"\nRecord of student 2 :: -----------------"<<endl;
    s2.show();

    return 0;
}

OUTPUT : :


/*  C++ Program to enter student details using Class  */

Record of student 1 :: -----------------

Marks =730

Grade = A

Record of student 2 :: -----------------

Marks =621

Grade = B

Process returned 0

Above is the source code and output for C++ Program to enter student details using Class which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments