Tuesday, December 16, 2014

C++ using Inline and Inside Function Definition and Constructor Program



Call  by Value

#include
#include
void k(int a,int b, int c)
{
cout<<"Total : "<
void main()
{
int x,y,z;
clrscr();
cout<<"Enter the value for x,y,z";
cin>>x>>y>>z;
getch();
}

Output

Enter the value for x,y,z
60
30
20
Total : 110

Inline Program

#include
#include
inline int square(int val)
{
return(val*val);
}
inline int cube(int val)
{
return (val*val*val);
}
void main()
{
int n;
clrscr();
cout<<"Enter a number\n";
cin>>n;
cout<
cout<<"\n"<
getch();
}

Output
       Enter a number
5
25
525

Inside Function Definition

#include
#include
class value
{
public:
int a,b;
void getdata()
{
cout<<"Enter the a, b value\n";
cin>>a>>b;
}
void add()
{
cout<<"Add value: "<"\n";
}
void sub()
{
cout<<"Sub Value: "<
}
void mul()
{
cout<<"Mul Value: "<
}
void div()
{
cout<<"Div value: "<
}
};
void main();
value a;
a.getdata;
a.add;
a.sub;
a.mul;
a.div();
getch();
}

Output

Enter the a, b value
40
3
Add Value            : 43
Sub value             :37
Mul Value            :120
Div Value             :13

Default Constructor
        
          #include
#include
class center
{
int a,b,c;
public:
center()
{
a=21;
b=12;
c=18;
}
void print()
{
cout<""<
}
};
void main()
{
clrscr();
center a1,a2,a3;
a1.print;
a2.print();
a3.print();
getch();
}

Output
         
          21      12      18
          21      12      18
          21      12      18

No comments:

Post a Comment