If You Are From The 09 Batch Then Read This >>

This Site is created for the Bharati Vidyapeeth's BCA 09 Batch..and hence everyone from you are requested to send your email ID at abhilash238650@gmail.com..Owner will send you a request to your Email-ID and after accepting it even you can post your views, day to day experiences and class works on this blog.
Visit owner's blog at
www.bloggerabhilash.info

Wednesday, December 22, 2010

Program 1 to 10 !!!

 1. swap 2 numbers using call by value.

#include
#include

void swap (int a,int b)
{
int t;
t=a;
a=b;
b=t;

cout<<
}

void main()
{
clrscr();
void swap(int a,int b);
int x,y;
x=10;
y=15;
swap(x,y);
getch();
}



2. swap two numbers using call by reference.


#include
#include

void swap (int *a,int *b)
{
int t;
t=&a;
&a=&b;
&b=t;
}


void main()
{
clrscr();
void swap(int *a,int *b);
int x,y;
x=10;
y=15;
swap(&x,&y);
cout<<"Swapped values are"<<
getch();
}



3.inline function to calculate Area of CIRCLE 

#include
#include

inline float area(int r)
{
return(3.14*r*r);
}

void main()
{
clrscr();
int r=5;
float b;
b=area(r);
cout<
getch();


3.b. inline function for avg of 3 nos.

#include
#include

inline float avg(int a,int b,int c)
{
return((a+b+c)/3);
}

void main()
int a,b,c;
clrscr();
cout<<"Enter the nos.";
cin>>a>>b>>c;
float av=avg(a,b,c);
cout<
getch();
}


3.c. inline function for area of triangle

#include
#include

inline float area(int b,int h)
{
return(0.5*b*h);
}

void main()
{
int b,h;
clrscr();
cout<<"Enter the height and base of triangle";
cin>>b>>h;
float ar=area(b,h);
cout<
getch();
}


4. overload a function to add integer, float and double each having 2 or 3 parameters.

#include
#include

int add(int a,int b);
float add(float a,float b,float c);
double add(double x,double y);

int add(int a,int b)
{
return(a+b);
}
float add(float a,float b,float c)
{
return(a+b+c);
}
double add(double x,double y)
{
return(X+y);
}

void main()
{
clrscr();
cout<<
cout<<
cout<<
getch();
}


5. overload a function to calculate area of rectangle having different data types such as integer,float and double.

 #include
#include

int area(int l,int b);
float area(float l,float b);
double(double l,double b);

int area(int l,int b)
{
return(l*b);
}
float area(float l,float b)
{
return(l*b);
}
double area(double l,double b)
{
return(l*b);
}

void main()
{
int l,b;
clrscr();
cout<<
cout<<
cout<<
getch();
}



6. To calculate area of triangle ,rectangle and square. 


#include
#include

float triangle(float b,float h);
float rectangle(float l,float b);
float square(float s);

float triangle(float b,float h)
{
return(0.5*b*h);
}
float rectangle(float l,flaot b)
{
return(l*b);
}
float square(float s)
{
return(4*s);
}

void main()
int l,b,h,s;
clrscr();
cout<<
cout<<
cout<<
getch();



7. To find the interest with rate 1.5 using default argument 


#include
#include

float interest(int p,int n,float r=1.5)
{
return((p*n*r)/100);
}

void main()
{
clrscr();
int p,n;
cout<<"Enter principle and no.years \n";
cin>>p>>n;
float i=interest(p,n);
cout<<"interest is"<
getch();



8. to give alias name to a variable principle in calculating simple interest & then modifying the variable. 


#include
#include

float interest(int p,int n,float r)
{
return((p*n*r)/100);
}

void main()
{
clrscr();
int p,n;
int &alias=p;
float r;
cout<<"Enter the principles & no. of years \n";
cin>>p>>n>>r;
float i=interest(p,n,r);
cout<<"\n interest is before modifying \t"<
alias=20;
cout<<"\n principle is modified \t"<i=interest(p,n,r);
cout<<"\n Interest after modifying principle \t"<
getch();
}



9. Swap the 2 numbers using reference variable.


#include
#include

void swap(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}

void main()
{
void swap(int &a,int &b);
clrscr();
int x=10;
int y=20;
cout<<"before swapping \t"<<<"   \t"<
swap(x,y);
cout<<"  \n after swapping   \t"<<<    \t"<
getch();
}



10. to take student's information from the user & display it using CLASS student. 


#include
#include

class stud
{
int rno;
char name[20];
public:
void getdata()
{
cout<<"Enter the roll no. &name \n";
cin>>rno>>name;
}
void display()
{
cout<<"\n Roll no \t"<<<" \n Nmae  \t"<
}
};

void main()
{
clrscr();
stud s;
s.getdata();
s.display();
getch();
}

No comments:

Post a Comment

You can ask your queries here and we will try to get back to you as soon as we will be done working with that..

Note: Only a member of this blog may post a comment.

Just Type The Keyword To Search Your Answer -- >>