Simple Class Example Program In C++
Definition
A class is a blueprint, or prototype which defines and describes the member attributes and member functions.
The C++ programming language allows programmers to separate program-specific datatypes through the use of classes. Classes define types of data structures and the functions that operate on those data structures. Instances of these datatypes are known as objects and can contain member variables, constants, member functions, and overloaded operators defined by the programmer.
Syntactically, classes are extensions of the C struct, which cannot contain functions or overloaded operators.
for better understanding,
- OOPS Overview and Concepts
- Introduction of Classes ( OOPS )
- Constructors and Destructors in C++ Classes
Class Syntax
class classname {
Access - Specifier :
Member Varibale Declaration;
Member Function Declaration;
}
Simple Class Example Program
/* Example Program Simple Class Example Program In C++
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include <iostream>
#include<conio.h>
using namespace std;
// Class Declaration
class person {
//Access - Specifier
public:
//Variable Declaration
string name;
int number;
};
//Main Function
int main() {
// Object Creation For Class
person obj;
//Get Input Values For Object Varibales
cout << "Enter the Name :";
cin >> obj.name;
cout << "Enter the Number :";
cin >> obj.number;
//Show the Output
cout << obj.name << ": " << obj.number << endl;
getch();
return 0;
}
Sample Output
Enter the Name :Byron
Enter the Number :100
Byron: 100
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming