Large program database linked list

profileaaditya1996
Lab7-LargePartsDatabasewLinkedLists-20200425.zip

Inventory.c

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "readline.h" struct part *inventory = NULL; /* points to first part */ /********************************************************** * print: Prints a listing of all parts in the database, * * showing the part number, part name, and * * quantity on hand. Part numbers will appear in * * ascending order. * **********************************************************/ void Print(void) { } //Same readline function for chapter 16 int ReadLine(char str[]) { } /********************************************************** * Search: Prompts the user to enter a part number, then * * looks up the part in the database. If the part * * exists, prints the name and quantity on hand; * * if not, prints an error message. * **********************************************************/ void Search(void) { } /********************************************************** * insert: Prompts the user for information about a new * * part and then inserts the part into the * * inventory list; the list remains sorted by * * part number. Prints an error message and * * returns prematurely if the part already exists * * or space could not be allocated for the part. * **********************************************************/ void Insert(void) { } /********************************************************** * Update: Prompts the user to enter a part number. * * Prints an error message if the part doesn't * * exist; otherwise, prompts the user to enter * * change in quantity on hand and Updates the * * database. * **********************************************************/ void Update(void) { } /********************************************************** * FindPart: Looks up a part number in the inventory * * list. Returns a pointer to the node * * containing the part number; if the part * * number is not found, returns NULL. * **********************************************************/ struct part *FindPart(int number) { }

Linked List Parts Database.pdf

LINKED LIST PARTS DATABASE Due Monday, April 29th at Midnight

CREATING T HE P ROJECT

Steps for starting the out Linked List project:

1. Make a new project named LinkedListPartsDatabase AND DO NOT HAVE IT

CREATE YOUR MAIN FILE FOR YOU!!!! You should have NO FILES YET

2. For our linked list, we are going to download the 3 files:

3. Save the files in the folder for your project

4. Right click on your header files folder and select “Add Existing Item”. Click on

readline.h and click “Select”

5. Next select your Source Files folder, click add existing, and add the two c files one at a

time.

R E A D L I N E . H

6. Open your h file. We will not be adding to this file. It contains all of the function

declarations and our struct.

This struct will create a node in our linked list that looks like this:

Our linked list will look like this:

L L P D M A I N . C

7. Open your main file. All you should see is the includes, some comments, and your main

function. Read over the comments so you can see what will be expected of the main

function.

a. First, we need to add the looping input and the list of codes for the user to enter.

b. We scan in the code and store it in the variable code. Add the following:

c. Second, we need a switch statement to use the user’s selection. Add the following

I N V E N TO R Y . C

8. Open your inventory file. You should see your function definitions, inventory

declaration, comments, and curly braces. Read over the comments to see what each

function is supposed to do.

a. First you need to fill in your print function. This function will iterate over our

linked list using our next pointers.

b. Next, we have the readline function we used previously in our string programs. It

reads in each line and ignores our spaces. Each item will be read and

c. Next, the search function finds a part specified by the user. The user enters the

part number and this function iterates over the list using the FindPart function and

then prints out the part name and quantity on hand.

d. Next, we have our findpart function. This function iterates over the list until it finds

the part number given by the user. Then it returns the pointer to the nodes location.

9. Next the insert function begins by prompting the user for information about a new part

and then inserts the part into the inventory list. We make sure the list remains sorted by

part number. The function will print an error message and returns prematurely if the part

already exists or space could not be allocated for the part.

Most of the insert code is similar to the insert code in the Linked List C

code we completed previously. Several changes have been added, starting with a

check to make sure 1. The database is not full, and 2. The part has not been

duplicated. If its duplicated, we make sure to free up the node we just created. We

do not need to take up more memory than necessary.

10. Next, we add our update function. The function asks the user for a part number to update,

then they are allowed to change the quantity on hand for the part selected.

ASSIGNM ENT

1. For this assignment the first part is to correctly implement the given code and have a

running project.

2. The second part of this assignment is to modify the code to allow the user to do the

following: (you need to modify the order of the list nodes for each of these. If you do

not and only “sort” when printing, you will receive no credit)

a. Sort by part number (already in the current insert)

b. Sort the parts in alphabetical order of part name instead of part number.

3. You will need to use a switch statement in the current insert and a flag to determine

which sort to use. The flag can be global if need be. (error check user input)

a. 0 – sort by part number ascending

b. 1 – sort by part number descending

4. Make sure to use the same sorting for each insert until the user changes the sort.

How to handle the user input for changing the sorting order:

1. Add an option for the user to change the sorting order in your option codes: Remember

error checking.

2. Then you need to as the user if they want to sort Ascending order or Descending order.

Allow them to cancel if they want. Remember error checking.

3. If they change it, modify your list. If they give you the same one that is currently in use,

just skip on to the next part.

4. Below is the abstract appearance of the linked list in ascending and descending order.

P SEUD OCOD E FOR CHANG E ASC/ D ESC

If user changes sorting mode to ascending

Call function sortAscending to sort the list ascending

A S C E N D I N G O R D E R

Else if the user changes the sorting mode to descending

Call function sortDescending to sort the list descending

D E S C E N D I N G O R D E R

Display operation code prompt again for the user when sorting is complete.

NOTES

 Default is sort by part number ascending

 Once a user chooses a new sort, rearrange the list to be in the correct order using code

similar to the priority queue we made in class. After the change, every insert should use

that sort method unless the user changes again.

 Look into bubble sort. We did the code for this last semester.

GRAD ING RUBRIC

Assignment Grading

Functional code – no errors present. If code does not run, then no points will be awarded. The grade of 0 will be given.

Cheating – If your code is identical to another students, both students will receive a grade of 0 for the assignment.

Grade Item Percent of Grade

Code implemented correctly as seen in the lab 45pts

Sort created correctly and used as specified in the instructions

45pts

Error checking present as specified. 10pts

Deductions Points Deducted

Naming your main c file main.c. It has to be descriptive. -10pts

Not using a switch statement. -10pts

Not modifying the functions as specified. -20pts for each function

Incorrect int/char usage -5pts for each infraction

Using global variables for anything except the ones in the given code, or a flag for user input.

-30pts per variable

Passing all addresses/variables into every function even if they are not needed in the function.

-30pts per function

1 character variable names, even in loops -5pts per variable

Uneven tabbing -31pts

Unreadable code (either through tabbing, spacing, variables names etc)

-31pts

No/few comments/copied comments -31pts

LLPDMain.c

#include <stdio.h> #include <stdlib.h> #include "readline.h" /********************************************************** * main: Prompts the user to enter an operation code, * * then calls a function to perform the requested * * action. Repeats until the user enters the * * command 'q'. Prints an error message if the user * * enters an illegal code. * **********************************************************/ int main(void) { }

readline.h

#ifndef READLINE_H #define READLINE_H #ifdef __cplusplus extern "C" { #endif #define NAME_LEN 25 struct part { int number; char name[NAME_LEN+1]; int on_hand; struct part *next; }; struct part *FindPart(int number); void Insert(void); void Search(void); void Update(void); void Print(void); int ReadLine(char str[]); #ifdef __cplusplus } #endif #endif /* READLINE_H */