C++ program to swap two variables using function overloading

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

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

21 thoughts on “C++ program to swap two variables using function overloading

  1. 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

  2. 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.

  3. 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.

  4. 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.

  5. That is very fascinating, You’re a very skilled blogger.
    I have joined your rss feed and sit up for seeking more of your wonderful post.
    Additionally, I have shared your web site in my social networks

  6. Right here is the right web site for everyone who really wants to find out about this
    topic. You realize so much its almost hard to argue with
    you (not that I personally would want to…HaHa). You certainly put a
    new spin on a topic that has been discussed
    for many years. Wonderful stuff, just excellent!

  7. Pease let me know if you’re looking for a article writer for your blog.
    You have some really good posts and I think I would be a good asset.
    If you ever want to take some of the load off, I’d love to write soime articles
    for your blog in exchange for a link back to mine.
    Please send me an email if interested. Cheers!

  8. Hi there! I could have sworn I’ve been to your blog before
    but after going through a few of the articles I realized
    it’s new to me. Anyways, I’m certainly pleased I came
    across it and I’ll be book-marking it and checking back regularly!

  9. Good day I am so delighted I found your webpage, I really found you
    by mistake, while I was browsing on Askjeeve for something else, Anyhow
    I am here now and would just like to say thanks for a
    incredible post and a all round interesting blog (I also love the theme/design), I
    don’t have time to browse it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back
    to read much more, Please do keep up the excellent
    work.

  10. Find all the newest new and Movie Reviews at Movie Vault.
    The tools are somewhat limited and geared towards those who do not
    have professional training, and a guide to Windows Movie Maker may be just what
    newbies need to get started putting together their
    own video masterpieces. Here are three tips that
    movie stars use to help you.

  11. I used to be recommended this blog by means of my cousin. I am no
    longer positive whether or not this publish
    is written by him as nobody else realize such unique approximately my difficulty.
    You are incredible! Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in