Question
Using the program segment and sample txt file below, write a program that contains a linked list of watercraft. The program should allow the user
Using the program segment and sample txt file below, write a program that contains a linked list of watercraft. The program should allow the user to:
1. load inventory of watercraft from file
2. add additional watercraft to front of list
3. add additional watercraft to end of list
4. number of watercraft in inventory
5. print inventory of watercraft
6. print specs of chosen watercraft
7. delete chosen watercraft
8. search watercraft by type
9. search watercraft by motor type
10. sort watercraft by price
11. total asset value in inventory
12. quit program
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The program should be divided into the following segments
1. mainDriver.c (contains main()function)
2. sll_list.h (header file for this singly linked-list program provided to you)
3. sll_list.c (implementation file for this doubly linked-list program)
4. watercraft.txt (contains watercraft for initializing your linked-list). The watercraft can be any kind of watercraft, such as pontoon, fishing, sport boat, sailboat, kayak, canoe, even ski jets (although there are no jet skis in the test file). You can add whatever types of watercraft that you want to the test file. Make sure that no fields are skipped, though.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Function prototypes:
Initializing The List:
int printMenu( ); // prints the menu to the user; returns the menu choice
list_t *newList( ); // creates a new list; initializes size, and head & tail pointers; // returns a pointer to the new list
void listInit( list_t *list, FILE *inFile ); // called from initializeFromFile(); call newWatercraft() to create and // initialize a new watercraft from the file; then add it to the end of // the list; increments the list size for each watercraft added
void initializeFromFile( list_t *list, FILE *inFile ); // calls listInit() sending the input file pointer (which is the file // specified at the command-line that was opened in the main() function)
watercraft_t *new_waterCraft( FILE *inFile ); // called by listInit() function // creates and initializes a new watercraft node from the input file pointer // sent in // returns a pointer to the watercraft that was just created
Adding Additional Watercraft:
void addToFront( list_t *list ); // creates a new watercraft from user input and then adds it to the front of the list // increments the list size
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // ssl_list.h //
#ifndef SLL_LIST_H #define SLL_LIST_H #include
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx
watercraft.txt (text file that contains content to be read into code) (can be copy and pasted):
pontoon,Crest,Carribean RS 230 SLC,1,Suzuki,115,Blue,26,134595.00,135945.00,1,200,0,250,450,450,0 fishing,Key West,239 FS,1,Mercury,250,Orange,24,86430.00,87630.00,0,0,250,200,500,250,0 sport boat,Tahoe,T16,1,Yamaha,300,Yellow,22,26895.00,27745.00,0,250,0,0,350,250,0 pontoon,Bennington,24 Slx,1,Mercury,140,Brown,24,83299.00,84049.00,1,250,0,200,0,300,0 kayak,Wilderness Systems,Tarpon 120 SOT,0,None,0,Red/Orange/Yellow,12,999.00,1149.00,0,0,0,0,0,0,150 pontoon,Suntracker,Bass Buggy 16 XL,1,Suzuki,115,Silver,22,13990.00,14990.00,1,200,0,250,300,250,0 pontoon,Crest,Classic LX 220 SLC,1,Mercury,115,Green,24,45599.00,47149.00,1,250,350,200,450,300,0 fishing,Phoenix,Bass Boat 920 Elite,2,Chevrolet,300,Orange,28,46995.00,48195.00,0,0,250,300,400,250,0 kayak,Eddyline,Rio,0,None,0,Green Apple,12,1429.00,1714.00,0,0,0,0,0,0,285 canoe,Old Town,Penobscot 164 ,0,None,0,Green,16,1299.95,1524.90,0,0,0,0,0,0,224.95 canoe,Mad River,Adventure 16,0,None,0,Red,16,899.00,1058.95,0,0,0,0,0,0,159.95 pontoon,Crest,Classic LX 200 L,1,Yamaha,150,Black,22,31816.00,33016.00,1,200,0,250,450,300,0 sport boat,Chaparral,297 Surf SSX,2,Chevrolet,300,Purple,24,220079.00,221279.00,0,250,350,0,400,200,0 fishing,Avenger,AV24,1,Yamaha,115,Gray,28,89995.00,90795.00,0,0,250,0,350,200,0 sport boat,Sea Ray,SDX 270,2,Chevrolet,300,Blue,28,185113.00,186213.00,0,200,300,0,350,250,0 fishing,Nitro,Z18 Pro,1,Suzuki,140,Black,30,35585.00,36235.00,0,0,0,0,400,250,0 pontoon,Bennington,25 Qxfb,1,Mercury,115,White,22,167000.00,168250.00,1,250,0,250,450,300,0 pontoon,Bentley,200 Cruise,1,Mercury,90,Silver,20,36995.00,37795.00,1,200,350,250,0,0,0
void addToFront ( list_t *list ); // creates a new watercraft from user input and then adds it to the front of the list // increments the list size void addToRear( list_t *list ); // creates a new watercraft from user input and then adds it to the rear of the list; should use the tail pointer // increments the list size Printing Entire List Of All Watercraft Or Specs Of Chosen Watercraft: void printList (list_t *list); // prints all the watercraft in the list void print Specs ( list_t *list ); 7/ prints a list of the watercraft (i.e.calls printList()) and asks user to choose which one to show the specs of // the specs will include the extra items and their associated costs, if applicable Deleting A Watercraft: void deleteWatercraft( list_t *list ); // prints the list of watercraft (i.e.calls printList() and lets the user choose which one to delete // then deletes the chosen watercraft from the list // decrements the list size // if list is empty, prints message that the list is empty Searching For And Printing Watercraft By Type Or Motor: int typeInInventory list_t *list, char whichOne [] ); // called by searchByType() function // search the list and return a 1 if that type is found, O if not found int motor InInventory( list_t *list, int whichone ); // called by searchByMotorType() function 1/ search the list and return a 1 if that motor type is found, 0 if not found (0 for no motor, 1 for out-board motor, and 2 for in-board) void printWatrcraftByType( list_t *list, char whichone[] ); // traverses the list for the type that matches whichone and prints all found void printWatrcraftByMotor( list_t *list, int whichone ); 1/ traverses the list for propulsion that matches whichone and returns all found void searchByType( list_t *list ); // prints choices of types for user to choose the desired one (e.g. 1 for pontoon, 2 for fishing, etc.) // uses if-else statement or switch statement to call typeInInventory() sending the list and the string for the type chosen (e.g. "pontoon" or "fishing", etc.) // if type In Inventory () returns a 1, call printWatercraftByType() void searchByMotorType( list_t *list ); // prints motor types for user to choose the desired one (e.g. 1 for no motor, 2 for out-board motor, 3 for in-board motor) // uses if-else statement or switch statement to call motorIn Inventory () sending the list and the integer for the type chosen (0, 1, or 2) // if type In Inventory () returns a 1, call printWatercraftByMotorType() Printing Watercraft By Price In Order From Lowest To Highest: void printByPrice ( list_t *list ); 7/ creates a new local list built from the existing list where each watercraft is added in order from lowest to highest // once the new list of watercraft in order of price from lowest to highest is built, then call printList() to print the sorted list Utility Function That Can Be Used In Your Other Functions: int isEmpty( list_t *list ); // returns 1 if the is empty and 0 if it is not empty Print Total Asset Value Of All Watercraft: void TAV ( list_t *list ); // prints the total asset value of all inventory (sum of total_price) void addToFront ( list_t *list ); // creates a new watercraft from user input and then adds it to the front of the list // increments the list size void addToRear( list_t *list ); // creates a new watercraft from user input and then adds it to the rear of the list; should use the tail pointer // increments the list size Printing Entire List Of All Watercraft Or Specs Of Chosen Watercraft: void printList (list_t *list); // prints all the watercraft in the list void print Specs ( list_t *list ); 7/ prints a list of the watercraft (i.e.calls printList()) and asks user to choose which one to show the specs of // the specs will include the extra items and their associated costs, if applicable Deleting A Watercraft: void deleteWatercraft( list_t *list ); // prints the list of watercraft (i.e.calls printList() and lets the user choose which one to delete // then deletes the chosen watercraft from the list // decrements the list size // if list is empty, prints message that the list is empty Searching For And Printing Watercraft By Type Or Motor: int typeInInventory list_t *list, char whichOne [] ); // called by searchByType() function // search the list and return a 1 if that type is found, O if not found int motor InInventory( list_t *list, int whichone ); // called by searchByMotorType() function 1/ search the list and return a 1 if that motor type is found, 0 if not found (0 for no motor, 1 for out-board motor, and 2 for in-board) void printWatrcraftByType( list_t *list, char whichone[] ); // traverses the list for the type that matches whichone and prints all found void printWatrcraftByMotor( list_t *list, int whichone ); 1/ traverses the list for propulsion that matches whichone and returns all found void searchByType( list_t *list ); // prints choices of types for user to choose the desired one (e.g. 1 for pontoon, 2 for fishing, etc.) // uses if-else statement or switch statement to call typeInInventory() sending the list and the string for the type chosen (e.g. "pontoon" or "fishing", etc.) // if type In Inventory () returns a 1, call printWatercraftByType() void searchByMotorType( list_t *list ); // prints motor types for user to choose the desired one (e.g. 1 for no motor, 2 for out-board motor, 3 for in-board motor) // uses if-else statement or switch statement to call motorIn Inventory () sending the list and the integer for the type chosen (0, 1, or 2) // if type In Inventory () returns a 1, call printWatercraftByMotorType() Printing Watercraft By Price In Order From Lowest To Highest: void printByPrice ( list_t *list ); 7/ creates a new local list built from the existing list where each watercraft is added in order from lowest to highest // once the new list of watercraft in order of price from lowest to highest is built, then call printList() to print the sorted list Utility Function That Can Be Used In Your Other Functions: int isEmpty( list_t *list ); // returns 1 if the is empty and 0 if it is not empty Print Total Asset Value Of All Watercraft: void TAV ( list_t *list ); // prints the total asset value of all inventory (sum of total_price)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started