Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save soachishti/7f02017d3a41437cfd63 to your computer and use it in GitHub Desktop.
Save soachishti/7f02017d3a41437cfd63 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<string>
#include <conio.h>
#include <windows.h>
#include<fstream>
using namespace std;
class node{
private:
string data;
node *next;
public:
int op1;
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
/* http://www.infernodevelopment.com/set-console-text-color */
static void SetColor(Color c) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
//SetColor(YELLOW);
// cout << "X\b";
}
static void coutColored(Color c, string text) {
SetColor(c);
cout << text;
SetColor(WHITE);
}
void goToXY(int x, int y) {
COORD coord = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int whereX() {
CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
return consoleinfo.dwCursorPosition.X;
}
int whereY() {
CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
return consoleinfo.dwCursorPosition.Y;
}
void Search(){
int op;
string search;
int offset = 0;
string line;
goToXY(1, 5);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 6);
SetColor(TEAL);
cout << " Categories |" << endl;
goToXY(1, 7);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 8);
SetColor(TEAL);
cout << " Science Fiction |" << endl;
goToXY(1, 9);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 10);
SetColor(TEAL);
cout << " English Litrature |" << endl;
goToXY(1, 11);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 12);
SetColor(TEAL);
cout << " Islamic Books |" << endl;
goToXY(1, 13);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 14);
SetColor(TEAL);
cout << " Computer Sciences |" << endl;
goToXY(1, 15);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 16);
SetColor(TEAL);
cout << " Management Sciences|" << endl;
goToXY(1, 17);
SetColor(GREEN);
cout << "---------------------";
goToXY(30, 7);
cout << "Press 1 for Searching Science Fiction." << endl;
goToXY(30, 8);
cout << "Press 2 for Searching English Litrature." << endl;
goToXY(30, 9);
cout << "Press 3 for Searching Islamic Books." << endl;
goToXY(30, 10);
cout << "Press 4 for Searching Computer Sciences." << endl;
goToXY(30, 11);
cout << "Press 5 for Searching Management Sciences." << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Please,Enter your Search choice:" << endl;
cin >> op;
system("cls");
if (op == 1){
ifstream Searchinfile;
Searchinfile.open("Science Fiction.txt");
cout << "Please,Enter the name of the book you are searching for?" << endl;
cin >> search;
if (Searchinfile.is_open()){
while (!Searchinfile.eof()){
getline(Searchinfile, line);
if ((offset == line.find(search, 0)) != string::npos){
cout << "Book Found:" << search << endl;
}
}
}
Searchinfile.close();
}
else if (op == 2){
ifstream Searchinfile;
Searchinfile.open("English Litrature.txt");
cout << "Please,Enter the name of the book you are searching for?" << endl;
cin >> search;
if (Searchinfile.is_open()){
while (!Searchinfile.eof()){
getline(Searchinfile, line);
if ((offset == line.find(search, 0)) != string::npos){
cout << "Book Found:" << search << endl;
}
}
}
Searchinfile.close();
}
else if (op == 3){
ifstream Searchinfile;
Searchinfile.open("Islamic Book.txt");
cout << "Please,Enter the name of the book you are searching for?" << endl;
cin >> search;
if (Searchinfile.is_open()){
while (!Searchinfile.eof()){
getline(Searchinfile, line);
if ((offset == line.find(search, 0)) != string::npos){
cout << "Book Found:" << search << endl;
}
}
}
Searchinfile.close();
}
else if (op == 4){
ifstream Searchinfile;
Searchinfile.open("Computer Science.txt");
cout << "Please,Enter the name of the book you are searching for?" << endl;
cin >> search;
if (Searchinfile.is_open()){
while (!Searchinfile.eof()){
getline(Searchinfile, line);
if ((offset == line.find(search, 0)) != string::npos){
cout << "Book Found:" << search << endl;
}
}
}
Searchinfile.close();
}
else{
ifstream Searchinfile;
Searchinfile.open("Management Science.txt");
cout << "Please,Enter the name of the book you are searching for?" << endl;
cin >> search;
if (Searchinfile.is_open()){
while (!Searchinfile.eof()){
getline(Searchinfile, line);
if ((offset == line.find(search, 0)) != string::npos){
cout << "Book Found:" << search << endl;
}
}
}
Searchinfile.close();
}
}
void English_lit(){
int x;
int y = 7;
int y1 = 9;
string Name;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~Enter New Record~~~~~~" << endl;
goToXY(23, 4);
SetColor(TEAL);
cout << "How many records do you want to enter:" << endl;
goToXY(23, 5);
SetColor(DARKBLUE);
cin >> x;
goToXY(23, y++);
SetColor(TEAL);
cout << "Enter the name of book number " << endl;
for (int i = 0; i < x; i++){
goToXY(23, y1++);
SetColor(DARKBLUE);
cin >> Name;
Enter_Rcd(Name);
}
node *temp = head;
ofstream writer("English Litrature.txt");
writer << "~~~~English Litrature~~~~" << endl;
while (temp != NULL){
writer << temp->data << endl;
temp = temp->next;
}
}
void Ismalic_Std(){
int x;
int y = 7;
int y1 = 9;
string Name;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~Enter New Record~~~~~~" << endl;
goToXY(23, 4);
SetColor(TEAL);
cout << "How many records do you want to enter:" << endl;
goToXY(23, 5);
SetColor(DARKBLUE);
cin >> x;
goToXY(23, y++);
SetColor(TEAL);
cout << "Enter the name of book number " << endl;
for (int i = 0; i < x; i++){
goToXY(23, y1++);
SetColor(DARKBLUE);
cin >> Name;
Enter_Rcd(Name);
}
node *temp = head;
ofstream writer("Islamic Book.txt");
writer << "~~~~~~Islamic Books~~~~~~" << endl;
while (temp != NULL){
writer << temp->data << endl;
temp = temp->next;
}
}
void Computer_Std(){
int x;
int y = 7;
int y1 = 9;
string Name;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~Enter New Record~~~~~~" << endl;
goToXY(23, 4);
SetColor(TEAL);
cout << "How many records do you want to enter:" << endl;
goToXY(23, 5);
SetColor(DARKBLUE);
cin >> x;
goToXY(23, y++);
SetColor(TEAL);
cout << "Enter the name of book number " << endl;
for (int i = 0; i < x; i++){
goToXY(23, y1++);
SetColor(DARKBLUE);
cin >> Name;
Enter_Rcd(Name);
}
node *temp = head;
ofstream writer("Computer Science.txt");
writer << "~~~~~~Computer Science~~~~~~" << endl;
while (temp != NULL){
writer << temp->data << endl;
temp = temp->next;
}
}
void Management_Sci(){
int x;
int y = 7;
int y1 = 9;
string Name;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~Enter New Record~~~~~~" << endl;
goToXY(23, 4);
SetColor(TEAL);
cout << "How many records do you want to enter:" << endl;
goToXY(23, 5);
SetColor(DARKBLUE);
cin >> x;
goToXY(23, y++);
SetColor(TEAL);
cout << "Enter the name of book number " << endl;
for (int i = 0; i < x; i++){
goToXY(23, y1++);
SetColor(DARKBLUE);
cin >> Name;
Enter_Rcd(Name);
}
node *temp = head;
ofstream writer("Management Science.txt");
writer << "~~~~~~Management Science~~~~~~" << endl;
while (temp != NULL){
writer << temp->data << endl;
temp = temp->next;
}
}
void Science_Fct(){
int x;
int y = 7;
int y1 = 9;
string Name;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~Enter New Record~~~~~~" << endl;
goToXY(23, 4);
SetColor(TEAL);
cout << "How many records do you want to enter:" << endl;
goToXY(23, 5);
SetColor(DARKBLUE);
cin >> x;
goToXY(23, y++);
SetColor(TEAL);
cout << "Enter the name of book number " << endl;
for (int i = 0; i < x; i++){
goToXY(23, y1++);
SetColor(DARKBLUE);
cin >> Name;
Enter_Rcd(Name);
}
node *temp = head;
ofstream writer("Science Fiction.txt");
writer << "~~~~~~Science Fiction~~~~~~" << endl;
while (temp != NULL){
writer << temp->data << endl;
temp = temp->next;
}
}
node *head;
void Enter_Rcd(string book_name){
node *temp = new node;
temp->data = book_name;
temp->next = NULL;
if (head != NULL){
temp->next = head;
}
head = temp;
}
void Mnu_for_Rcd(){
goToXY(1, 5);
cout << "---------------------" << endl;
goToXY(1, 6);
SetColor(TEAL);
cout << " Categories |" << endl;
goToXY(1, 7);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 8);
SetColor(TEAL);
cout << " Science Fiction |" << endl;
goToXY(1, 9);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 10);
SetColor(TEAL);
cout << " English Litrature |" << endl;
goToXY(1, 11);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 12);
SetColor(TEAL);
cout << " Islamic Books |" << endl;
goToXY(1, 13);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 14);
SetColor(TEAL);
cout << " Computer Sciences |" << endl;
goToXY(1, 15);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 16);
SetColor(TEAL);
cout << " Management Sciences|" << endl;
goToXY(1, 17);
SetColor(GREEN);
cout << "---------------------";
goToXY(30, 7);
cout << "Press 1 for Science Fiction." << endl;
goToXY(30, 8);
cout << "Press 2 for English Litrature." << endl;
goToXY(30, 9);
cout << "Press 3 for Islamic Books." << endl;
goToXY(30, 10);
cout << "Press 4 for Computer Sciences." << endl;
goToXY(30, 11);
cout << "Press 5 for Management Sciences." << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Please,Enter your choice:" << endl;
cin >> op1;
Decision1(op1);
}
void Decision1(int x){
switch (x){
case 1:
system("cls");
Science_Fct();
break;
case 2:
system("cls");
English_lit();
break;
case 3:
system("cls");
Ismalic_Std();
break;
case 4:
system("cls");
Computer_Std();
break;
case 5:
system("cls");
Management_Sci();
break;
default:
cout << "Error:Invalid Entry" << endl;
}
}
};
class Library_Mgn_Sys{
private:
node obj;
string Password = "united123";
string PWD;
string USNM = "Zerk";
string Newpass;
char ch;
int op;
string old_pass;
public:
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
/* http://www.infernodevelopment.com/set-console-text-color */
static void SetColor(Color c) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
//SetColor(YELLOW);
// cout << "X\b";
}
static void coutColored(Color c, string text) {
SetColor(c);
cout << text;
SetColor(WHITE);
}
void goToXY(int x, int y) {
COORD coord = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int whereX() {
CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
return consoleinfo.dwCursorPosition.X;
}
int whereY() {
CONSOLE_SCREEN_BUFFER_INFO consoleinfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleinfo);
return consoleinfo.dwCursorPosition.Y;
}
void LogIn(){
for (;;){
SetColor(DARKGREEN);
goToXY(28, 1);
cout << "LIBRARY MANAGEMENT SYSTEM" << endl;
goToXY(30, 3);
SetColor(RED);
cout << "~~~~~~LOG IN~~~~~~" << endl;
goToXY(30, 4);
SetColor(GREEN);
cout << "Username:" << endl;
goToXY(40, 4);
SetColor(RED);
cin >> USNM;
goToXY(30, 6);
SetColor(GREEN);
cout << "Password:" << endl;
goToXY(40, 6);
SetColor(RED);
ch = _getch();
while (ch != 13)
{
PWD.push_back(ch);
cout << '*';
ch = _getch();
}
cout << endl;
system("cls");
if (USNM == "Zerk" && PWD == Password){
break;
}
}
}
void Log_Out(){
exit(0);
LogIn();
}
void Change_pass(){
goToXY(30, 3);
cout << "----New Password----" << endl;
goToXY(30, 4);
cout << "Old Password:" << endl;
goToXY(43, 4);
cin >> old_pass;
goToXY(30, 5);
cout << "New Password:" << endl;
goToXY(43, 5);
cin >> Newpass;
PWD = Newpass;
}
void Interface(){
int c = 0;
cout << endl;
goToXY(0, 2);
SetColor(RED);
cout << "User:" << USNM << endl;
goToXY(10, 1);
SetColor(GREEN);
cout << "---------------------------------------------------------------------" << endl;
goToXY(10, 2);
SetColor(TEAL);
cout << "| Enter Records | Change Password | Search Book | Log Out |" << endl;
SetColor(GREEN);
goToXY(10, 3);
cout << "---------------------------------------------------------------------" << endl;
goToXY(1, 5);
cout << "---------------------" << endl;
goToXY(1, 6);
SetColor(TEAL);
cout << " Categories |" << endl;
goToXY(1, 7);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 8);
SetColor(TEAL);
cout << " Science Fiction |" << endl;
goToXY(1, 9);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 10);
SetColor(TEAL);
cout << " English Litrature |" << endl;
goToXY(1, 11);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 12);
SetColor(TEAL);
cout << " Islamic Books |" << endl;
goToXY(1, 13);
SetColor(GREEN);
cout << "---------------------" << endl;
goToXY(1, 14);
SetColor(TEAL);
cout << " Computer Sciences |" << endl;
goToXY(1, 15);
SetColor(GREEN);
cout << "--------------------" << endl;
goToXY(1, 16);
SetColor(TEAL);
cout << " Management Sciences|" << endl;
goToXY(1, 17);
SetColor(GREEN);
cout << "---------------------";
}
void Directions(){
goToXY(30, 7);
cout << "Press 1 for Enter Records." << endl;
goToXY(30, 8);
cout << "Press 2 for Change Password." << endl;
goToXY(30, 9);
cout << "Press 3 for Search Book." << endl;
goToXY(30, 10);
cout << "Press 4 for Log Out." << endl;
goToXY(30, 11);
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Please , select the option." << endl;
cin >> op;
Selector(op);
}
void Selector(int x){
switch (x){
case 1:
system("cls");
obj.Mnu_for_Rcd();
break;
case 2:
system("cls");
Change_pass();
break;
case 3:
system("cls");
obj.Search();
break;
case 4:
system("cls");
Log_Out;
break;
default:
cout << "Invalid Instruction." << endl;
}
}
};
int main(){
Library_Mgn_Sys set1;
set1.LogIn();
set1.Interface();
set1.Directions();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment