About

Project specifications

Group: Kai Hirota & Alvin Choi

Process

Specify the problem requirements.

  • Accept, store, retrieve, and print different types of user-input data (words/numbers)

  • Store many values/data that are similar (e.g. store all the names together) together in the same container (array/struct/pointer)

  • Link different types of data together

Analyze the problem.

  • Storage of array of strings (name of grocery items & units), or array of arrays of char

  • Capable of accepting user input data, and storage/retrieval of the input data

  • Preferably, does not require the creator to predetermine memory spaces to reserve

  • Storage of array of integers (qty of each grocery item)

  • Preserves the relation between the three data input by the user per grocery item (array index) when storing the data

  • Able to print a list of all of the added grocery items by retrieving the three stored values from three different arrays, while preserving the relation between those three values

Design and implement the algorithm to solve the problem.

  • Attempt 1: Pointer arrays

    • Allows us to initialize variables/arrays without allocating predetermined memory space

    • Capable of accepting user-input data

    • However we later found out that: the array of strings that the pointer array accepted from the user was not actually stored inside the program. Due to the location of where the data was stored, the stored data became read-only, meaning that the occupied memory space cannot be freed up until the program is terminated.

  • Attempt 2: Pointers of arrays of char

    • Explanation: in c, strings, such as the names of the grocery items, are arrays of char.

    • We tried to create arrays of char, and group those arrays by using pointers

    • Failed: could not figure out how to add those arrays of chars to pointers

  • Attempt 3: Structures (struct)

    • "Arrays allow to define type of variables that can hold several data items of the same kind. Structure is another user defined data type available in C that allows to combine data items of different kinds. Structures are used to represent a record."

    • To design the program as we envisioned, we would have to store the char arrays and integers under one struct. Each struct represents one grocery item. Each containers would have to be stored under another larger container - perhaps by using pointers.

    • Failed: Structs could not be printed

  • Attempt 4: Linked lists

    • To implement linked lists, we had to attempt to combine and integrate arrays, structures, and pointers

    • Failed: too complicated. To make this work, we had to combine structs and pointers

  • Attempt 5: Multi-dimensional arrays

    • Succeeded

Test and verify the completed program.

  • Issue 1: We had a if/else statement for menu. one of the items on the menu contained a while statement, and that while statement contained another if/else statement.

    • It was not concise nor aesthetic. if it can be written in a simpler manner & fewer lines, it should be.

    • Making adjustments to the structure of the code would have been complicated, given the 3 layers of if/while/if statement

    • Solution: cleaned up the code, implemented do while statement and switch statement

  • Issue 2: in "[1]add more items, or [0]menu" entering 0 either forced us out of all loops, or caused the program to end with errors.

    • Solution: added a space into scanf

    • Before: scanf("%c", &menu);

    • After: scanf(" %c", &menu);

Final Submission / Source Code

Link to Github