0% found this document useful (0 votes)
5 views

Pointers and Function Overloading

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Pointers and Function Overloading

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Write a program to define a class ‘account’ having data

members as account_no , name and balance. Accept and


display this information for 10 objects of this class using
pointer to object.
# include <iostream.h>
# include <coinio.h>
class account
{ private : int account_no;
char name [50];
float balance;
public :
void getdata ( void )
{
cout << “ENTER account no: “ ;
cin >> account_no;
cout << “ENTER name : “;
cin>> name;
cout << “ENTER balance : “;
cin >> balance;
}
void showdata ()
{
cout << “ Account no = “ << account_no <<endl;
cout << “ Name = “ << name <<endl;
cout << “ Balance = “ << balance <<endl;
}
};
void main(void)
{
int n;
cout <<”Enter the number of account holders “ ;
cin >> n;
account *a = new account[n];
for (int i=0; i<=n ; i++)
{
a -> getdata ();
a-> display();
a++;
}
}

 write a C++ program to declare a class birthday


having data members as day, month, year.
Accept this information for five objects using
pointer to the array of objects

 Write a C++ program to declare a class "Box"


having data members height, width and
breadth. Accept this information for one object
using pointer to that object . Display the area
and volume of that object.
Write a C++ Program to interchange the values of
two int , float and char using function overloading.
# include <iostream.h>
void swap (int , int ); // function prototype for three
integers
void swap ( float, float); // function prototype for three floats
void swap ( char, char);
void main()
{
int a,b;
cout <<”Enter the two integer numbers “ ;
cin >> a>>b;
cout <<”before swapping “ ;
cout <<”a= “<< a;
cout <<”b= “<< b;
cout <<”after swapping “ ;
swap(a , b );

float c,d;
cout <<”Enter the two float numbers “ ;
cin >> c>>d;
cout <<”before swapping “ ;
cout <<”c= “<< c;
cout <<”d= “<< d;
cout <<”after swapping “ ;
swap(c , d );

char e,f;
cout <<”Enter the two characters“ ;
cin >> e>>f;
cout <<”before swapping “ ;
cout <<”e= “<< e;
cout <<”f= “<< f;
cout <<”after swapping “ ;
swap(e , f );

void swap ( int a ,int b)// 4,6


{
int t;
t=a;//t=4
a=b;//a=6
b=t;//b=4
cout <<”a= “<< a;
cout <<”b= “<< b;

void swap ( float a , float b)


{
float t;
t=a;
a=b;
b=t;
cout <<”a= “<< a;
cout <<”b= “<< b;

}
void swap ( char a , char b)
{
char t;
t=a;
a=b;
b=t;
cout <<”a= “<< a;
cout <<”b= “<< b;

2. Write a C++ Program that find the sum of two


int and double number using function
overloading.
# include <iostream.h>
int sum (int , int );
double sum ( double, double);
void main()
{
int a,b,c1;
cout <<”Enter the two integer numbers “ ;
cin >> a>>b;
cout <<”\n a= “<< a;
cout <<”\n b= “<< b;
c1=sum(a , b );
cout <<”\n c1= “<< c1;

float c,d,c2;
cout <<”Enter the two float numbers “ ;
cin >> c>>d;
cout <<”c= “<< c;
cout <<”d= “<< d;
c2=sum(c , d );
cout <<”\n c2= “<< c2;

}
int sum ( int a ,int b)
{
int t;
t=a+b;
return t;
}

double sum ( double a , double b)


{
double t;
t=a+b;
return t;
}
3. Write C++ program to find the area of various
geometrical shapes by Function overloading.
(eg.Area of circle, circumference of circle etc…)

You might also like