The classes are the most important feature of C++ that leads to Object Oriented programming. 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.
A class provides the blueprints for objects, so basically an object is created from a class. We declare objects of a class with exactly the same sort of declaration that we declare variables of basic types. Following statements declare two objects
First we create a class which store the name string data type, marks integer data type, result as string and grade as string.
class student { public: string sname;// name of the student int marks; // marks of students string result; // students result };
In the above class student we declare three variables which store the information of about the student.
Now we declare the object of that class.
Student info; // Declare a object variable info of student class // (where student is class / user define data type)
Now we write a complete program:
#include using namespace std; class student { public: string sname; // name of the student int marks; // marks of students string result; // students result }; int main() { student info;// object of class student // get the information cout<<"Enter the Student name"< >info.marks; cout< 40) info.result="Pass"; else info.result="Fail"; // dipslay the information on screen cout << "Your Information : " <
Declaring and Initializing Local Variable in C
Declaring and Initializing Global Variable in C Language
Printf Function In C Language
Sacnf Function In C Language
for Loop in C Language
While Loop in C Language
Do While Loop in C Language
Switch Case Statement IN C
IF -Else Statement IN C
Break Statement IN C /C++
User Define Function IN C /C++
Cout/Cin Function IN C /C++
Array IN C /C++
Two Dimensional Array IN C /C++
String In IN C /C++
Pointer In IN C /C++
Const and volatile keyword IN C /C++
Class and Object in C++
Function Over Loading in C++
Character Array In C++
Constructor in C++
Operator overloading in C++
Function Templates in C++
ATM Sample Project In Simple C Language
Find Area of Shape Using Function In C++