Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SHOPPING_H
- #define SHOPPING_H
- template<class DataType>
- class Shopping
- {
- private:
- class Node
- {
- public:
- DataType data;
- Node * link;
- };
- Node *pHead;
- Node *pCurr;
- Node *pPrev;
- int numItem;
- public:
- Shopping();
- ~Shopping();
- bool Traverse(DataType, int &);
- void AddToFront();
- void AddToMiddle();
- void DeleteFront();
- void DeleteMiddle();
- void PrintData();
- int NumberOfItem();
- };
- #endif
- template<class DataType>
- Shopping<DataType>::Shopping()
- {
- numItem = 0;
- pHead = 0;
- }
- template<class DataType>
- Shopping<DataType>::~Shopping()
- {
- }
- template<class DataType>
- void Shopping<DataType>::AddToFront()
- {
- DataType item;
- Node *pNew = new Node;
- cout << "Enter data : ";
- cin >> item;
- pNew->data = item;
- pNew->link = pHead;
- pHead = pNew;
- numItem++;
- }
- template<class DataType>
- void Shopping<DataType>::AddToMiddle()
- {
- DataType item;
- Node *pNew = new Node;
- cout << "Enter data : ";
- cin >> item;
- if (numItem == 1)
- pCurr = pHead;
- pNew->data = item;
- pNew->link = pCurr->link;
- pCurr = pNew;
- numItem++;
- }
- template<class DataType>
- void Shopping<DataType>::DeleteFront()
- {
- pHead = pHead->link;
- numItem--;
- cout << "First Item Deleted" << endl;
- }
- template<class DataType>
- void Shopping<DataType>::DeleteMiddle()
- {
- pPrev->link = pCurr->link;
- numItem--;
- cout << "Item Deleted" << endl;
- }
- template<class DataType>
- void Shopping<DataType>::PrintData()
- {
- pCurr = pHead;
- while (pCurr != 0)
- {
- cout << pCurr->data << " ";
- pCurr = pCurr->link;
- }
- cout << "\n";
- }
- template<class DataType>
- int Shopping<DataType>::NumberOfItem()
- {
- return numItem;
- }
- template <class DataType>
- bool Shopping<DataType>::Traverse(DataType target, int &loc)
- {
- if (numItem == 0)
- cout << "There is no item in the list" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->data != target && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->data == target)
- return true;
- else
- return false;
- }
- }
- -------------------------------------------------------------------------------
- .cpp
- #include <iostream>
- #include<string>
- #include<iomanip>
- #include<Windows.h>
- #include<conio.h>
- #include<stdlib.h>
- using namespace std;
- #include "shopping.h"
- void menuscreen();
- int login();
- void main()
- {
- system("COLOR b");
- cout << "\t\t ***************************************\n\n\n\n";
- cout << "\t\t ASAEESAEKOSADKOSAKDOSAKDOAS \n";
- cout << "\t\t ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
- cout << "\t\t\t ONLINE SHOPPING \n\n\t\t\t\t";
- system("pause");
- system("cls");
- login();
- }
- void menuscreen()
- {
- int option;
- int target;
- int location;
- Shopping<int> shop;
- system("color 4f");
- cout << " \t \t \t Welcome To ONLINE SHOPPING \n \n ";
- cout << " \t \t \t __________________________ \n ";
- cout << "\t\t Menu: \n";
- cout << "\t\t 1. \t add \n";
- cout << "\t\t 2. \t delete \n";
- cout << "\t\t 3. \t display \n";
- cout << "\t\t 4. \t search \n";
- cout << "\t\t 5. \t sort\n";
- cout << "\t\t 6. \t Log Out.\n";
- cout << "\t\t 7. \t Quit.\n";
- cout << " \t \t \t __________________________ \n\n ";
- cout << "\t\t *** Available only within Melacca.***\n";
- cout << " \n \n";
- do
- {
- cout << "\t User option >> ";
- cin >> option;
- switch (option)
- {
- case 1:
- for (int i = 1; i < 4; i++)
- {
- shop.AddToFront();
- }
- cout << "\n The List Are : ";
- shop.PrintData();
- break;
- case 2:
- cout << "\nItem to delete : ";
- cin >> target;
- if (shop.Traverse(target, location) == true)
- {
- if (location == 0)
- shop.DeleteFront();
- else
- shop.DeleteMiddle();
- }
- else
- {
- cout << "Item is not found \n";
- }
- break;
- case 3:
- cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
- cout << "\n The List Are : ";
- shop.PrintData();
- break;
- case 4:
- cout << "\nEnter the search item : ";
- cin >> target;
- if (shop.Traverse(target, location) == true)
- {
- cout << "Item is found at location : " << location << endl;
- }
- else
- {
- cout << "Item is not found \n";
- }
- break;
- case 5:
- cout << "\n\n\t***sort***\n\n";
- break;
- case 6:
- cout << "\n\n\t***YOU HAVE SUCCESSFULLY LOGGED OUT !!!***\n\n";
- cout << "\n\n\t***THANK YOU FOR USING OUR SYSTEM***\n\n";
- system("pause");
- login();
- break;
- case 7:
- cout << "\n\n\t***THANK YOU FOR USING OUR SYSTEM***\n\n";
- return ;
- break;
- default:
- exit(0);
- break;
- }
- } while (option < 1 || option>5);
- cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
- cout << "\n The List Are : ";
- shop.PrintData();
- cout << "\nNumber Of Item Now: " << shop.NumberOfItem();
- cout << "\n The List Are : ";
- shop.PrintData();
- }
- int login()
- {
- string username;
- string password;
- username = "ADMIN";
- char ch;
- string input;
- karate:
- system("cls");
- 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\tENTER USERNAME : ";
- cin >> input;
- if (input == username)
- {
- cout << "\n";
- cout << "\tENTER PASSWORD : ";
- ch = _getch();
- while (ch != 13)
- {
- password.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- if (password == "1234")
- {
- cout << "\n\n\n\n\n\n\t\t\t ACCESS GRANTED !!!\n ";
- for (int i = 0; i <3; i++)
- {
- cout << " ";
- Sleep(250);
- }
- Sleep(500);
- system("cls");
- menuscreen();
- }
- else
- cout << "\n\n\t\tAccess Denied.....Invalid Password\n\n";
- system("pause");
- goto karate;
- }
- else if (password == "00")
- {
- cout << "\n\n\n\n\n\n\t\t\t EXITING PROGRAMME !!!\n ";
- return(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement