Quantcast
Channel: Java Question Bank » Cpp Programs
Viewing all articles
Browse latest Browse all 22

‘C++’ Program that uses functions to swap two integers, Characters, Reals using function overloading

$
0
0

***************************************************************************************************************************************************

 A ‘C++’ Program that uses functions to swap two integers, Characters, Reals using function overloading

***************************************************************************************************************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream.h>
#include<conio.h>
void swap(int a,int b)
{
cout<<"\nBefore swapping of integers:\nA="<<a<<"\nB="<<b;
int c=a;
a=b;
b=c;
cout<<"\nAfter swapping of integers:\nA="<<a<<"\nB="<<b;
}
void swap(char a,char b)
{
cout<<"\nBefore swapping of characters:\nA="<<a<<"\nB="<<b;
char c=a;
a=b;
b=c;
cout<<"\nAfter swapping of characters:\nA="<<a<<"\nB="<<b;
}
void swap(float a,float b)
{
cout<<"\nBefore swapping of reals:\nA="<<a<<"\nB="<<b;
float c=a;
a=b;
b=c;
cout<<"\nAfter swapping of reals:\nA="<<a<<"\nB="<<b;
}

void main()
{
int a,b;
clrscr();
cout<<"Enter two integers :";
cin>>a>>b;
swap(a,b);
char c1,c2;
cout<<"\nEnter two characters :";
cin>>c1>>c2;
swap(c1,c2);
float f1,f2;
cout<<"\nEnter two real numbers :";
cin>>f1>>f2;
swap(f1,f2);
getch();
}

/*     OUTPUT
======
Enter two integers :43
52

Before swapping of integers:
A=43
B=52
After swapping of integers:
A=52
B=43

Enter two characters :m
s

Before swapping of characters:
A=m
B=s
After swapping of characters:
A=s
B=m

Enter two real numbers :3.4
7.1

Before swapping of reals:
A=3.4
B=7.1
After swapping of reals:
A=7.1
B=3.4

*/

More Programs :

A C++ Program  to make the Frequency count of letters in a given Text

17 total views, no views today


Viewing all articles
Browse latest Browse all 22

Trending Articles