Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Define a structure Apple with fields for color and size. Notice that the colo

ID: 3622298 • Letter: A

Question

a. Define a structure Apple with fields for color and size. Notice that the color is a string and the size is a double type value
b. Write a function inputApple, which takes a pointer to the structure type Apple, prompts the user for the color and size, and sets the fields.
c. Write a function compareApples, which takes two variables of structure type Apple and returns 1 if the two apples are identical and 0 otherwise.
d. Write a main function
i. Use two variables of structure type Apple myApple and yourApple
ii. Use the function inputApple two times to set the fields for each apple.
iii. Compare the two apples and print the corresponding messages on the screen.

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct apple{
char color[20];
double size;
};
void inputapple(struct apple * );
int compareApples(struct apple ,struct apple );
int main()
{
struct apple myApple,yourApple;
struct apple *my,*you;
my = &myApple;
you = &yourApple;
inputapple(my);
inputapple(you);
if(compareApples(myApple,yourApple))
printf("both apples are same ");
else
printf("both apples are not same. ");
getch();
return 0;
}
void inputapple(struct apple *r)
{
char colour[20];
double p;
printf("enter the color of apple :");
scanf("%s",colour);
strcpy(r->color,colour);
printf("Enter size of Apple :");
scanf("%lf",&p);
r->size=p;
}
int compareApples(struct apple p,struct apple q)
{
if(!strcmp(p.color,q.color))
if(p.size==q.size)
return 1;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote