Mar 20, 2007

C++ program to demonstrate class and object (OOP)

class : class is a template for an object. (master copy)
object : object is an instance of a class. (photo copy)
members of the class are by default private. private means members can not be accessible from anywhere in the prgraom excpet where it is defined.
This program to demonstrate C++ class/object
It will ask user to input roll no., name and marks of a student.

#include<iostream.h>
#include<conio.h>
class student
{
public :
int rn; // data members
char name[10];
float marks;
};

main()
{
clrscr();
student s1; // s1 is an object.
cout <<"enter any roll number";
cin >> s1.rn;
cout <<"enter name";
cin >> s1.name;
cout <<"enter any marks";
cin >> s1.marks;
getch();
}

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive