//27-11-2014
//Ahmad Furqan Attari
//p5.9
#include <iostream>
#include <conio.h>
using namespace std;
struct time
{
int hours;
int mins;
int secs;
};
void swap(time& a, time& b)
{
int temp;
temp = a.hours;
a.hours = b.hours;
b.hours = temp;
temp = a.mins;
a.mins = b.mins;
b.mins = temp;
temp = a.secs;
a.secs = b.secs;
b.secs = temp;
}
void main(void)
{
time t1 = { 5, 42, 34 }, t2 = {6,26,56};
cout << "Befor swap" << endl;
cout<<"t1 = " << t1.hours << " hours " << t1.mins << " minutes " << t1.secs << " sec " << endl;
cout << "t2 = " << t2.hours << " hours " << t2.mins << " minutes " << t2.secs << " sec " << endl;
swap(t1,t2);
cout << "After swap" << endl;
cout << "t1 = " << t1.hours << " hours " << t1.mins << " minutes " << t1.secs << " sec " << endl;
cout << "t2 = " << t2.hours << " hours " << t2.mins << " minutes " << t2.secs << " sec " << endl;
_getch();
}
//Ahmad Furqan Attari
//p5.9
#include <iostream>
#include <conio.h>
using namespace std;
struct time
{
int hours;
int mins;
int secs;
};
void swap(time& a, time& b)
{
int temp;
temp = a.hours;
a.hours = b.hours;
b.hours = temp;
temp = a.mins;
a.mins = b.mins;
b.mins = temp;
temp = a.secs;
a.secs = b.secs;
b.secs = temp;
}
void main(void)
{
time t1 = { 5, 42, 34 }, t2 = {6,26,56};
cout << "Befor swap" << endl;
cout<<"t1 = " << t1.hours << " hours " << t1.mins << " minutes " << t1.secs << " sec " << endl;
cout << "t2 = " << t2.hours << " hours " << t2.mins << " minutes " << t2.secs << " sec " << endl;
swap(t1,t2);
cout << "After swap" << endl;
cout << "t1 = " << t1.hours << " hours " << t1.mins << " minutes " << t1.secs << " sec " << endl;
cout << "t2 = " << t2.hours << " hours " << t2.mins << " minutes " << t2.secs << " sec " << endl;
_getch();
}
No comments:
Post a Comment