Gumagawa pu kame, na parang sa library sya, simple lang. Mag iinput ng gustong libro, tapos pangalan, student number nung studyante, at kailan dapat ibalik
Nalilito po kase ako pano yung diba nakapag lagay nako ng due date. nasstore mga yon, dun sa 2nd .dat file ( yung filename1 which is logs.dat),
then kulang kupa nyan is dapat, kung nag input sya ng return or RETURN or Return(yung else if sa pinaka baba) e dapat, magiinput ako ng name(pag may equal na name na ininput ko, dun sa name na naka store, i cout nya yon, then magiinput ng DATE RETURNED.
tapos dapat pag date returned > date dued, maiissue sya na lost or overdued book, and if date returned < date dued, papasalamat ang program.
kung may tips po kayo para mas mapagada thanks.
CpE student po.(kung nagtataka kayo para san pa yung class or iba, kase po dapat andun halos nung lesson namen sa isang program eh)
Nalilito po kase ako pano yung diba nakapag lagay nako ng due date. nasstore mga yon, dun sa 2nd .dat file ( yung filename1 which is logs.dat),
then kulang kupa nyan is dapat, kung nag input sya ng return or RETURN or Return(yung else if sa pinaka baba) e dapat, magiinput ako ng name(pag may equal na name na ininput ko, dun sa name na naka store, i cout nya yon, then magiinput ng DATE RETURNED.
tapos dapat pag date returned > date dued, maiissue sya na lost or overdued book, and if date returned < date dued, papasalamat ang program.
kung may tips po kayo para mas mapagada thanks.
CpE student po.(kung nagtataka kayo para san pa yung class or iba, kase po dapat andun halos nung lesson namen sa isang program eh)
Code:
#include<iostream>
#include<cstdlib>
#include<string>
#include<conio.h>
#include<fstream>
#include<iomanip>
using namespace std;
class Number
{
private:
int nums;
public:
Number(int = 2030);
int setNumber(int);
int showNumber();
};
Number::Number(int numr)
{
nums = numr;
}
int Number::showNumber()
{
cout<<nums;
}
int main()
{
Number a;
int studnum;
string selection;
string gname;
bool done = false;
bool done1 = false;
int counter = -1;
string yesorno;
string booktitle, bookauthor;
int booknumber;
int dateBorrowed, dateDued, dateReturned;
string borrowreturn;
int day, year;
string month;
string searchname;
ofstream outFile;
ofstream fileOut;
ifstream inFile;
string filename = "booklist.dat";
string filename1 = "logs.dat";
string line;
int choice;
cout<<"\t\tWelcome to E-Zi library"<<endl;
cout<<"Do you wish to borrow or return? [BORROW or RETURN]: ";
cin>>borrowreturn;
if(borrowreturn == "BORROW" || borrowreturn == "Borrow" || borrowreturn == "borrow")
{
cout<<"You like to access our book list? [YES or NO]: "<<endl;
cin>>yesorno;
if(yesorno == "YES" || yesorno == "Yes" || yesorno == "yes")
{
cout<<"Here is the list of our books:"<<endl;
inFile.open(filename.c_str());
if(inFile.fail())
{
cout<< "File does not exist." << endl;
system("pause");
exit(1);
}
while(getline(inFile, line))
{
cout << line << endl;
}
inFile.close();
cout<<endl;
cout<<"Press ENTER if you're done choosing, take your time.... ";
cin.ignore();
cin.get();
do{
cout<<"What book would you like to borrow?: ";
getline(cin, booktitle);
if(booktitle == "The Lord of the Rings" || booktitle == "the lord of the rings")
{
cout<<"Title: The Lord of the Rings"<<endl;
cout<<"Author: J. R. R. Tolkien"<<endl;
cout<<"Book number 0001"<<endl;
}
else if(booktitle == "The Hobbit" || booktitle == "the hobbit")
{
cout<<"Title: The Hobbit"<<endl;
cout<<"Author: J. R. R. Tolkien"<<endl;
cout<<"Book number 0002"<<endl;
}
else if(booktitle == "The Little Prince" || booktitle == "the little prince")
{
cout<<"Title: The Little Prince"<<endl;
cout<<"Author: Antoine de Saint-Exupéry"<<endl;
cout<<"Book number 0003"<<endl;
}
else if(booktitle == "Harry Potter and the Philosopher's Stone" || booktitle == "harry potter and the philosopher's stone" || booktitle == "harry potter and the philosophers stone")
{
cout<<"Title: Harry Potter and the Philosopher's Stone"<<endl;
cout<<"Author: J. K. Rowling"<<endl;
cout<<"Book number 0004"<<endl;
}
else if(booktitle == "Twilight" || booktitle == "twilight")
{
cout<<"Title: Twilight"<<endl;
cout<<"Author: Stephenie Meyer"<<endl;
cout<<"Book number 0005"<<endl;
}
else if(booktitle == "She: A History of Adventure" || booktitle == "she: a history of adventure")
{
cout<<"Title: She: A History of Adventure"<<endl;
cout<<"Author: H. Rider Haggard"<<endl;
cout<<"Book number 0006"<<endl;
}
else if(booktitle == "The Da Vinci Code" || booktitle == "the da vinci code")
{
cout<<"Title: The Da Vinci Code"<<endl;
cout<<"Author: Dan Brown"<<endl;
cout<<"Book number 0007"<<endl;
}
else if(booktitle == "Carrie" || booktitle == "carrie")
{
cout<<"Title: Carrie"<<endl;
cout<<"Author: Stephen King"<<endl;
cout<<"Book number 0008"<<endl;
}
else if(booktitle == "The Ginger Man" || booktitle == "the ginger man")
{
cout<<"Title: The Ginger Man"<<endl;
cout<<"Author: J. P. Donleavy"<<endl;
cout<<"Book number 0009"<<endl;
}
else if(booktitle == "The Mark of Zorro" || booktitle == "the mark of zorro")
{
cout<<"Title: The Mark of Zorro"<<endl;
cout<<"Author: Johnston McCulley"<<endl;
cout<<"Book number 0010"<<endl;
}
else if(booktitle == "Mockingjay" || booktitle == "mockingjay")
{
cout<<"Title: Mockingjay"<<endl;
cout<<"Author: Suzanne Collins"<<endl;
cout<<"Book number 0011"<<endl;
}
else if(booktitle == "Angels & Demons" || booktitle == "angels & demons" || booktitle == "Angels and Demons" || booktitle == "angels and demons")
{
cout<<"Title: Angels & Demons"<<endl;
cout<<"Author: Dan Brown"<<endl;
cout<<"Book number 0012"<<endl;
}
else if(booktitle == "The Adventures of Pinocchio" || booktitle == "the adventures of pinocchio")
{
cout<<"Title: The Adventures of Pinocchio"<<endl;
cout<<"Author: Carlo Collodi"<<endl;
cout<<"Book number 0013"<<endl;
}
else if(booktitle == "Kane and Abel" || booktitle == "kane and abel")
{
cout<<"Title: Kane and Abel"<<endl;
cout<<"Author: Jeffrey Archer"<<endl;
cout<<"Book number 0014"<<endl;
}
else if(booktitle == "The Godfather" || booktitle == "the godfather")
{
cout<<"Title: The Godfather"<<endl;
cout<<"Author: Mario Puzo"<<endl;
cout<<"Book number 0015"<<endl;
}
else if(booktitle == "Frankenstein" || booktitle == "frankenstein")
{
cout<<"Title: Frankenstein"<<endl;
cout<<"Author: Mary Shelley"<<endl;
cout<<"Book number 0016"<<endl;
}
else if(booktitle == "The Fault in Our Stars" || booktitle == "the fault in our stars")
{
cout<<"Title: The Fault in Our Stars"<<endl;
cout<<"Author: John Green"<<endl;
cout<<"Book number 0017"<<endl;
}
else if(booktitle == "Tuesdays with Morrie" || booktitle == "tuesdays with morrie")
{
cout<<"Title: Tuesdays with Morrie"<<endl;
cout<<"Author: Mitch Albom"<<endl;
cout<<"Book number 0018"<<endl;
}
else if(booktitle == "Life of Pi" || booktitle == "life of pi")
{
cout<<"Title: Life of Pi"<<endl;
cout<<"Author: Yann Martel"<<endl;
cout<<"Book number 0019"<<endl;
}
else if(booktitle == "Captain Underpants" || booktitle == "captain underpants")
{
cout<<"Title: Captain Underpants"<<endl;
cout<<"Author: Dav Pilkey"<<endl;
cout<<"Book number 0020"<<endl;
}
else if(booktitle == "Tarzan" || booktitle == "tarzan")
{
cout<<"Title: Tarzan"<<endl;
cout<<"Author: Edgar Rice Burroughs"<<endl;
cout<<"Book number 0021"<<endl;
}
else if(booktitle == "The Hardy Boys" || booktitle == "the hardy boys")
{
cout<<"Title: The Hardy Boys"<<endl;
cout<<"Author: Franklin W. Dixon, &others"<<endl;
cout<<"Book number 0022"<<endl;
}
else if(booktitle == "Winnie-the-Pooh" || booktitle == "winnie-the-pooh" || booktitle == "Winnie the Pooh" || booktitle == "winnie the pooh")
{
cout<<"Title: Winnie-the-Pooh"<<endl;
cout<<"Author: A. A. Milne"<<endl;
cout<<"Book number 0023"<<endl;
}
else if(booktitle == "Fear Street" || booktitle == "fear street")
{
cout<<"Title: Fear Street"<<endl;
cout<<"Author: R. L. Stine"<<endl;
cout<<"Book number 0024"<<endl;
}
else if(booktitle == "James Bond" || booktitle == "james bond")
{
cout<<"Title: James Bond"<<endl;
cout<<"Author: Ian Fleming"<<endl;
cout<<"Book number 0026"<<endl;
}
else if(booktitle == "American Girl" || booktitle == "american girl")
{
cout<<"Title: American Girl"<<endl;
cout<<"Author: *various authors"<<endl;
cout<<"Book number 0026"<<endl;
}
else if(booktitle == "Fifty Shades of Grey" || booktitle == "fifty shades of grey" || booktitle == "50 Shades of Grey" || booktitle == "50 shades of grey")
{
cout<<"Title: Fifty Shades of Grey"<<endl;
cout<<"Author: E. L. James"<<endl;
cout<<"Book number 0027"<<endl;
}
else if(booktitle == "Nancy Drew" || booktitle == "nancy drew")
{
cout<<"Title: Nancy Drew"<<endl;
cout<<"Author: Carolyn Keene*various authors"<<endl;
cout<<"Book number 0028"<<endl;
}
else if(booktitle == "Perry Mason" || booktitle == "perry mason")
{
cout<<"Title: Perry Mason"<<endl;
cout<<"Author: Erle Stanley Gardner"<<endl;
cout<<"Book number 0029"<<endl;
}
else if(booktitle == "Peyton Place" || booktitle == "peyton place")
{
cout<<"Title: Peyton Place"<<endl;
cout<<"Author: Grace Metalious"<<endl;
cout<<"Book number 0030"<<endl;
}
}while (yesorno == "No" || yesorno == "no" || yesorno == "NO");
cout<<"Press ENTER to continue... "<<endl;
cin.ignore();
}
if(yesorno == "yes")
{
inFile.open(filename1.c_str());
inFile >> gname >> studnum >> booktitle ;
while(inFile.good())
{
cout << gname << " 2030" << studnum << " " << booktitle << endl;
cout<<month<<" "<<day<<" "<<year<<" "<<endl;
inFile >> gname >> studnum >> booktitle>>month>>day>>year;
}
inFile.close();
outFile.open(filename1.c_str(),ios::app);
if(outFile.fail())
{
cout << "File does not exist" << endl;
system("pause");
exit(1);
}
outFile.setf(ios::fixed);
outFile.setf(ios::showpoint);
outFile.precision(2);
//outFile.setf(ios::end);
cout<<"Enter your name[Last name, Given name, M.I.]: ";
getline(cin, gname);
cout<<endl;
cout<<"Default first 4 digits of your student number: ";
a.showNumber();
cout<<endl;
cout<<"Please enter the last 4 digits of your student number: ";
cin>>studnum;
system("cls");
cout<<"January February March April"<<endl;
cout<<"May June July August"<<endl;
cout<<"September October November December"<<endl;
cout<<"Month: ";
cin>>month;
cout<<endl;
cout<<"Day: ";
cin>>day;
cout<<endl;
cout<<"Year: ";
cin>>year;
cout<<endl;
cout<<"Due date to return the book is on: ";
cout<<month<<" "<<day<<" "<<year<<" "<<endl;
//outFile.seekp(0L,ios::end);
outFile << "Name: "<<gname << "\nStudent number: 2030" <<studnum << "\nBook borrowed: " << booktitle<<endl;
outFile<<"Due date: "<<month<<" "<<day<<" "<<year<<" "<<endl<<endl;
outFile.close();
}
//counter++;
// cout<<"Enter your name[Last name, Given name, M.I.]: ";
// getline(cin, gname);
// cout<<endl;
// cout<<"Default first 4 digits of your student number: ";
// a.showNumber();
// cout<<endl;
// cout<<"Please enter the last 4 digits of your student number: ";
// cin>>studnum;
// system("cls");
// cout<<endl<<endl;
// cout<<"Here is your full log of this transaction:"<<endl;
// cout<<"Name: "<<gname<<endl;
// cout<<"Student number: ";
// a.showNumber();
// cout<<studnum<<endl;
// cout<<"Book: "<<booktitle<<endl<<endl;
}
else if(borrowreturn == "RETURN" || borrowreturn == "Return" || borrowreturn == "return")
{
inFile.open(filename1.c_str());
if(inFile.fail())
{
cout<< "File does not exist." << endl;
system("pause");
exit(1);
}
while(getline(inFile, line))
{
cout << line << endl;
}
inFile.close();
cout<<endl;
do{
cout <<"Enter a student name to look up the log: ";
cin>>searchname;
bool found = false;
if(searchname == gname)
{
cout<<"Name: "<<gname << "\nStudent number: 2030" <<studnum << "\nBook borrowed: " << booktitle<<endl;
cout<<"Due date: "<<month<<" "<<day<<" "<<year<<" "<<endl<<endl;
found = true;
}}while(searchname == gname);
}
system("pause");
return 0;
}