Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

[c++ help]library code

fleshy

Novice
Advanced Member
Messages
21
Reaction score
0
Points
26
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)

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;
}
 
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)

Alam mo na yung konsepto ng classes at objects dahil nag define at nag declare ka... pero sana tinuloy mo na at ginawa mo ng Object-Oriented yung mini library mo.

Put it this way. Gawa ka ng Book class, Student class, at Library class. Yung Library class can have as many Student and Book classes. While the Student can have a limited number of Book class. Ilagay mo sa Library class yung logic like loading of book information from a file, loading of student information from another file, borrowing, returning, and the user interface.
 
Last edited:
Gets ko po ibig nyong sabihin, makakapagtry ako ng bago pero pano or posible ba na kung mag show/getClass ako, ma eequate ko sya to a single variable or new cariable? Tnatry ko kase oag i outfile ko ang ginamit kong a.showNumber eh ayaw nya, or in some case di nya nasstore sa storage na .dat file
 
Gets ko po ibig nyong sabihin, makakapagtry ako ng bago pero pano or posible ba na kung mag show/getClass ako, ma eequate ko sya to a single variable or new cariable? Tnatry ko kase oag i outfile ko ang ginamit kong a.showNumber eh ayaw nya, or in some case di nya nasstore sa storage na .dat file

Follow mo lang yung lead sa sinabi ko na 3 classes madali mo maime-maintain and ma-manage yung mga objects that way. Ang gawin mong technique since you are dealing with a text file, load mo sa memory pag nag create ka ng Library object, then I-save mo lang ONCE kung mag terminate or end na yung program. Habang nagra-run ang program, dun ka mag perform ng operations sa data sa memory-- add, edit, remove. The following are some of the functions and types you may need for each class.

[Book]
1. setters/getters for variables (each are of type string):
a) book_number
b) book_title
c) book_author
d) check_out_date
e) check_in_date
f) boolean variable to to see if book is currently checked out.

[Student]
1. setters/getters for each are of type string):
a) student_id
b) first_name
c) last_name

2. Array of Book object that will hold the borrowed books from the Library.

3. The following functions:
a) RemoveItemFromBookArray()
b) AddItemToBookArray()
c) FindBookByBookNumber()

[Library]
1. Create the following member variables
a) Array of Book objects
b) Array of Student objects

2. Create the following functions
a) run() // this is where the main loop will be for the Console UI
b) LoadBooksFromFile()
c) LoadStudentsFromFile()
d) tokenize() // to tokenize each line from the file. You should define a format for your student and book files eg. for student (1000#Juan#de la cruz) where the delimiter is the character '#', eg. for book(1#The Lord of the Rings#J. R. R. Tolkien).
 
Mas gets ko na po, salamat. Oo nga mas madali nga po ata yung sstore ko nalang pag itterminate na yung program. Salamat po! Pasimula palang kame sa programming madaming times pako magtatanong dito :)
 
baket di ka na lang gumamit ng sqlite API sir, madali lang yun i integrate since c/c++ din yun gawa, to relieve you of the debugging. that is, kung hinde bawal. hehe
 
Last edited:
Back
Top Bottom