Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <cstring>
- #include <cstdlib>
- #include <fstream>
- #include <cstdio>
- #include <cctype>
- using namespace std;
- struct listing
- {
- int itemno,quantity;
- char brand[50], stationery[50];
- };
- struct initialise
- {
- int init, itemsize, brandsize;
- };
- int initialisef();
- int menuf();
- void listreadf();
- int searchid();
- int main()
- {
- int menuloop=1, arraysize, menu, idcheck, addsize;
- char keyw[50];
- struct listing output, display;
- while (menuloop == 1)
- {
- ifstream item_num("item number.txt");
- ifstream stationery("stationery.txt");
- ifstream brand("brand.txt");
- ifstream quantity("quantity.txt");
- arraysize = initialisef();
- addsize = arraysize;
- struct listing* list = NULL;
- list = new listing[arraysize];
- for (int i = 0; i < arraysize; i++)
- {
- list[i].itemno = 0;
- strcpy(list[i].brand,"");
- strcpy(list[i].stationery,"");
- list[i].quantity = 0;
- }
- while (item_num)
- {
- for (int i = 0; i < arraysize; i++)
- {
- item_num >> list[i].itemno;
- }
- }
- while (stationery)
- {
- for (int i = 0; i <= arraysize; i++)
- {
- stationery.getline(list[i].stationery,50);
- }
- }
- while (brand)
- {
- for (int i = 0; i <= arraysize; i++)
- {
- brand.getline(list[i].brand,50);
- }
- }
- while (quantity)
- {
- for (int i = 0; i < arraysize; i++)
- {
- quantity >> list[i].quantity;
- }
- }
- menu = menuf();
- switch (menu)
- {
- case 1: // list
- system("CLS");
- cout << "Item number\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
- for (int i = 0; i < arraysize; i++)
- {
- cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << "\t" << setw(6) << list[i].quantity << endl;
- }
- system("PAUSE");
- break;
- case 2: // search by item number
- idcheck = searchid();
- for (int i = 0; i < arraysize; i++)
- {
- if (list[i].itemno == idcheck)
- {
- display = list[i];
- system("CLS");
- cout << "Item number";
- cout << "\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
- cout << setw(7) << display.itemno << "\t\t" << setw(9) << display.stationery << "\t" << setw(9) << display.brand << "\t" << setw(6) << display.quantity << endl;
- system("PAUSE");
- }
- }
- break;
- case 3: // search by keyword
- cout << "Enter search keyword: ";
- cin >> keyw;
- for (int i = 0; i < arraysize; i++)
- {
- cout << keyw;
- if (strncmp(list[i].brand,"pen",50) == 0 || strncmp(list[i].stationery,"pen",50) == 0)
- {
- system("CLS");
- cout << "Item number";
- cout << "\tStationery";
- cout << "\t" << setw(9) <<"Brand" << endl;
- cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << endl;
- system("PAUSE");
- }
- else
- {
- cout << list[i].brand;
- system("PAUSE");
- }
- }
- break;
- case 4: // low inventory
- system("CLS");
- cout << "Item number" << "\tStationery" << "\t" << setw(9) <<"Brand" << "\t" << setw(9) << "Quantity" << endl;
- for (int i = 0; i < arraysize; i++)
- {
- if ( list[i].quantity < 10)
- {
- cout << setw(7) << list[i].itemno << "\t\t" << setw(9) << list[i].stationery << "\t" << setw(9) << list[i].brand << "\t" << setw(6) << list[i].quantity << endl;
- }
- }
- system("PAUSE");
- break;
- case 5: // update
- break;
- case 6: // add
- cout << "Enter";
- break;
- case 7: // delete
- break;
- case 8: //exit
- menuloop = 0;
- break;
- default:
- menuloop = 1;
- break;
- }
- delete[] list;
- }
- return 0;
- }
- int initialisef()
- {
- int out;
- ifstream initialise("initialise.txt");
- // checking
- if (!initialise)
- {
- cout << "Error opening the file.\n";
- }
- else
- {
- initialise >> out;
- }
- initialise.close();
- return out;
- }
- int menuf()
- {
- int input;
- system("CLS");
- cout << "1. List.\n";
- cout << "2. Search by item number.\n";
- cout << "3. Search by keyword. WIP\n";
- cout << "4. Show low inventories.\n";
- cout << "5. Update. WIP\n";
- cout << "6. Add. WIP\n";
- cout << "7. Delete. WIP\n";
- cout << "8. Exit.\n";
- cin >> input;
- return input;
- }
- void listread()
- {
- int listno;
- system("CLS");
- ifstream listfile( "item number.txt" );
- if (!listfile)
- {
- cout << "Error opening file.\n";
- exit(100);
- }
- else
- {
- cout << "Item number" << "\t\tStationery\n";
- listfile >> listno;
- while (listfile)
- {
- cout << setw(5) << listno << endl;
- listfile >> listno;
- }
- listfile.close();
- }
- }
- int searchid()
- {
- int id;
- system("CLS");
- cout << "\n\n\t\t\t Item number search";
- cout << "\n\n\n\tEnter item number to search: ";
- cin >> id;
- return id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement