Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- #include<fstream>
- #include<Windows.h>
- #include<conio.h>
- #include<stdlib.h>
- using namespace std;
- #include "Header.h"
- void login();
- void menuscreen();
- int target2;
- void main()
- {
- login();
- menuscreen();
- cout << " ";
- }
- void menuscreen()
- {
- Shop mylist;
- string target, brand, modelname, size, quantity;
- int location, choice, bil, target1;
- char backOption, choice1;
- ifstream infile;
- infile.open("info.txt");
- while (infile >> bil >> brand >> modelname >> size >> quantity)
- {
- if (mylist.NumberOfItem() == 0)
- mylist.AddToFrontInput(bil, brand, modelname, size, quantity);
- else
- mylist.AddToMiddleInput(bil, brand, modelname, size, quantity);
- }
- infile.close();
- cout << "========================\n\n";
- cout << " *******" << "MENU" << "*******" << endl << endl;
- cout << "========================\n1. ADD ITEM\n2. DELETE ITEM\n3. DISPLAY RECORD\n4. SORT BY BRAND\n5. SEARCH BY MODEL\n6. EXIT\n========================\n\n";
- cout << endl;
- do
- {
- cout << "User option >> ";
- cin >> choice;
- cin.ignore();
- switch (choice)
- {
- case 1:
- system("cls");
- cout << " \t \t \t__________________________ \n\n ";
- cout << " \t \t \t\t ADD ITEM \n \n ";
- cout << " \t \t \t__________________________ \n\n ";
- if (mylist.NumberOfItem() == 0)
- {
- mylist.AddToFront();
- cout << "\nContinue Add Item? (Y\\N) : ";
- cin >> choice1;
- cin.ignore();
- if (choice1 == 'Y' || choice1 == 'y')
- {
- do
- {
- mylist.AddToMiddle();
- cout << "\nContinue Add Item? (Y\\N) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y' || choice1 == 'y');
- }
- }
- else
- if (mylist.Traverse() == true)
- {
- do
- {
- mylist.AddToMiddle();
- cout << "\nContinue Add Item? (Y\\N) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y' || choice1 == 'y');
- }
- cout << "\nSUCCESSFULLY ADDED!\n";
- system("pause");
- system("cls");
- menuscreen();
- break;
- case 2:
- do
- {
- system("cls");
- cout << "-----DELETE ITEM-----\n\n";
- cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- cout << left << setw(8) << " No. " << left << setw(20) << " Brand " << left << setw(20) << "Model Name " << left << setw(20) << " Size " << left << setw(20) << " Quantity " << endl;
- cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- mylist.displayData();
- cout << "\nNo. : ";
- cin >> target1;
- if (mylist.searchDelete(target1, location) == true)
- {
- if (location == 0)
- {
- mylist.DeleteFront();
- }
- else
- {
- mylist.DeleteMiddle();
- }
- cout << "\nITEM DELETED!\n";
- }
- cout << "\nContinue Delete Item? (Y\\N) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y' || choice1 == 'y');
- system("pause");
- system("cls");
- menuscreen();
- break;
- case 3:
- system("cls");
- cout << "-----DISPLAY BY NAME-----\n\n";
- cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- cout << left << setw(8) << " No. " << left << setw(20) << " Brand " << left << setw(20) << "Model Name " << left << setw(20) << " Size " << left << setw(20) << " Quantity " << endl;
- cout << left << setw(8) << "-----" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- mylist.displayData();
- cout << endl << "Total : " << mylist.NumberOfItem() << endl;
- system("pause");
- system("cls");
- menuscreen();
- break;
- case 4:
- do
- {
- system("cls");
- cout << "-----SORT BY BRAND-----\n\n";
- cout << "ENTER BRAND : ";
- getline(cin, target);
- mylist.sortQuantity(target);
- cout << "Continue Sort By Brand? (Y\\N) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y' || choice1 == 'y');
- system("cls");
- menuscreen();
- break;
- case 5:
- system("cls");
- cout << "-----SEARCH BY MODEL-----" << "\n\nModel Name : ";
- getline(cin, target);
- cout << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- cout << left << setw(20) << " Brand " << left << setw(20) << "Model Name" << left << setw(20) << " Size " << left << setw(20) << " Quantity " << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- if (mylist.searchModel(target, location) == true)
- {
- mylist.printSearch(location);
- }
- else
- {
- cout << "Item is not found\n";
- cout << endl;
- }
- system("pause");
- system("cls");
- menuscreen();
- break;
- case 6:
- mylist.displayOutput();
- cout << "\n====EXITING PROGRAMME====\n";
- exit(EXIT_FAILURE);
- break;
- default:
- cout << "Invalid input,please re-enter!!!\n\n";
- break;
- }
- } while (choice < 1 || choice>6);
- }
- void login()
- {
- string username;
- string password;
- username = "ADMIN";
- char ch;
- string input;
- karate:
- system("cls");
- cout << "\n\t\t\t\t\t=====DOVER KICKS MALAYSIA=====\n\n";
- cout << "\n\t\t\t\t\t=====ADMINISTRATOR LOGIN=====\n\n";
- cout << "\n\t\t\t\t\t=====Enter 00 to Exit=====\n\n";
- cout << "\n\n\n\tUSERNAME >> ";
- cin >> input;
- if (input == username)
- {
- cout << "\n";
- cout << "\tPASSWORD >> ";
- ch = _getch();
- while (ch != 13)
- {
- password.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- if (password == "1234")
- {
- cout << "\n\n\n\t\t\t\t\t ACCESS GRANTED !!!\n ";
- for (int i = 0; i < 6; i++)
- {
- cout << " ";
- Sleep(250);
- }
- Sleep(500);
- system("cls");
- return;
- }
- else
- cout << "\n\n\t\tACCESS DENIED !!! INVALID PASSWORD !!! \n\n";
- system("pause");
- goto karate;
- }
- else if (input == "00")
- {
- exit(EXIT_FAILURE);
- }
- else if (input != username)
- {
- cout << "\n\n\t\tACCESS DENIED !!! INVALID PASSWORD !!! \n\n";
- }
- system("pause");
- goto karate;
- }
- -------------------------------------------------------------------------------------------------------------
- #ifndef HEADER_H
- #define HEADER_H
- #include<fstream>
- const int sizez = 10;
- ifstream infile;
- ofstream outfile;
- class Shop
- {
- private:
- struct Shoe
- {
- int bil;
- string brand;
- string modelname;
- string size;
- string quantity;
- };
- class Node
- {
- public:
- Shoe ShoeData;
- Node*link;
- };
- Node*pHead;
- Node*pCurr;
- Node*pPrev;
- Node*pTail;
- int numItem;
- public:
- Shop();
- ~Shop();
- void AddToFront();
- void AddToMiddle();
- void DeleteFront();
- void DeleteMiddle();
- int NumberOfItem();
- bool searchDelete(int, int &);
- bool searchModel(string, int &);
- void sortQuantity(string target);
- void printSearch(int target);
- void displayData();
- bool Traverse();
- void displayOutput();
- void AddToFrontInput(int, string, string, string, string);
- void AddToMiddleInput(int, string, string, string, string);
- int array[sizez];
- void bubblesort(string, int);
- bool Traverse(string target, int &loc);
- };
- #endif
- Shop::Shop()
- {
- numItem = 0;
- pHead = 0;
- }
- Shop::~Shop() {}
- void Shop::AddToFront()
- {
- string item1, item2, item3, item4;
- int item5;
- Node*pNew = new Node;
- cout << "\nEnter Brand : ";
- fflush(stdin);
- getline(cin, item1);
- cout << "Enter Model Name : ";
- getline(cin, item2);
- cout << "Enter Size : ";
- getline(cin, item3);
- cout << "Enter Quantity : ";
- getline(cin, item4);
- numItem++;
- item5 = numItem;
- pNew->ShoeData.brand = item1;
- pNew->ShoeData.modelname = item2;
- pNew->ShoeData.size = item3;
- pNew->ShoeData.quantity = item4;
- pNew->ShoeData.bil = item5;
- pNew->link = pHead;
- pHead = pNew;
- }
- void Shop::AddToMiddle()
- {
- string item1, item2, item3, item4;
- int item5;
- Node*pNew = new Node;
- cout << "\nEnter Brand : ";
- getline(cin, item1);
- cout << "Enter Model Name : ";
- getline(cin, item2);
- cout << "Enter Size : ";
- getline(cin, item3);
- cout << "Enter Quantity : ";
- getline(cin, item4);
- if (numItem == 1)
- pCurr = pHead;
- numItem++;
- item5 = numItem;
- pNew->ShoeData.brand = item1;
- pNew->ShoeData.modelname = item2;
- pNew->ShoeData.size = item3;
- pNew->ShoeData.quantity = item4;
- pNew->ShoeData.bil = item5;
- pNew->link = pCurr->link;
- pCurr->link = pNew;
- pCurr = pNew;
- }
- void Shop::DeleteFront()
- {
- pHead = pHead->link;
- pCurr = pHead;
- numItem--;
- for (int i = 1; i <= numItem; i++)
- {
- pCurr->ShoeData.bil = i;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- }
- void Shop::DeleteMiddle()
- {
- pPrev->link = pCurr->link;
- numItem--;
- pCurr = pHead;
- for (int i = 1; i <= numItem; i++)
- {
- pCurr->ShoeData.bil = i;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- }
- int Shop::NumberOfItem()
- {
- return numItem;
- }
- bool Shop::searchDelete(int target1, int &loc)
- {
- if (numItem == 0)
- cout << "NO ITEM" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->ShoeData.bil != target1 && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->ShoeData.bil == target1)
- return true;
- else
- return false;
- }
- }
- bool Shop::Traverse(string target, int &loc)
- {
- if (numItem == 0)
- cout << "There is no item in the list" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->ShoeData.modelname != target&&pCurr->link != 0)
- {
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->ShoeData.modelname == target)
- return true;
- else
- return false;
- }
- }
- bool Shop::searchModel(string target, int &loc)
- {
- if (numItem == 0)
- cout << "NO ITEM" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->ShoeData.modelname != target && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->ShoeData.modelname == target)
- return true;
- else
- return false;
- }
- }
- void Shop::sortQuantity(string target)
- {
- int total = 0;
- cout << endl;
- pCurr = pHead;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- cout << left << setw(20) << " Brand " << left << setw(20) << "Model Name " << left << setw(20) << " Size " << left << setw(20) << " Quantity " << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- for (int i = 0; i < numItem; i++)
- {
- if (pCurr->ShoeData.brand == target)
- {
- cout << endl;
- cout << left << setw(20) << pCurr->ShoeData.brand;
- cout << left << setw(20) << pCurr->ShoeData.modelname;
- cout << left << setw(20) << pCurr->ShoeData.size;
- cout << left << setw(20) << pCurr->ShoeData.quantity;
- total++;
- }
- else;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- cout << "\n\nTotal : " << total << endl << endl;
- }
- void Shop::printSearch(int target)
- {
- pCurr = pHead;
- int loc = 0;
- while (loc != target && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- cout << left << setw(20) << pCurr->ShoeData.brand;
- cout << left << setw(20) << pCurr->ShoeData.modelname;
- cout << left << setw(20) << pCurr->ShoeData.size;
- cout << left << setw(20) << pCurr->ShoeData.quantity;
- }
- void Shop::displayData()
- {
- pCurr = pHead;
- while (pCurr != 0)
- {
- cout << " " << pCurr->ShoeData.bil << " ";
- cout << left << setw(20) << pCurr->ShoeData.brand;
- cout << left << setw(20) << pCurr->ShoeData.modelname;
- cout << left << setw(20) << pCurr->ShoeData.size;
- cout << left << setw(20) << pCurr->ShoeData.quantity;
- pCurr = pCurr->link;
- cout << endl;
- }
- }
- bool Shop::Traverse()
- {
- pCurr = pHead;
- while (pCurr->link != NULL)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- if (pCurr->link == NULL)
- return true;
- else
- return false;
- }
- void Shop::displayOutput()
- {
- outfile.open("info.txt");
- pCurr = pHead;
- while (pCurr != 0)
- {
- outfile << " " << pCurr->ShoeData.bil << " ";
- outfile << left << setw(20) << pCurr->ShoeData.brand;
- outfile << left << setw(20) << pCurr->ShoeData.modelname;
- outfile << left << setw(20) << pCurr->ShoeData.size;
- outfile << left << setw(20) << pCurr->ShoeData.quantity;
- pCurr = pCurr->link;
- outfile << endl;
- }
- outfile.close();
- }
- void Shop::AddToFrontInput(int item5, string item1, string item2, string item3, string item4)
- {
- Node*pNew = new Node;
- numItem++;
- item5 = numItem;
- pNew->ShoeData.brand = item1;
- pNew->ShoeData.modelname = item2;
- pNew->ShoeData.size = item3;
- pNew->ShoeData.quantity = item4;
- pNew->ShoeData.bil = item5;
- pNew->link = pHead;
- pHead = pNew;
- }
- void Shop::AddToMiddleInput(int item5, string item1, string item2, string item3, string item4)
- {
- Node*pNew = new Node;
- if (numItem == 1)
- pCurr = pHead;
- numItem++;
- item5 = numItem;
- pNew->ShoeData.brand = item1;
- pNew->ShoeData.modelname = item2;
- pNew->ShoeData.size = item3;
- pNew->ShoeData.quantity = item4;
- pNew->ShoeData.bil = item5;
- pNew->link = pCurr->link;
- pCurr->link = pNew;
- pCurr = pNew;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement