Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note 1: This project may be done alone or in pairs, Pair projects will be evalua

ID: 3695596 • Letter: N

Question

Note 1: This project may be done alone or in pairs, Pair projects will be evaluated at a slightly higher standard, at about a 20 points level. For example, a submission worth 230 points submitted alone would be counted as 210 points if submitted by a pair.

Note 2: This final project has both a fixed part and an optional part. In both cases, the program must follow the 8 Program Standards given with Project 4 (all previous projects are still posted in the folder “Previous Projects”).

Note 3: The optional part is for extra credit, and is somewhat open ended. Up to 120 extra points may be earned through extra credit.

--------------------------------------

Consider the inventory management application of Project 6. A solution to this project is given at the end of this document. You can use this code or your own code as a basis for this assignment. The code at the end of this document has a separate sort command to sort the entries rather than keeping the inventory sorted. Either way is fine.

For the fixed part of this project (the 200 points) you must extend the program as follows:

The inventory is to be kept in alphabetical order.   When a new entry is to be added, you must use the “Insertion Sort” to find the appropriate location in the array.

add a command ‘d’ for delete to delete an entry corresponding to a product name typed by the user.

Add a command “u” to allow a user to update (edit) one or more of the fields in the inventory

Make the program object-oriented. This means having a separate class for the internal representation of the inventory, with methods like sort, list, or delete.

For the optional part of this project may extend the program in any of various ways. Some areas for extension are as follows:

Usability and Aesthetics: Make the output especially pleasing to see and use, or keep the inventory file in a reasonably attractive format. For example, for output one might have

Name:             Milk

Quantity:         10

Notes:             Chilled storage

Human Engineering: Provide good human engineering for the user. This means being very tolerant of user errors and making it easy to use. For example, you might give the user an option to name the inventory file, or you might check if the user tries to add another entry with the same name. You might also add a simple help command.

Reliability: Make the program especially reliable. Try to make it so that the program will not crash even under incorrect inputs. For example, handle a missing file well or prevent an array out of bounds error.

Maintainability: Make the program especially well structured and readable. As per discussed in class.

Functionality: Enhance the functionality of the program in various ways, even small ways.

For functionality, one enhancement would be to check that a find or enter command actually has a non-null string for the name. A little more work would be to check the validity of an item’s quantity. For instance, always verifying that an item’s quantity is greater than or equal to zero.

For another example, one could allow a partial match to find or delete an entry. For example, “F po” would match any entry with “pop” in the name, for example “Pop” or “Popcorn” or “Potato”. You might use the function “find” in C++ for this feature.

