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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
trending now

Trending now

This is a popular 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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education