Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this program, you will work with a structure representing a LEGO building set, which is defined as follows ( from LegoSet.h ) : typedef

In this program, you will work with a structure representing a LEGO building set, which is defined as follows (from LegoSet.h):
typedef struct {
char name[50]; // Name of set
unsigned num; // Set number
unsigned pieces; // Number of pieces in set
unsigned minAge; // Minimum recommended age
unsigned maxAge; // Maximum recommended age
} LegoSet;
You must complete the main function in exam3_struct_main.c as well as the three function definitions in LegoSet.c.
Your final program should recognize three commands:
age: Prompt the user to enter an age and print all sets that are appropriate for someone of that age (in other words, the age input is between the minimum and maximum age for that set, including those endpoints) using the findByAge() function described below:
void findByAge(LegoSet list[], unsigned n, unsigned a): takes in an array of LegoSet structures, list, the number of structures in the array, n, and the desired age, a. Function prints all age-appropriate sets found in list, as well as the total number of sets that were printed. For example, if I enter age 4, the output would be:
Enter age: 4
Classic Large Creative Brick Box (#10698)
790 pieces
Ages 4 and up
Disney Ariel's Celebration Boat (#43191)
114 pieces
Ages 4-10
DUPLO Town Farm Tractor & Animal Care (#10950)
27 pieces
Ages 2-5
Total sets for age 4: 3
largest: Find and print the set with the most pieces in an array of LegoSet structures using the largestSet() function described below:
unsigned largestSet(LegoSet list[], unsigned n): takes in an array of LegoSet structures, list, and the number of structures in the array, n. Function returns the index of the structure with the most pieces.
exit: Exit the program
In addition, you must write one more function:
void printSet(LegoSet* ls): Given a pointer to a LegoSet structure, print the contents of that structure to match one of the two formats below. If the maximum age in the structure is 99, the output should match this form, showing only the minimum age:
Tree House Building Kit (#21318)
3036 pieces
Ages 16 and up
Otherwise, the last line should list both the minimum and maximum ages, as shown below:
Disney Ariel's Celebration Boat (#43191)
114 pieces
Ages 4-10
Your program does not have to check for any errors--the partially written main function already handles error checking.

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

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions