//This is the main file
#include<iostream>
#include<fstream>
#include<string>
#include "Books.h"
#include"account.h"
using namespace std;
int main()
{
cout << "\tWelcome\t" <<endl;
cout << "1-Login" <<endl;
cout << "2-Register" <<endl;
cout << "3-exit" <<endl;
cout << "Please enter a choice: ";
cin >> choice;
switch (choice){
case 1:
system ("cls");
cout << "Please enter Username:\t";
cin >> username;
cout<<"Password: ";
cin>>password;
accounts.open ("accounts.txt");
{
getline(accounts,data);
}
passwords.open ("passwords.txt");
{
getline(passwords,data);
}
accounts.close();
passwords.close();
if (data.compare(username)==0,data.compare(password)==0)
cout << "Welcome back "<< username << " to our private library" <<endl;
else
cout << "Sorry, invalid login information" <<endl;
break;
case 2:
cout << "Please create new username: ";
cin >> newAcc;
cout<<"Create new password: ";
cin >> newpassword;
regAcc.open ("accounts.txt");
regpass.open ("passwords.txt");
regAcc << newAcc;
regpass<<newpassword;
regAcc.close();
regpass.close();
system("cls");
cout<<"_______________________________________________________________"<<endl;
cout << "Congratulations "<< newAcc <<" your account has been succesfully created.\t" <<endl;
cout<<"_______________________________________________________________"<<endl;
cout<<" "<<endl;
cout << "Please enter your new login information "<<endl;
cout<<"Username:";
cin>>username;
cout<<" "<<endl;
cout<<"Password: ";
cin>>password;
accounts.open ("accounts.txt");
{
getline(accounts,data);
}
passwords.open ("passwords.txt");
{
getline(passwords,data);
}
accounts.close();
passwords.close();
if (data.compare(username)==0,data.compare(password)==0)
cout << "Welcome "<< username << " now you have access to our private library" <<endl;
else
cout << "Sorry, invalid login information!!" <<endl;
break;
case 3:
cout<<"Goodbye!!!"<<endl;
exit(1);
break;
default:
cout << "Sorry, invalid input" <<endl;
}
if (data.compare(username)!=0,data.compare(password)!=0)
exit(1);
else
//if(choice==1 || 2)
// exit(1);
//
//else
/*cout<<"Welcome to our library"<<endl;
cout<<"Press 1 to continue or 2 to exit"<<endl;
cout<<"Choice: ";*/
// cin>>choice2;
//if (choice2==2);
// exit(1);
// else (choice==1);
//system ("pause");
//return 0;
//}
ifstream inFile;
inFile.open("Bookdata.txt");
string Title[3];
string Author[3];
int ISBN[3];
double Price[3];
int count=0;
while (!inFile.eof())
{
inFile>>Title[count];
inFile>>Author [count];
inFile>>ISBN [count];
inFile>>Price [count];
count++;
}
Book Books[3];
for (int x=0; x<3; x++)
{
Books [x].Setup (Title [x], Author[x], ISBN [x], Price [x]);
}
int num;
cout<<"Please enter an ISBN number to search for"<<endl;
cin>>num;
int found=-1;
for (int x=0; x<3; x++)
{
if (Books[x].ISBNSearch(num)== 1)
found = x;
}
if (found != -1)
cout<<"The book title is: "<<Books[found].GetTitle()<<endl;
inFile.close();
if (found != -1)
// cout<<"The Author is: "<<Books[found].Setup()<<endl;
inFile.close();
system("pause");
return 0;
}
//This is account.h
#include <iostream>
#include <fstream>
#include <string>
#include"Books.h"
using namespace std;
ifstream accounts;
ifstream passwords;
string getcontent;
string username;
string password;
string data;
int choice;
int choice2;
ofstream regAcc;
ofstream regpass;
string newAcc;
string newpassword;
//this is Books.h
#include<string>
#ifndef Books_H
#define Books_H
using namespace std;
class Book
{
private:
string Title;
string Author;
int ISBN;
double Price;
public:
Book(){} //does nothing : constructor
Book (string title, string author, int isbn, double price){Title=title; Author=author; ISBN=isbn; Price=price;}//constructor
void Setup(string, string, int, double);//acepts string name and author. int price. double price
int ISBNSearch(int);
string GetTitle();
};
#endif
//this is Books.cpp
#include"Books.h"
void Book::Setup(string title, string author, int isbn, double price)//declares book
{
Title=title;
Author=author;
ISBN=isbn;
Price=price;
}
int Book::ISBNSearch(int num)
{
if (num == ISBN)
return 1;
else
return 0;
}
string Book::GetTitle()
{
return Title;
}