Final Submission: You must follow the posted file “Submission of Projects.doc” or points will be deducted. This means submitting a portfolio or dossier of sorts (a stapled or bound set of pages containing

A separate cover page (or pages) itemizing the grounds for extra credit. It is your responsibility to itemize all grounds for extra credit.

A printout of your code,

A printout from several consecutive runs, illustrating the various features of your program. For example, you must show that the file I/O works.

A printout from the list command

In the sample runs, each of the commands "e", "f", "l", “d”, “u”, and "q" should be illustrated.

A solution similar to Project 6.

#include <iostream>

#include <iomanip>

#include <fstream>

#include <string>

using namespace std;

struct Entry {

       string name, quantity, notes;

};

Entry entryList[100];

int rec_num = 0;

int num_entries;

string toUpper (string S) {

       for (int i= 0; i<S.length(); i++)

             S[i] = toupper(S[i]);

       return S;

}

void ReadFile () {

   string S, eol;

   fstream input("Inventory.txt");

   while (!input.eof() && !input.fail()){

       input >> entryList[rec_num].name

                >> entryList[rec_num].quantity;

     getline(input, eol); //reads the end-of-line marker

      getline(input, S);

       entryList[rec_num].notes = S;

       rec_num++;

   }

   cout << "Inventory read." << endl;

   num_entries = rec_num;

   input.close();

   return;

}

void StoreFile () {

   fstream F("Inventory.txt");

   rec_num = 0;

       while (rec_num < num_entries){

       F << entryList[rec_num].name   << " "

           << entryList [rec_num].quantity << " "

             << entryList [rec_num].notes << " " << endl;

       rec_num++;

   }

   cout << "Inventory stored." << endl;

   return;

}

void add_item(string name, string quantity, string notes){

       entryList [num_entries].name   = name;

       entryList [num_entries].quantity = quantity;

       entryList [num_entries].notes = notes;

       num_entries++;

    return;

}

void retrieve_item(string name){

    for (int i = 0; i < num_entries; i++){

        if (toUpper(entryList [i].name) == toUpper(name)) {

            cout << "Quantity: " << entryList [i].quantity << endl

                 << "Notes: " << entryList [i].notes << endl;

            return;

        }

    }

    cout << "Item not found" << endl;

    return;

}

void listAllItems() {

       int i = 0;

       while (i < num_entries) {

             cout << "-- " << entryList [i].name << " "

                    << entryList [i].quantity << endl

                    << "-- " << entryList [i].notes << endl << endl;

             i++;

       }

}

int main(){

    string name, quantity, notes;

    char command;

    ReadFile ();

    cout << "Use "e" for enter, "f" for find, "l" for list, "q" to quit."

         << endl << "Command: ";

    cin >> command;

    while (command != 'q'){

        switch (command){

        case 'e': cin >> name;   cout << "Enter Quantity: ";

                  cin >> quantity; cout << "Enter Notes: ";

                  cin.ignore(); getline(cin, notes);

                  add_item(name, quantity, notes);    break;

        case 'f': cin >> name; retrieve_item(name); break;

case 'l': listAllItems(); break;

        }

        cout << " Command: "; cin >> command;

    }

    StoreFile();

    cout << "All set !";

    return 0;

}

Name:             Milk

Quantity:         10

Notes:             Chilled storage

Explanation / Answer

#include <fstream>

#include <string>

using namespace std;

struct Entry {

       string name, quantity, notes;

};

Entry entryList[100];

int rec_num = 0;

int num_entries;

string toUpper (string S) {

       for (int i= 0; i<S.length(); i++)

             S[i] = toupper(S[i]);

       return S;

}

void ReadFile () {

   string S, eol;

   fstream input("Inventory.txt");

   while (!input.eof() && !input.fail()){

       input >> entryList[rec_num].name

                >> entryList[rec_num].quantity;

     getline(input, eol); //reads the end-of-line marker

      getline(input, S);

       entryList[rec_num].notes = S;

       rec_num++;

   }

   cout << "Inventory read." << endl;

   num_entries = rec_num;

   input.close();

   return;

}

void StoreFile () {

   fstream F("Inventory.txt");

   rec_num = 0;

       while (rec_num < num_entries){

       F << entryList[rec_num].name   << " "

           << entryList [rec_num].quantity << " "

             << entryList [rec_num].notes << " " << endl;

       rec_num++;

   }

   cout << "Inventory stored." << endl;

   return;

}

void add_item(string name, string quantity, string notes){

       entryList [num_entries].name   = name;

       entryList [num_entries].quantity = quantity;

       entryList [num_entries].notes = notes;

       num_entries++;

    return;

}

void retrieve_item(string name){

    for (int i = 0; i < num_entries; i++){

        if (toUpper(entryList [i].name) == toUpper(name)) {

            cout << "Quantity: " << entryList [i].quantity << endl

                 << "Notes: " << entryList [i].notes << endl;

            return;

        }

    }

    cout << "Item not found" << endl;

    return;

}

void listAllItems() {

       int i = 0;

       while (i < num_entries) {

             cout << "-- " << entryList [i].name << " "

                    << entryList [i].quantity << endl

                    << "-- " << entryList [i].notes << endl << endl;

             i++;

       }

}

int main(){

    string name, quantity, notes;

    char command;

    ReadFile ();

    cout << "Use "e" for enter, "f" for find, "l" for list, "q" to quit."

         << endl << "Command: ";

    cin >> command;

    while (command != 'q'){

        switch (command){

        case 'e': cin >> name;   cout << "Enter Quantity: ";

                  cin >> quantity; cout << "Enter Notes: ";

                  cin.ignore(); getline(cin, notes);

                  add_item(name, quantity, notes);    break;

        case 'f': cin >> name; retrieve_item(name); break;

case 'l': listAllItems(); break;

        }

        cout << " Command: "; cin >> command;

    }

    StoreFile();

    cout << "All set !";

    return 0;

}

/*

* Precondition: itemsInArray is the number of items that are

*    stored in A. These items must be in increasing order

*    (A[0] <= A[1] <= ... <= A[itemsInArray-1]).

*    The array size is at least one greater than itemsInArray.

* Postcondition: The number of items has increased by one,

*    newItem has been added to the array, and all the items

*    in the array are still in increasing order.

* Note: To complete the process of inserting an item in the

*    array, the variable that counts the number of items

*    in the array must be incremented, after calling this

*    subroutine.

*/

static void insert(int[] A, int itemsInArray, int newItem) {

     

   int loc = itemsInArray - 1; // Start at the end of the array.

  

   /* Move items bigger than newItem up one space;

      Stop when a smaller item is encountered or when the

      beginning of the array (loc == 0) is reached. */

  

   while (loc >= 0 && A[loc] > newItem) {

      A[loc + 1] = A[loc]; // Bump item from A[loc] up to loc+1.

      loc = loc - 1;        // Go on to next location.

   }

  

   A[loc + 1] = newItem; // Put newItem in last vacated space.

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote