Oop 1
Oop 1
class time
t
int hours;
int minutes;
public:
void gettime(int h, int m)
{
hours=h;
minutes-m;
}
void puttime(void)
t
cout<< hours<<"hours and:”;
cout<
class sample
{
int a;
int b;
publie:
void setvalue( ) { a=25:b=40;}
friend float mean( sample s);
I
float mean (sample s)
t
return (float(s.a+s.b)/2.0);
}
int main()
{
PTAsample x;
x . setvalue( );
cout<<"mean value="<
public:
void setvelue(int x) {x= I; }
friend void max (xyz,abe);
h
class abe
{
int a;
publ
void setvelue( int i) {a=i; }
friend void max(xyz,abe);
void. max( xyz m, abe n)
t
iffm .x>=n.a)
‘cout=
class class-2;
class class-1
t
56 PTCint value |;
void indata( int a) { value=a; }
void display(void) { cout<
class account;
class account2
t
private:
int balance;
public:
account2( ) { balance=567; }
void showace2( )
{
cout<<"balanceinaccount2 is:”<
class complex
t
float x;
float y;
public:
void input( float real , float imag)
{
xereal;
yeimag;
}
friend complex sum( complex , complex);
void show ( complex );
i
complex sum (complex e1, complex ¢2)
t
complex ¢3;
€B.xel.xte2.x;
©3.yel ye
return ¢33}
void complex ::show (complex ¢)
{
cout<<¢,x<<" +] “< * ip;
cout<a;
The deferencing operator ->* is used as to accept a member when we use pointers to
both the object and the member. The dereferencing operator. .* is used when the object itself is used
with the member pointer. Note that * ip is used like a member name.
We can also design pointers to member functions which ,then can be invoked using
the deferencing operator in the main as shown below.
(object-name.* pointer-to-member function)
(pointer-to -object -> * pointer-to-member function)
The precedence of () is higher than that of |.* and ->* , so the parenthesis are
necessary,
61
PTADEREFERENCING OPERATOR:
#include
class M
void set_xy(int a,int b)
{
yb;
}
friend int sum(M);
hs
int sum (M m)
‘
int M :: * px= &M =: x; //pointer to member x
int Ms: * py- & m::yy/pointer to y
M* pm=&m;
int s-m.* px + pm->py;
return(s);
}
int main ()
t
Mm;
void(M::*pf)(int,int)=&M::set-xy;//pointer to function set-xy (n*pi\( 10,20);
invokes set-xy
cout<<"sum=:"<* pf)(30,40); // invokes set-xy
cout<<"sum="<
#inelude
class abe
t
private:
char nmi;
public:
abe ()
t
cout<<"enter your name:”;
cin>>nm;
}
void display( )
t
}
cout<
class integer
u
output:
object 1
m0
n=100
object?
m=25
integer(int,int);
void display( void)
cout<<"m=:"<
#include
class abe
{
private:
char nm [30];
int age;
public:
abe (){ }// default
abe ( char xf}, int y);
void get()
{
cout<<"enter your name:”;
cin>>nm;
cout<<” enter your age:
cin>>age;
ot
void display( )
t
cout<
#inelude
class sum
t
private;
int a;
int b;
int ¢;
float d;
double e;
public:
sum()t
cout<<"enter a;”;
cin>>a;
cout<<"enter b:”:
cin>>b;
cout<<"sur
}
sum(int aint b);
sum(int a, float d,double c);
= *<
class code
{
int id;public
code () { } “constructor
code (int a) { ida; } //eonstructor
code(code &x)
{
Id-x.id;
}
vi isplay( )
{
cout<
Hinelude
class string
t
char *name;
int eng
public:
string ()ew char [length+1]; /* one extra for \0 */
string( char *s) //constructor 2
{
length=strlen(s);
name=new char [length+1];
strepy(name,s);
}
void display(void)
{
cout<
int count=
class alpha
t
publie:
alpha( )
t
count ++;
cout<<"\n no of object created :”<
int x=I;
class abe
t
public:
abe( )
t
x5
cout<<"construct the no”<
#include
class stock2;
class stock
t
int code, item;
float price;
public:
stockl (int a, int b, float c)
{
code=a;
item=b;
price=c;
}
void disp( )
{
cout<<"eode"<You might also like
- 6. Introduction to Programming (POPvsOOP)
No ratings yet6. Introduction to Programming (POPvsOOP)5 pages - EContent_3_2025_01_30_19_48_10_Unit1_lntroductionpptxUpdatedpptx__2025_01_16_15_52_58
No ratings yetEContent_3_2025_01_30_19_48_10_Unit1_lntroductionpptxUpdatedpptx__2025_01_16_15_52_5868 pages - Object Oriented Programming Using C++: UNIT-1
No ratings yetObject Oriented Programming Using C++: UNIT-143 pages - Evolution of Programming Methodologies and Consepts of Oop
100% (1)Evolution of Programming Methodologies and Consepts of Oop48 pages - Procedure Oriented Programming Language
No ratings yetProcedure Oriented Programming Language273 pages - Object Oriented Programming With C++ 18CS44
No ratings yetObject Oriented Programming With C++ 18CS4423 pages - Lecture 6 Introduction to Object Oriented Programming
No ratings yetLecture 6 Introduction to Object Oriented Programming26 pages