Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: help!!!with c++

  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help!!!with c++

    i am trying tocreate a library management program using file i\o.i am stuck please help.this is what i have done.


    //library
    #include<iostream.h>
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #include<fstream.h>
    class lib
    {
    public:
    char name[120];
    char genre[20];
    char author[20];
    int doi;
    int dor;
    void getdata();
    void display();
    };
    void lib:: getdata()
    {
    cout<<"enter the books name";
    cin>>name;
    cout<<"emter author";
    cin>>author;
    cout<<"enter genre";
    cin>>genre;

    }
    void lib:: display()
    {
    cout<<"book\tauthor";
    cout<<endl<<name<<"\t"<<author<<"\t"<<genre;

    }

    void main()
    {cout<<"MENU"<<endl;
    cout<<"1."<<"enter a book"<<endl;
    cout<<"2."<<"issue"<<endl;
    int p;
    fstream filout("q.txt",ios::app);
    int n;
    char c;
    lib b[10];
    cin>>p;
    switch (p)
    { case 1:
    { int i=0,j;
    cout<<"do u want to enter more books ?";
    cin>>c;
    while(c=='y'||c=='Y')
    {
    cout<<"enter the no of books";
    cin>>n;
    for(i;i<n;i++)
    { b[i].getdata();
    b[i].display();
    filout<<b[i].name<<"\t"<<b[i].author<<"\t"<<b[i].genre<<"\n";
    cout<<endl<<endl;
    }
    cout<<"do u want to continue?";
    cin>>c;
    }
    filout.close();

    ifstream fin("q.txt");
    fin.seekg(0);
    cout<<"________\n\n";
    // for(j=0;j<i;j++)
    j=0;
    do
    {
    fin>>b[j].name;
    fin>>b[j].author;
    fin>>b[j].genre;
    cout.width(7);
    cout<<j+1<<". "<<b[j].name<<"\t\t"<<b[j].author<<"\t\t"<<b[j].genre<<endl;
    // fin>>author;
    j++;
    } while(fin);

    fin.close();
    break;
    }
    case 2 :
    { cout<<endl<<"to issue"<<endl;
    char bok[20];
    fstream is;
    is.open("q.txt",ios::in|ios:ut);
    cout<<endl<<"enter the name of book u want to issue";
    cin>>bok;
    while(is)
    { int k=0;
    if (bok ==b[k].name )
    {
    cout<<"enter date of issue";
    cin>>b[k].doi;
    cout<<"book is due on"<<b[k].doi+7;
    }
    k++;

    }
    break;
    }
    }
    }

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Please read our guidelines on homework assignments.

    What is wrong with your program? What do you need help with? You need to be more specific.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •