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

Define a structure (struct) named Product that contains the following members: A

ID: 3694090 • Letter: D

Question

Define a structure (struct) named Product that contains the following members: Ac-string for product name An integer for product code. A float for product cost. Create a dynamic array of Product that can be resized on demand. The initial size of the array (SIZE) is determined by the user input. Fill in the array with SIZE number of products. The program allows the user to append additional n(input) products to the array. Show the content of the array and the average cost before and after appending products. Note, you need to define the following functions to perform input, output and finding average cost. InputProduct: The function inputs the name, code, and the cost of each product in the array you create. Output Product: The function outputs the name, code, and the cost of each product in the array you create. AverageCost: The function finds the average cost of the products stored in the array you create. The following is a sample run:

Explanation / Answer

#include <stdio.h> // header function
struct product // struct product
{
char name[50]; // name
int code;
int cost;
};

int main()
{
int n,i,avg=0; // required variables for the operations
float result;
printf("Enter n input number of values: ");
scanf("%d",&n); // reading n number of inputs from user
struct product pd[n]; // creating struct array
for(i=0;i<n;i++) // loop for getting input from user
{
printf("Enter product name: ");
scanf("%s",&pd[i].name); // reading data from user
printf("Enter product code: ");
scanf("%d",&pd[i].code);
printf("Enter product cost: ");
scanf("%d",&pd[i].cost);
}
printf("The list of products and their details are: "); // printing the stored values
for(i=0;i<n;i++)
{
printf("product name: %s ",pd[i].name);
printf("product code: %d ",pd[i].code);
printf("product cost: %d ",pd[i].cost);
}
printf("printing average cost of products: "); // printing the vaerage cost of products
for(i=0;i<n;i++) // loop to calculate the toatal costs
{
avg=avg+pd[i].cost; // to sum total costs
}
result=avg/n; // average formula
printf("The average is: %f ",result); // printing average

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