FUNCTION OVERLOADING
AIM:
A program to demonstrate how function overloading is carried out for swapping of two variables of the various data types, namely integer, floating point number and character types
ALGORITHAM:
• Start the process
• Get the integer values of ix,iy
• Get the floating values of fx,fy
• Get the character values of cx,cy
• Call swap(ix,iy)
o Assign temp<-a
o Assighn a<-b,b<-temp
• Swapping the integer values
• Print the value of ix and iy
• Swapping floating values
• Print the values oh fx and fy
• Swapping on characters
• Print the value of cx,cy
• Stop the process
PROGRAM
#include<iostream.h> #include<conio.h> void swap(int &ix,int &iy); void swap(float &fx,float &fy); void swap(char &cx,char &cy); void main() { int ix,iy; float fx,fy; char cx,cy; clrscr(); cout<<"Enter 2 integers:"; cin>>ix>>iy; cout<<"Enter 2 floating point no:s:"; cin>>fx>>fy; cout<<"Enter 2 characters:"; cin>>cx>>cy; cout<<"\nIntegers:"; cout<<"\nix="<<ix<<"\niy="<<iy; swap(ix,iy); cout<<"\nAfter swapping"; cout<<"\nix="<<ix<<"\niy="<<iy; cout<<"\nFloating point no:s"; cout<<"\nfx="<<fx<<"\nfy="<<fy; swap(fx,fy); cout<<"\nAfter swapping"; cout<<"\nfx="<<fx<<"\nfy="<<fy; cout<<"\nCharacters"; cout<<"\ncx="<<cx<<"\ncy="<<cy; swap(cx,cy); cout<<"\nAfter swapping"; cout<<"\ncx="<<cx<<"\ncy="<<cy; getch(); } void swap(int &a,int &b) { int temp; temp=a; a=b; b=temp; } void swap(float &a, float &b) { float temp; temp=a; a=b; b=temp; } void swap(char &a, char &b) { char temp; temp=a; a=b; b=temp; }
Output:
Enter 2 integers: 100 200
Enter 2 floating point no:s :-11.11 22.22
Enter 2 characters: s t
Integers:
Ix=100
Iy=200
After swapping
Ix=200
Iy=100
Floating point no:
Fx=-11.11
Fy=22.22
After swapping
Fx=22.22
Fy=-11.11
Characters
Cx=s
Cy=t
After swapping
Cx=t
Cx=s
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
April 4th, 2010 at 5:54 pm
very nice example
June 15th, 2010 at 12:35 am
I’m not quite as well familiar with this subject. I extra so just prefer to go to blogs for layout tips and details like that. But you definitely designed a subest that i in most cases care practically nothing about pretty interesting. That is a awesome blog site to design mine following. I wish you don’t mind if i bookmark your blog, to ensure i can effortlessly pick it once again during the long term. Cheers
June 21st, 2010 at 4:03 am
I assumed it was proceeding to be some unexciting old report, nonetheless it actually compensated for my time. I most definitely will submit a link to this submit on my web page. I am convinced my visitors are planning to locate that absolutely useful.
August 23rd, 2010 at 2:34 pm
Only one of my favored facts about blogging is this community of bloggers. We aren’t cut-throat. We share successes and miseries. And when a thing operates, we really don’t continue it to ourselves – we want it to operate for all of us. I adore blogging and wish that it becomes full-time one day, but I get pleasure from the mastering and growing (the journey) and am an extremely patient man.
August 24th, 2010 at 12:18 am
I’ve been thinking the exact exact issue myself recently. Glad to see anyone for the identical wavelength! Nice content.
August 24th, 2010 at 12:47 am
Im no expert, but I think you just constructed an exceedingly nice point stage. You naturally know what youre talking about, and I can ultimately get behind that. Thanks for getting so upfront and so sincere.
April 27th, 2011 at 10:17 pm
nice sight but than too.programs must be in simple language so that it could be easily understandable……..and one more thing every solution..IE…… multiple solution of every program should be there for the better understanding of a viewer and especially students………….
September 7th, 2011 at 4:54 pm
Nice