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

Your code should define and use the following structures struct part char descri

ID: 3805867 • Letter: Y

Question

Your code should define and use the following structures struct part char descriptionC20]; int qtyPerkit; double cost PenItem; struct kit int num Parts; struct part componentsC25]; double kitCost create a program that will prompt the user for the number of kits they wil be designing for our purposes we expect this to be no more than 10, so your code should make sure the user enters a value between 1-10). prompt the user for the number of unique parts in each "kit (for our purposes we are assuming that number will be less than 25, your code should handle the case where the user enters a value not in the range 1-25.) write a function that wil prompt the user for the details about each part in a kit, populating a part struct with the details after all the data is obtained from the user write a function that will calculate the total cost of the kit write a function that wilprint the details of the kit in tabular form, including subcost for each item

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
//Structure definition for Parts
struct part
{
//Structure members
char description[20];
int qtyPerKit;
float costPerKit;
};//End of structure

//Structure definition for Kit
struct kit
{
//Structure members
int numParts;
struct part components[25];
double kitCost;
};//End of structure

//Structure array created for 10 kits
struct kit myKit[10];
int no;

//To accept data
void Accept()
{
int x, y = 0;
//Loops till valid number of kits entered between 1 - 10
do
{
//Accepts number of kits
printf(" Enter number of kits you are creating: (between 1 - 10): ");
scanf("%d", &no);
//Checks for validity
if(!(no >= 1 && no <= 10))
//If invalid display the message and asks to reenter.
printf(" Please enter a number between 1 - 10");
//If valid break
else
break;
}while(1); //End of while
//Loops till number of kits
for(x = 0; x < no; x++)
{
printf(" Working on kit %d", (x + 1));
fflush(stdin);
printf(" How many parts in the kit? ");
scanf("%d", &myKit[x].numParts);
//Loops till number of parts
for(y = 0; y < myKit[x].numParts; y++)
{
printf(" Enter the description of the part (< 20 character, no space): ");
scanf("%s", myKit[x].components[y].description);
printf(" Enter number of %s's in the kit: ", myKit[x].components[y].description);
scanf("%d", &myKit[x].components[y].qtyPerKit);
printf(" Enter the cost of each %s:", myKit[x].components[y].description);
scanf("%f", &myKit[x].components[y].costPerKit);
}//End of inner for loop
}//End of outer for loop
}//End of function

//To display data
void Display()
{
int x, y;
float subTotal, total = 0;
printf(" Description Qty Cost Subtotal ");
//Loops till number of kits
for(x = 0; x < no; x++)
{
//Loops till number of parts
for(y = 0; y < myKit[x].numParts; y++)
{
//Calculates sub total
subTotal = myKit[x].components[y].qtyPerKit * myKit[x].components[y].costPerKit;
//Calculates grand total
total += subTotal;
printf(" %s %d %.2f %.2f", myKit[x].components[y].description, myKit[x].components[y].qtyPerKit, myKit[x].components[y].costPerKit, subTotal);
}//End of inner for loop
}//End of for loop
printf(" Total cost for kit is %f: ", total);
}//End of function

//Main function
int main()
{
//Calls accept function to accept data
Accept();
//Calls display function to display data
Display();
}//End of main

Output:


Enter number of kits you are creating: (between 1 - 10): 2

Working on kit 1
How many parts in the kit? 2

Enter the description of the part (< 20 character, no space): Ram

Enter number of Ram's in the kit: 2

Enter the cost of each Ram:10.00

Enter the description of the part (< 20 character, no space): Rom

Enter number of Rom's in the kit: 20

Enter the cost of each Rom:30.00

Working on kit 2
How many parts in the kit? 1

Enter the description of the part (< 20 character, no space): Chip

Enter number of Chip's in the kit: 60

Enter the cost of each Chip:10.00

Description Qty Cost Subtotal

Ram 2 10.00 20.00
Rom 20 30.00 600.00
Chip 60 10.00 600.00

Total cost for kit is 1220.000000:

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