Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Sunday, September 25, 2016

Static Members Both Data And Function

Program To Illustrate The Concept Of Static Members :


#include<iostream>
using namespace std;
class datatype
{
    int a;
    static int count;
    public:
        datatype()
        {
            a=++count;
        }
        void show()
        {
            cout<<"\nValue of Variable is "<<a;
        }
        static void showcount()
        {
            cout<<"\nNo of Objects cretaed "<<count;
        }
};
int datatype::count;

main()
{
    datatype a,b,c;
    a.show();
    b.show();
    c.show();
    datatype::showcount();
}

Wednesday, September 7, 2016

PROGRAM TO ILLUSTRATE THE CONCEPT OF INLINE FUNCTION WITHIN THE CLASS

PROGRAM TO ILLUSTRATE THE CONCEPT OF INLINE FUNCTION WITHIN THE CLASS.

#include <iostream>
using namespace std;
class square
{
public:
int num;

void getdata()
{
cout<<"Enter the Number: ";
cin>>num;
}

int sq();
};

inline int square::sq()
{
return (num*num);
}

int main()
{
square s;
s.getdata();
cout<<"\nSquare of Number is "<<s.sq();
}



Friday, September 2, 2016

PROGRAM TO ILLUSTRATE THE CONCEPT OF CLASS AND OBJECT:
// program to illustrate the concept of classes ans=d objects
#include<iostream>
using namespace std;
class student
{
private:
int rollno;
float marks;
char name[20];
public:
void getdata()
{
cout<<"ENTER NAME ";
cin>>name;
cout<<"ENTER ROLL NO";
cin>>rollno;
cout<<"ENTER MARKS";
cin>>marks;
}
void print()
{
cout<<"YOU ENTERED";
cout<<"\nNAME: "<<name;
cout<<"\nROLL NO: "<<rollno;
cout<<"\nMARKS: "<<marks;
}
};
main()
{
student s;
s.getdata();
s.print();
}