Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HEADER_H
- #define HEADER_H
- #include<fstream>
- ifstream infile;
- ofstream outfile;
- class List
- {
- private:
- struct Student
- {
- int bil;
- string name;
- string matricno;
- string plateno;
- string hostel;
- };
- class Node
- {
- public:
- Student StudentData;
- Node*link;
- };
- Node*pHead;
- Node*pCurr;
- Node*pPrev;
- Node*pTail;
- int numItem;
- public:
- List();
- ~List();
- void AddToFront();
- void AddToMiddle();
- void DeleteFront();
- void DeleteMiddle();
- int NumberOfItem();
- bool searchDelete(int, int &);
- bool searchPlate(string, int &);
- void sortHostel(string target);
- void printSearch(int);
- void displayData();
- bool Traverse();
- void displayOutput();
- void AddToFrontInput(int, string, string, string, string);
- void AddToMiddleInput(int, string, string, string, string);
- };
- #endif
- List::List()
- {
- numItem = 0;
- pHead = 0;
- }
- List::~List() {}
- void List::AddToFront()
- {
- string item1, item2, item3, item4;
- int item5;
- Node*pNew = new Node;
- cout << "\nEnter Name : ";
- getline(cin, item1);
- cout << "Enter Matric No. : ";
- getline(cin, item2);
- cout << "Enter Plate No. : ";
- getline(cin, item3);
- cout << "Enter Hostel : ";
- getline(cin, item4);
- numItem++;
- item5 = numItem;
- pNew->StudentData.name = item1;
- pNew->StudentData.matricno = item2;
- pNew->StudentData.plateno = item3;
- pNew->StudentData.hostel = item4;
- pNew->StudentData.bil = item5;
- pNew->link = pHead;
- pHead = pNew;
- }
- void List::AddToMiddle()
- {
- string item1, item2, item3, item4;
- int item5;
- Node*pNew = new Node;
- cout << "\nEnter Name : ";
- getline(cin, item1);
- cout << "Enter Matric No. : ";
- getline(cin, item2);
- cout << "Enter Plate No. : ";
- getline(cin, item3);
- cout << "Enter Hostel : ";
- getline(cin, item4);
- if (numItem == 1)
- pCurr = pHead;
- numItem++;
- item5 = numItem;
- pNew->StudentData.name = item1;
- pNew->StudentData.matricno = item2;
- pNew->StudentData.plateno = item3;
- pNew->StudentData.hostel = item4;
- pNew->StudentData.bil = item5;
- pNew->link = pCurr->link;
- pCurr->link = pNew;
- pCurr = pNew;
- }
- void List::DeleteFront()
- {
- pHead = pHead->link;
- pCurr = pHead;
- numItem--;
- for (int i = 1; i <= numItem; i++)
- {
- pCurr->StudentData.bil = i;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- }
- void List::DeleteMiddle()
- {
- pPrev->link = pCurr->link;
- numItem--;
- pCurr = pHead;
- for (int i = 1; i <= numItem; i++)
- {
- pCurr->StudentData.bil = i;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- }
- int List::NumberOfItem()
- {
- return numItem;
- }
- bool List::searchDelete(int target1, int &loc)
- {
- if (numItem == 0)
- cout << "NO ITEM" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->StudentData.bil != target1 && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->StudentData.bil == target1)
- return true;
- else
- return false;
- }
- }
- bool List::searchPlate(string target, int &loc)
- {
- if (numItem == 0)
- cout << "NO ITEM" << endl;
- else
- {
- pCurr = pHead;
- loc = 0;
- while (pCurr->StudentData.plateno != target && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- if (pCurr->StudentData.plateno == target)
- return true;
- else
- return false;
- }
- }
- void List::sortHostel(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) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- for(int i = 0; i < numItem; i++)
- {
- if (pCurr->StudentData.hostel == target)
- {
- cout << endl;
- cout << left << setw(20) << pCurr->StudentData.name;
- cout << left << setw(20) << pCurr->StudentData.matricno;
- cout << left << setw(20) << pCurr->StudentData.plateno;
- cout << left << setw(20) << pCurr->StudentData.hostel;
- total++;
- }
- else;
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- cout << "\n\nTotal : " << total << endl << endl;
- }
- void List::printSearch(int location)
- {
- pCurr = pHead;
- int loc = 0;
- while (loc != location && pCurr->link != 0)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- loc++;
- }
- cout << left << setw(20) << pCurr->StudentData.name;
- cout << left << setw(20) << pCurr->StudentData.matricno;
- cout << left << setw(20) << pCurr->StudentData.plateno;
- cout << left << setw(20) << pCurr->StudentData.hostel;
- }
- void List::displayData()
- {
- pCurr = pHead;
- while (pCurr != 0)
- {
- cout << " " << pCurr->StudentData.bil << " ";
- cout << left << setw(20) << pCurr->StudentData.name;
- cout << left << setw(20) << pCurr->StudentData.matricno;
- cout << left << setw(20) << pCurr->StudentData.plateno;
- cout << left << setw(20) << pCurr->StudentData.hostel;
- pCurr = pCurr->link;
- cout << endl;
- }
- }
- bool List::Traverse()
- {
- pCurr = pHead;
- while (pCurr->link != NULL)
- {
- pPrev = pCurr;
- pCurr = pCurr->link;
- }
- if (pCurr->link == NULL)
- return true;
- else
- return false;
- }
- void List::displayOutput()
- {
- outfile.open("info.txt");
- pCurr = pHead;
- while (pCurr != 0)
- {
- outfile << " " << pCurr->StudentData.bil << " ";
- outfile << left << setw(20) << pCurr->StudentData.name;
- outfile << left << setw(20) << pCurr->StudentData.matricno;
- outfile << left << setw(20) << pCurr->StudentData.plateno;
- outfile << left << setw(20) << pCurr->StudentData.hostel;
- pCurr = pCurr->link;
- outfile << endl;
- }
- outfile.close();
- }
- void List::AddToFrontInput(int item5, string item1, string item2, string item3, string item4)
- {
- Node*pNew = new Node;
- numItem++;
- item5 = numItem;
- pNew->StudentData.name = item1;
- pNew->StudentData.matricno = item2;
- pNew->StudentData.plateno = item3;
- pNew->StudentData.hostel = item4;
- pNew->StudentData.bil = item5;
- pNew->link = pHead;
- pHead = pNew;
- }
- void List::AddToMiddleInput(int item5, string item1, string item2, string item3, string item4)
- {
- Node*pNew = new Node;
- if (numItem == 1)
- pCurr = pHead;
- numItem++;
- item5 = numItem;
- pNew->StudentData.name = item1;
- pNew->StudentData.matricno = item2;
- pNew->StudentData.plateno = item3;
- pNew->StudentData.hostel = item4;
- pNew->StudentData.bil = item5;
- pNew->link = pCurr->link;
- pCurr->link = pNew;
- pCurr = pNew;
- }
- ---------------------------------------------------
- #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 main()
- {
- List mylist;
- string target, name, matric, plate, hostel;
- int location, choice, bil, target1;
- char backOption, choice1;
- login();
- ifstream infile;
- infile.open("info.txt");
- while (infile >> bil >> name >> matric >> plate >> hostel)
- {
- if (mylist.NumberOfItem() == 0)
- mylist.AddToFrontInput(bil, name, matric, plate, hostel);
- else
- mylist.AddToMiddleInput(bil, name, matric, plate, hostel);
- }
- infile.close();
- do
- {
- cout << "**********" << "MENU" << "**********" << endl << endl;
- cout << "========================\n1. ADD ITEM\n2. DELETE ITEM\n3. DISPLAY RECORD\n4. SORT BY HOSTEL\n5. SEARCH BY PLATE NO\n6. EXIT\n========================\n\n";
- cout << " = ";
- cin >> choice;
- cin.ignore();
- cout << endl;
- system("cls");
- switch (choice)
- {
- case 1:
- cout << "-----ADD ITEM-----\n";
- if (mylist.NumberOfItem() == 0)
- {
- mylist.AddToFront();
- cout << "\nAdd some more? (Y=yes, N=no) : ";
- cin >> choice1;
- cin.ignore();
- if (choice1 == 'Y')
- {
- do
- {
- mylist.AddToMiddle();
- cout << "\nAdd some more? (Y=yes, N=no) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y');
- }
- else
- break;
- }
- else
- if (mylist.Traverse() == true)
- {
- do
- {
- mylist.AddToMiddle();
- cout << "\nAdd some more? (Y=yes, N=no) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y');
- }
- cout << "\nSUCCESSFULLY ADDED!\n";
- 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) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << 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 << "\nDelete more? (Y=yes, N=no) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y');
- break;
- case 3:
- 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) << " Name " << left << setw(20) << "Matric No " << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << 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;
- break;
- case 4:
- do
- {
- system("cls");
- cout << "-----SORT BY HOSTEL-----\n\n";
- cout << "HOSTEL : ";
- getline(cin, target);
- mylist.sortHostel(target);
- cout << "SORT AGAIN? (Y=yes, N=no) : ";
- cin >> choice1;
- cin.ignore();
- } while (choice1 == 'Y');
- break;
- case 5:
- cout << "-----SEARCH BY PLATE NO-----" << "\n\nPlate No. : ";
- getline(cin, target);
- cout << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- cout << left << setw(20) << " Name " << left << setw(20) << "Matric No" << left << setw(20) << " Plate No " << left << setw(20) << " Hostel " << endl;
- cout << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << left << setw(20) << "----------" << endl;
- if (mylist.searchPlate(target, location) == true)
- mylist.printSearch(location);
- else
- cout << "Item is not found\n";
- cout << endl;
- break;
- case 6:
- mylist.displayOutput();
- cout << "\n. . . EXITING SYSTEM . . .\n\n";
- exit(EXIT_FAILURE);
- break;
- }
- cout << "\nBACK TO MAIN MENU? (Y=yes, N=no) : ";
- cin >> backOption;
- system("cls");
- }
- while (backOption == 'Y');
- {
- mylist.displayOutput();
- cout << "\n. . . EXITING SYSTEM . . .\n\n";
- }
- }
- void login()
- {
- string username;
- string password;
- username = "ADMIN";
- char ch;
- string input;
- karate:
- system("cls");
- cout << "\n\t\t\t\t\t=====VEHICLE STICKER REGISTRATION=====\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 VERIFYING . . . ";
- for (int i = 0; i < 6; i++)
- {
- cout << "\xdb\xdb\xdb\xdb\xdb";
- Sleep(250);
- }
- Sleep(500);
- system("cls");
- return;
- }
- else
- cout << "\n\n\t\tAccess Denied.....Invalid Password\n\n";
- system("pause");
- goto karate;
- }
- else
- cout << "\n\n\t\tAccess Denied.....Invalid Username\n\n";
- system("pause");
- goto karate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement