Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************************************
- * Project Name: Array Implementation of Choco List ADT List Version 2 *
- * Programmer : Put your Name here *
- * Date Completed: June 23, 2016 *
- ***********************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 14
- /******************************************************************
- * Data Structure Definition *
- ******************************************************************/
- typedef struct {
- unsigned int prodID; /* product ID, uniquely identifies an element */
- char prodDesc[50]; /* product description*/
- float prodPrice; /* product price*/
- int prodQty; /* product count or quantity */
- }product, products[SIZE]; /* product record */
- typedef struct cell {
- product item; /* array of products */
- int prodCtr; /* number of products in the list */
- }*chocoList; /* Definition of the ADT List ver 4 */
- typedef enum {
- TRUE, FALSE
- }boolean;
- /******************************************************************
- * Function Prototypes *
- ******************************************************************/
- void initializeList(chocoList *L);
- void populateSortedList(chocoList L);
- void displayList(chocoList L, char * listName);
- void displayProduct(product X);
- int insertSorted(chocoList L, product X);
- product deleteFirstOccurence(chocoList L, float prodPrice);
- int main(void)
- {
- chocoList L; /* sorted List */
- product deleted; /* container for the deleted record */
- /*---------------------------------------------------------------------------------
- * Problem #1 :: Initialize the choco list. Display the products in the list after*
- * calling populateSortedList(). *
- * printf("\n\n\nProblem #1:: "); *
- *--------------------------------------------------------------------------------*/
- printf("\n\n\nProblem #1: penispenispenis");
- initializeList(&L);
- populateSortedList(L);
- displayList(L,"List");
- /*---------------------------------------------------------------------------------
- * Problem #2 :: Delete 1 product from the list by calling deleteFirstOccurence(). *
- * Display the returned product record by calling displayProduct(). *
- * printf("\n\n\nProblem #2:: "); *
- *--------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------
- * CHALLENGE :: Redo Problem #s 1 & 2 using either versions 3 or 4 *
- * Keep in mind the changes when converting the ADT List Versions *
- *--------------------------------------------------------------------------------*/
- getch();
- return 0;
- }
- /****************************************************************************************
- * This function initializes the list for its first use. *
- ****************************************************************************************/
- void initializeList(chocoList *L)
- {
- *L = (chocoList)malloc(sizeof(struct cell));
- }
- /****************************************************************************************
- * This function populates the list by calling insertSorted(). *
- ****************************************************************************************/
- void populateSortedList(chocoList L)
- {
- int x, result = 1;
- product data[] = { {1501, "Hersheys", 100.50, 10},
- {1502, "Hersheys Almond", 100.50, 15},
- {1503, "Hersheys Krackel", 100.50, 15},
- {1701, "Toblerone", 150.75, 20},
- {1702, "Toblerone Milk", 150.75, 40},
- {1703, "Toblerone Honey", 150.75, 10},
- {1550, "Cadbury", 200.00, 30},
- {1201, "Kitkat", 97.75, 40},
- {1450, "Ferrero", 150.50, 50},
- {1601, "Meiji", 75.50, 60},
- {1301, "Nestle", 124.50, 70},
- {1525, "Lindt", 175.50, 80},
- {1545, "Valor", 100.50, 90},
- {1455, "Tango", 49.50, 100}
- };
- for(x = 0; x < 10 && result == 1; x++){
- result = insertSorted(L, data[x]);
- }
- }
- /****************************************************************************************
- * This function display the details of all products in the list. *
- ****************************************************************************************/
- void displayList(chocoList L, char * listName)
- {
- int x;
- system("CLS"); /* clears the screen before displaying succeeding lines */
- if(L->prodCtr != 0){
- printf("\nElements of the Product List %s:", listName);
- printf("\n\n%-10s%-15s%10s%10s","ID","Description","Price","Quantity");
- printf("\n%-10s%-15s%10s%10s","--","-----------","-----","--------");
- for(x = 0 ; x < L->prodCtr; x++){
- printf("\n%-10d", L->item[x].prodID);
- printf("%-15s", L->item[x].prodDesc);
- printf("%10.2f", L->item[x].prodPrice);
- printf("%10d", L->item[x].prodQty);
- }
- }else{
- printf("\n\tChoco list is currently empty!\n");
- }
- printf("\n\n Press any key to continue . . . ");
- getch();
- }
- /****************************************************************************************
- * This function inserts a product X in an alphabetically sorted list according to its *
- * product description. It returns a value of 1 for successful insertion. Otherwise, 0. *
- * Use memcpy() in shifting the elements downward to provide space for the new product. *
- ***************************************************************************************/
- int insertSorted(chocoList L, product X)
- {
- }
- /****************************************************************************************
- * This function deletes the first occurence of a product given the prodPrice.It returns*
- * the product record ones it is found. Otherwise, it returns a dummy record containing *
- * "XXX" for string values and 0 for integer and float values. Use memcpy() in shifting *
- * the elements upward to avoid having empty indices within the array. *
- ***************************************************************************************/
- product deleteFirstOccurence(chocoList L, float prodPrice)
- {
- }
- /****************************************************************************************
- * This function display the details of 1 product. *
- ***************************************************************************************/
- void displayProduct(product X)
- {
- //system("CLS"); /* clears the screen before displaying succeeding lines */
- printf("\n\nElements of Product %d:", X.prodID);
- printf("\n\n%-10s%-15s%10s%10s","ID","Description","Price","Quantity");
- printf("\n%-10s%-15s%10s%10s","--","-----------","-----","--------");
- printf("\n%-10d", X.prodID);
- printf("%-15s", X.prodDesc);
- printf("%10.2f", X.prodPrice);
- printf("%10d", X.prodQty);
- printf("\n\n Press any key to continue . . . ");
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement