Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
void issue_book()
{
          system("cls");
          char sn[20],bn[20];
          int found=0,flag=0;
   cout<<"\t\t\nBOOK ISSUE";
          cout<<"\n\n\tEnter student's ID number: ";
          cin>>sn;
          fp.open("student.dat",ios::in|ios::out);
          fp1.open("book.dat",ios::in|ios::out);
          while(fp.read((char*)&st,sizeof(student)) && found==0)
          {
                    if(strcmpi(st.get_ID_number(),sn)==0)
                    {
                               found=1;
                               if(st.rettoken()==0)
                               {
                                        cout<<"\n\n\tEnter book number: ";
                                         cin>>bn;
                                         while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
                                         {
                                                   if(strcmpi(bk.getbooknumber(),bn)==0)
                                                 {
                                                           bk.show_book();
                                                             flag=1;
                                                             st.addtoken();
                                                             st.getstbno(bk.getbooknumber());
                                                             int pos=-1*sizeof(st);
                                                             fp.seekp(pos,ios::cur);
                                                             fp.write((char*)&st,sizeof(student));
                                                             cout<<"\n\n\t Book issued successfully...";
                                                   }
                                        }
                                        if(flag==0)
                                                   cout<<"Book number does not exist";
                               }
                              else
                                        cout<<"You have not returned the last book ";
                    }
          }
          if(found==0)
                    cout<<"Student record not exist...";
          getch();
          system("cls");
          fp.close();
          fp1.close();
}


What I have tried:

void issue_book()
{
system("cls");
char sn[20],bn[20];
int found=0,flag=0;
printf("\nBOOK ISSUE");
printf("\n\nEnter student's ID number: ");
Posted
Updated 7-Nov-20 6:07am
v2

Reading up on printf(), scanf(), fopen(), fwrite(), and fclose() should give you all the information you need to replace the file and io functions. Everything else is already C, except maybe some syntactic details that the compiler will tell you about anyway.
   
Comments
sumitfayez 2-Sep-20 6:00am
   
Thanks Man :)
Maciej Los 2-Sep-20 9:57am
   
5ed!
Stefan_Lang 2-Sep-20 11:46am
   
Thank you
The posted code is very C-like, you may easily do it yourself.
Change:
  • the cout statements into printf calls (as you've already done in your attempt).
  • the cin statements into scanf calls.
   
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Finding a random chunk of code that might do what your teacher wants and getting others to "convert it" so you can hand it in as your own work doesn't count as "effort"
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900