Create a class distance to store the distance in feet and inches. Overloaded+ add -operation to add and subtract two distances.
Answers
Answer:
Explanation:
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
#include <stdio.h>
struct Distance{
int feet;
float inch;
}d1,d2,sum;
int main(){
printf("Enter information for 1st distance\n");
printf("Enter feet: ");
scanf("%d",&d1.feet);
printf("Enter inch: ");
scanf("%f",&d1.inch);
printf("\nEnter infromation for 2nd distance\n");
printf("Enter feet: ");
scanf("%d",&d2.feet);
printf("Enter inch: ");
scanf("%f",&d2.inch);
sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;
/* If inch is greater than 12, converting it to feet. */
if (sum.inch>12.0)
{
sum.inch=sum.inch-12.0;
++sum.feet;
}
printf("\nSum of distances=%d\'-%.1f\"",sum.feet,sum.inch);
return 0;