Classes in OOP (Object Oriented Programming)
Classes and Functions in OOP (Object Oriented Programming)
In object-oriented programming, a class is a template definition of the methods and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables.
The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are:
- A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass
- Subclasses can also define their own methods and variables that are not part of their superclass.
- The structure of a class and its subclasses is called the class hierarchy.
A Simple Program defining Classes using OOP (Object Oriented Programming) is given below in which i have made a class named Student:
#include<iostream>
using namespace std;
class student
{
int rollnumber;
char name[120];
char FatherName[120];
public:
void Setstudent()
{
cout << "Please enter roll number:";
cin >> rollnumber;
cout << "Please enter name:";
cin >> name;
cout << "Please enter Father Name:";
cin >> FatherName;
}
void Getstudent()
{
cout << "Rollnumber:" << rollnumber << "\n";
cout << "Name:" << name << "\n";
cout << "FatherName:" << FatherName << "\n";
}
};
int main()
{
student s[10];
for(int i=1;i<=10;i++)
{
s[i].Setstudent();
}
}
using namespace std;
class student
{
int rollnumber;
char name[120];
char FatherName[120];
public:
void Setstudent()
{
cout << "Please enter roll number:";
cin >> rollnumber;
cout << "Please enter name:";
cin >> name;
cout << "Please enter Father Name:";
cin >> FatherName;
}
void Getstudent()
{
cout << "Rollnumber:" << rollnumber << "\n";
cout << "Name:" << name << "\n";
cout << "FatherName:" << FatherName << "\n";
}
};
int main()
{
student s[10];
for(int i=1;i<=10;i++)
{
s[i].Setstudent();
}
}
Comments
Post a Comment