hello
am doing a library program. i am almost done with it. but now my problem is i have to make the record update section work as each of the record can be updated separately.
so far i think of making another menu and do it like that. now my question is
1. i already have ("CLS") and ("cls") ( both of them but i do not know whats the difference) will this cls duo make any problem for a 3rd one .
2. i am going to put a new menu under another menu's case . ( i do not see any problem with it ) but will it make any problem.
i added my display and update part as code here . ( did not add the full code because its more than 500 line now )
the beginning of the code is like this
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
#include <fstream>
#include <string>
#include <ctime>
#include <sys/stat.h>
using namespace std;
struct Book_Record
{
int ID;
string price,requestor,call,invoice,supplier,copies,total,published;
string date,isbn;
string name,author,category,publisher;
bool deleted;
};
#define BOOK_FILE_NAME "Books.txt"
Book_Record Book;
int Auto = 100;
fstream *fs = NULL, *fs1 = NULL;// file streams for files : fs -> 'add', fs1 -> 'temp'
bool deletion = false;
void closeFile(fstream *); // closes a file with its pointer, then deletes the file pointer
bool isFileExist(const char *); // check if a file exists
int main()
{
ifstream input;
input.open("id.txt"),ios::in;
input >> Auto;
ofstream output;
int tries = 3;
string acc,password,MainPage;
cout << "\n\n\n";
cout << "\t\t*** ***" <<endl;
cout << "\t\t*** Welcome ***" <<endl;
cout << "\t\t*** To ***" <<endl;
cout << "\t\t*** Library Book Registration ***" <<endl;
cout << "\t\t*** Program ***" <<endl;
cout << "\t\t*** ***" <<endl;
cout << "\n\n\n";
{
while (tries)
{
cout <<"Please Enter ID: \a";
cin >> acc;
cout <<"Please Enter Password: ";
cin >> password;
system("CLS");
if (acc == "abc" && password =="123")
{
goto MainPage;
}
else
{
cout << "Invalid Id or Password. Please enter again" <<endl;
cout << "The Program Will terminate After 3 Unsuccessful Try" <<endl;
tries--;
}
}
return -1;
}
return 0;
MainPage:
system("CLS");
int num;
{
enum num { Add = 1, Search = 2, Update = 3, Delete = 4, Display = 5, Total = 6, Exit = 7};
}
do
{
system( "CLS" );
cout << "\n\n\n";
cout << "\t*** Welcome to Librery Book Register System ***" <<endl;
cout << "\t*** ***" <<endl;
cout << "\t*** 1. Add Record ***" <<endl;
cout << "\t*** 2. Search Record ***" <<endl;
cout << "\t*** 3. Update Record ***" <<endl;
cout << "\t*** 4. Delete Record ***" <<endl;
cout << "\t*** 5. Display Records ***" <<endl;
cout << "\t*** 6. Total number of Books ***" <<endl;
cout << "\t*** 7. Exit Program ***" <<endl;
cout <<"\n\n\n\n"<<flush;
cout<<"please select one: ";
num= _getch();
}
while ( num < '1' || num > '7' );
system ( "CLS" );
if (num == '2' || num == '3' || num == '4' || num == '5' || num == '6' )
{
if (!isFileExist (BOOK_FILE_NAME))
{
cout<<"Can't open or create '"<<BOOK_FILE_NAME<<"'file"<<endl;
system("pause");
goto MainPage;
}
}
switch(num)
{
int confirm;
int recs_num;
int id;
case '1':
and the display part is like this
fs = new fstream ( BOOK_FILE_NAME, ios::in | ios::binary );
if (!fs)
{
cout << "Can not open" <<BOOK_FILE_NAME<< "file." << endl;
system("pause");
break;
}
while (fs->read( (char *) &Book, sizeof(Book) ))
{
if ( !Book.deleted )
{
cout << "\n\n\n\n";
cout << "Book's ID\t\t: " << Book.ID << '\n';
cout << "Book's Name\t\t: " << Book.name << '\n';
cout << "Book's Author\t\t: " << Book.author << '\n';
cout << "Book's Publisher\t: " << Book.publisher << '\n';
cout << "Book's Category\t\t: " << Book.category << '\n';
cout << "Year Publisher\t\t: " << Book.publisher << '\n';
cout << "Book's ISBN\t\t: " << Book.isbn << '\n';
cout << "Price Of book\t\t: " << Book.price << '\n';
cout << "Requstor of Book\t: " << Book.requestor << '\n';
cout << "Book in Collum No\t: " << Book.call << '\n';
cout << "Book's Invoice No\t: " << Book.invoice << '\n';
cout << "Supplier for The Book\t: " << Book.supplier << '\n';
cout << "Number of Copies\t: " << Book.copies << '\n';
cout << "Added Date\t\t: " << Book.date << '\n';
cout << "\n\n\n\n";
}
}
closeFile(fs);
system ("pause");
goto MainPage;
break;
and the update part.
cout << "\n\nPlease enter BOOK's ID: " ;
cin>>id;
fs= new fstream ( BOOK_FILE_NAME, ios::in | ios::out | ios::binary);
if (!fs)
{
cout << "\nCan not open or create "<<BOOK_FILE_NAME<<"File"<< endl;
system("pause");
break;
}
recs_num= -1;
while (fs->read( (char*) &Book, sizeof(Book) ))
{
recs_num++;
if ( Book.ID == id && !Book.deleted)
break;
}
if (fs->eof())
{
cout << "\nBook Does Not Exist in The Librery" << endl;
closeFile(fs);
system("pause");
goto MainPage;
}
cout << "\n Enter Book's NAME: " ;
cin.get();
getline (cin,Book.name);
while (Book.name.find_first_of("qwertyuiopasdfghjklzxcvbnm") == string::npos)
{
cout << "\n* Invalid input! Please enter again!*\nNAME: " ;
getline (cin,Book.name);
}
////// so on as the records/////////
cout << "\nHow Many Copies of Book(example 033): " ;
cin.get();
getline (cin,Book.copies);
while (Book.copies.find_first_of("1234567890") == string::npos)
{
cout << "\n *Invalid input!please enter again! *\nCopies(example 033): " ;
getline (cin,Book.copies);
}
// char date[10];
// _strdate(date);
Book.date = date;
fs->seekp ( sizeof(Book) * recs_num, ios::beg );
fs->write( (char*) &Book, sizeof(Book) );
closeFile(fs);
cout << "\nRecord is modified."<< endl;
system("pause");
goto MainPage;
break;