Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Specification: Service requests by Tech-Support a) Define an appropriate self-referential structure that contains at least 1 numeric, 1 character and 1 string data type.

Problem Specification: Service requests by Tech-Support

a) Define an appropriate self-referential structure that contains at least 1 numeric, 1 character and 1 string data type.

b) Manage the selected data using a linked list. A data item should have a unique alpha-numeric identifier.

c) The use of the atoi()/atof() and gets() functions are strictly not allowed.

d) Achieve appropriate error checking and robustness by avoiding the use of the scanf() function. Instead, use fgets(), getchar, and strto() functions

e) Ensure to consider the user experience and use a looping technique and a case selection structure to control selection from the following menu:

1) Insert a data item in order

2) Remove a specific data item from the list

3) View a specific data item

4) Print a list of all the data items

5) Exit Application

Code :

#include #include #include

// Structure Definition struct item{ int itemId; float itemPrice; char itemName[20]; struct item *nextPtr; };

// Structure renaming typedef struct item Item; typedef struct item *ItemPtr;

/*Function Prototypes*/ void menu (); void printList (ItemPtr sPtr); ItemPtr makeItem (int id, float price, char name[20]); //ItemPtr removeItem (ItemPtr, int); ItemPtr addItem (ItemPtr sPtr, int id, float price, char name[20]); //void viewItem (ItemPtr sPtr, int value); int main () { ItemPtr startPtr; // creating list pointer startPtr = NULL; // initialising the start of the list int id, choice; float price; char name[20]; menu (); scanf ("%d", &choice); while (choice != 5) { switch (choice) { case 1: printf (" Enter ID,Price & Name of Item for Insertion: "); scanf ("%d%f%s", &id,&price,name); startPtr = addItem (startPtr, id,price,name); printList (startPtr); printf (" "); break; case 2: printf (" Enter Item for deletion : "); //scanf ("%d", &value); //startPtr = removeItem (startPtr, value); printList (startPtr); printf (" "); break; case 3: printf (" Enter Item Number to View : "); //scanf ("%d", &value); //viewItem (startPtr, value); printf (" "); break; case 4: printList (startPtr); printf (" "); break; default: printf ("Invalid Option... Please Try Again "); break; } menu (); scanf ("%d", &choice); } }// end of main

void menu () { printf ("\t1: Insert Item into Ordered List "); printf ("\t2: Remove Item from List "); printf ("\t3: View Item from List "); printf ("\t4: Printing the List "); printf ("\t5: Exit "); printf ("\tEnter Choice: "); } ItemPtr makeItem(int id, float price, char name[20]) { ItemPtr nPtr = malloc(sizeof(Item)); if(nPtr == NULL) { puts("Memory issues... node not created"); } else { nPtr->itemId = id; nPtr->itemPrice = price; strcpy(nPtr->itemName,name); nPtr->nextPtr = NULL; } return nPtr; }

void printList(ItemPtr sPtr) { ItemPtr tempPtr = sPtr; if (tempPtr == NULL) { puts("The List is Empty... nothing to print"); } else { printf("ID\tPrice\tName "); while (tempPtr != NULL) { printf("%d\t%.2f\t%s ", tempPtr->itemId, tempPtr->itemPrice, tempPtr->itemName); tempPtr = tempPtr->nextPtr; } puts(""); } }

ItemPtr addItem(ItemPtr sPtr, int id, float price, char name[20]) { ItemPtr previousPtr, currentPtr, newPtr; previousPtr = NULL; currentPtr = sPtr; newPtr = makeItem(id,price,name); while (currentPtr != NULL && id > currentPtr->itemId) { previousPtr = currentPtr; currentPtr = currentPtr->nextPtr; } if (previousPtr == NULL) // are we at the start of the list, then insert at start { newPtr->nextPtr = sPtr; sPtr = newPtr; } else // otherwise we can insert elsewhere { previousPtr->nextPtr = newPtr; newPtr->nextPtr = currentPtr; } return sPtr; }

/* ItemPtr removeItem (ItemPtr sPtr, int value) {

}

void viewItem (ItemPtr sPtr, int value) {

} */

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_2

Step: 3

blur-text-image_3

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

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions