Data Structure Keyword Typedef struct Distance{ int feet; float inch; ): typedef struct Distan int feet; float inch: } distances: int main() { struct Distance d1, d2; int main() { distances d1. d2: Modify the code to use typedef when declaring a structure.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section: Chapter Questions
Problem 2PP
icon
Related questions
Question

#include <stdio.h>
#include<stdlib.h>struct Distance
{
int feet;
float inch;
} dist1, dist2, sum;int main()
{
struct Distance* distance1 = NULL;
struct Distance* distance2 = NULL;
struct Distance* distance3 = NULL;
distance1 = (struct Distance*)malloc(sizeof(struct Distance*));
distance2 = (struct Distance*)malloc(sizeof(struct Distance*));
distance3 = (struct Distance*)malloc(sizeof(struct Distance*));
printf("input feet for distance no.1:");
scanf("%d", &distance1->feet); printf("input inch for distance no.1:");
scanf("%f", &distance1->inch); printf("input feet for distance no.2:");
scanf("%d", &distance2->feet); printf("input inch for distance no.2:");
scanf("%f", &distance2->inch); printf("input feet for distance no.3:");
scanf("%d", &distance3->feet); printf("input inch for distance no.3:");
scanf("%f", &distance3->inch); printf("1st distance\n");
printf("Enter feet: ");
scanf("%d", &dist1.feet); printf("Enter inch: ");
scanf("%f", &dist1.inch);
printf("2nd distance\n"); printf("Enter feet: ");
scanf("%d", &dist2.feet); printf("Enter inch: ");
scanf("%f", &dist2.inch); // adding feet
sum.feet = dist1.feet + dist2.feet;
// adding inches
sum.inch = dist1.inch + dist2.inch; // changing to feet if inch is greater than 12
while (sum.inch >= 12)
{
++sum.feet;
sum.inch = sum.inch - 12;
} printf("Sum of distances = %d\'-%.1f\"", sum.feet, sum.inch);
return 0;
}

 

Data Structure
Keyword Typedef
struct Distance{
int feet;
float inch;
typedef struct Distance{
int feet;
float inch:
} distances;
int main() {
struct Distance d1, d2;
}
int main() {
distances d1, d2;
}
Modify the code to use typedef when declaring a structure.
Transcribed Image Text:Data Structure Keyword Typedef struct Distance{ int feet; float inch; typedef struct Distance{ int feet; float inch: } distances; int main() { struct Distance d1, d2; } int main() { distances d1, d2; } Modify the code to use typedef when declaring a structure.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr