Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Turn the following code into one that has a main with less than 10 lines and the rest as call functions. Add notes to explain

Turn the following code into one that has a main with less than 10 lines and the rest as call functions.

Add notes to explain what is happening in the code.

/*

* C program to display the inventory of items in a store / shop

* The inventory maintains details such as name, price, quantity

* and manufacturing date of each item.

*/

#include

void main()

{

struct date

{

int day;

int month;

int year;

};

struct details

{

char name[20];

int price;

int code;

int qty;

struct date mfg;

};

struct details item[50];

int n, i;

printf("Enter number of items:");

scanf("%d", &n);

fflush(stdin);

for (i = 0; i < n; i++)

{

fflush(stdin);

printf("Item name: ");

scanf("%s", item[i].name);

fflush(stdin);

printf("Item code: ");

scanf("%d", &item[i].code);

fflush(stdin);

printf("Quantity: ");

scanf("%d", &item[i].qty);

fflush(stdin);

printf("price: ");

scanf("%d", &item[i].price);

fflush(stdin);

printf("Manufacturing date(dd-mm-yyyy): ");

scanf("%d-%d-%d", &item[i].mfg.day,

&item[i].mfg.month, &item[i].mfg.year);

}

printf(" ***** WELCOME ***** ");

printf("---------------------------------------------------------

--------- ");

printf("S.N.| NAME | CODE | QUANTITY | PRICE

| MFG.DATE ");

printf("---------------------------------------------------------

--------- ");

for (i = 0; i < n; i++)

printf("%d %-15s %-d %-5d %-5d

%d/%d/%d ", i + 1, item[i].name, item[i].code, item[i].qty,

item[i].price, item[i].mfg.day, item[i].mfg.month,

item[i].mfg.year);

printf("---------------------------------------------------------

--------- ");

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago