Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program In C as follows: Create an array of integers named toy that has 4 rows and 120 columns. The program should repeatedly

Write a program In C as follows:

Create an array of integers named toy that has 4 rows and 120 columns.

The program should repeatedly display the following menu:

A or a to add a toy to the bag

V or v to calculate and display the total value of the toys

W or w to calculate and display the total weight of the toys

D or d to delete a toy from the array

M or m to calculate and display the number of small toys

N or n to calculate and display the number of medium toys

L or l to calculate and display the number of large toys

X or x to start filling a new bag

P or p to exit program

Santas bag can hold 30 large toys or 60 medium toys or 120 small toys or any combination of sizes that satisfy this requirement (ex: 29 large + 2 medium or + 4 small would be max capacity). Also, the total weight of toys cannot exceed 620 Kgs. All values are entered in centimeters and grams.

The following functions need to be created and used in the program:

Void wipe(int cat[][4], int n);

Void populate(int cat[][4], int n);

Int size(int L, int W, int H);

Int check_capacity(int cat[][4], int n, int tsize, int tweight);

Int rm_toy(int cat[][4], int n, int toynum);

Int weight(int cat[][4], int n);

Int value(int cat[][4], int n);

Int small(int cat[][4], int n);

Int medium(int cat[][4], int n);

Int large(int cat[][4], int n);

Functions:

The function wipe that will overwrite the array zeros zeros.

Populate function asks the user for the bag number and populates the first row array with the individual toy numbers as the concatenation of the bag number and the numbers from 1 to 120.(e: if bag number is 12 then the toy numbers would be 121, 122, 123, 124,, 12119, 12120)

Size function takes three parameters in cm as the length width and height of each box and return an integer as follows:

0 if any of the three dimensions is greater than 100 or less than 1

4 if any of the three dimensions is greater than 75

2 if any of the three dimensions is greater than 50

1 if any of the dimensions is greater than 0 an less than or equal 50

Check capacity function will have four parameters, one of them is the weight of the toy, one of them is the value returned by the size function and will return a 0 if the array cannot add the specific box, and 1 if it can be added.

Rm_toy deletes a toy from the array if the argument passed to the parameter toynum matches a toy number in the array. The function returns 1 if a match was found and deleted.

The weight function returns the total weight of the toys in the array.

The value function returns the total value of the toys in the array.

The small function returns the total number of small boxes.

The medium function returns the total number of medium boxes.

The Large function returns the total number of large boxes.

Menu options:

Option A: To add a toy to the bag, the user is asked for the length, width, height, and weight of the bag. The function size, check_capacity, and weight are called to determine if the box can be added. I it can be added, then the user is asked for the value in dollars(no cents) and the next available array location(column) will be populated with the size(as returned by the size function), weight, and value.

Option V: call the function value on the array and display the return value in main.

Option W: call the function weight on the array and display the return value in main.

Option D: ask the user for a toy number, use the delete function to attempt toy deletion, output a message in main stating weather deletion is successful or not.

Options M, N, and L are similar to V and W.

Option X: call function wipe and then ask the user for a bag number and pass as argument to function populate. Enter option X first every time you start the program too.

Option P: exit program.

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago