Can any one tell me how will working this program?

Write your question here.

[code]
#include<iostream.h>
#include<conio.h>
class distance
{
int feet,inches;
public:
void distance_assign(int f,int i)
{
feet=f;
inches=i;
}
void display()
{
cout<<"\n Feet:"<<feet<<"\t inches:"<<inches;
}
distance operator+(distance d2)
{
distance d3;
d3.feet=feet+d2.feet;
d3.inches=(inches+d2.inches);
d3.feet+=(inches+d2.inches);
return d3;

}
};
void main()
{
clrscr();
distance dist_1,dist_2;
dist_1.distance_assign(12,11);
dist_2.distance_assign(24,1);
distance dist_3=dist_1+dist_2;
dist_1.display();
dist_2.display();
dist_3.display();
getch();
}


------------------


dist_1.distance_assign(12,11);
dist_2.distance_assign(24,1);
distance dist_3=dist_1+dist_2;



distance operator+(distance d2)
{
distance d3;
d3.feet=feet+d2.feet;
d3.inches=(inches+d2.inches);
d3.feet+=(inches+d2.inches);
return d3;
[/b]

Kindly help the the following program how will executed... Only particular area (bold) i cant understand. Can anyone tell me how will working... Please Explain........
@r 4 raja

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
// Distances.cpp : main project file.

#include<iostream>
#include<conio.h>
#include <windows.h>

using std::cout;
using std::endl;

class distance
{
 int feet,inches;
public:
 void distance_assign(int f,int i)
 {
	feet=f;
	inches=i;
 }

 void display()
 {
	cout<<"\n Feet:"<<feet<<"\t inches:"<<inches;
 }

 distance operator+(distance d2)
 {
	distance d3;
       d3.feet=feet+d2.feet;
       d3.inches=(inches+d2.inches);
	//d3.feet+=(inches+d2.inches); // Adding twice. Removed
	do
	{
	 d3.inches -=12;
	 d3.feet++;
	}while (d3.inches > 11);// If inches  >= 12, add 1 to feet and subtract 12 inches
	return d3;
 }
};

void clrscr()
{
 DWORD n;
 DWORD size;
 COORD coord = {0};
 CONSOLE_SCREEN_BUFFER_INFO csbi;
 HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
 GetConsoleScreenBufferInfo ( h, &csbi );
 size = csbi.dwSize.X * csbi.dwSize.Y;
 FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
 GetConsoleScreenBufferInfo ( h, &csbi );
 FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
 SetConsoleCursorPosition ( h, coord );
}

void main()
{
 clrscr();
 distance dist_1, dist_2;
 dist_1.distance_assign(12,11);
 dist_2.distance_assign(24,11);
 distance dist_3=dist_1+dist_2;
 dist_1.display();
 dist_2.display();
 cout << endl << "---------------------------"; // add an underscore before showing totals
 dist_3.display();
 getch();
}
Topic archived. No new replies allowed.