/* Author: Susan Mitchell */ /* File : Project1.c */ #include #include "Inventory.h" Cd* getCd(); void main() { char artist[MAXSIZE_ARTIST]; char title[MAXSIZE_TITLE]; int i, count; Cd* aCd; CdNode* aNode; /* Initialize the list and print it */ printf("*** Initializing list\n"); initializeList(); printf("\n\n"); printList(); /* Read the cd information and place into list from the most recent */ /* to earliest received, then print the list */ printf ("\n\n*** Creating original list\n"); scanf("%d", &count); for (i = 1; i <= count; i++) { aCd = getCd(); insertNode(aCd); } printf("\n\n"); printList(); /* Search for a given cd based on its artist and title, then print */ /* the cd information */ printf("\n\n*** Searching for a cd\n"); scanf("%*c"); printf("\n\nEnter artist (%d characters maximum):\n", MAXSIZE_ARTIST); gets(artist); printf("Enter title (%d characters maximum):\n", MAXSIZE_TITLE); gets(title); aNode = findNode(artist, title); if (aNode == NULL) printf("Cd not in inventory\n"); else { printf("Cd found:\n\n"); printCd(aNode->info); } /* Compute and display number of nodes in list and total inventory */ /* value */ printf("\n\n*** Computing number of nodes and inventory value\n"); computeNumNodes(); computeValue(); printf("\nNumber of nodes = %d\n", computeNumNodes()); printf("Inventory value = $%1.2f\n", computeValue()); /* Print all cds for which the number left in stock is zero */ printf("\n\n*** Printing out-of-stock cds\n"); printOutOfStock(); /* Delete all cds for which the number left in stock is zero and */ /* print the list */ printf("\n\n*** Deleting out-of-stock cds\n"); deleteOutOfStock(); printf("\n\n"); printList(); /* Empty the list and print it to be sure it is empty */ printf("\n\n*** Emptying the list\n"); emptyList(); printf("\n\n"); printList(); printf ("\n\n*** End of Program ***\n"); } /* This functions gets the information for a cd from standard input */ /* and returns a pointer to a cd structure intialized with the values */ /* entered. */ Cd* getCd() { char artist[MAXSIZE_ARTIST + 1]; char title[MAXSIZE_TITLE + 1]; int month; int day; int year; int numInStock; float price; scanf("%*c"); printf("\n\nEnter artist (%d characters maximum):\n", MAXSIZE_ARTIST); gets(artist); printf("Enter title (%d chars. max.):\n", MAXSIZE_TITLE); gets(title); printf("Enter date received (mm dd yyyy):\n"); scanf("%d%d%d", &month, &day, &year); printf("Enter number in stock:\n"); scanf("%d", &numInStock); printf("Enter price:\n"); scanf("%f", &price); return (createCd(artist, title, month, day, year, numInStock, price)); }