Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have written my final project and I am getting 3 simple errors that I can\'t s

ID: 3815590 • Letter: I

Question

I have written my final project and I am getting 3 simple errors that I can't seem to fix. I will attach the final project syllabus, my code i've written for the final project, and the errors I am receiving. Please fix my code so it will compile and run and attach copyable corrected code so it will work and I will gladly give you 5 stars :-) thank you

My code:

#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip>
using namespace std;
class book
{
   char bno[6];
   char bname[50];
   char aname[20];
public:
   void create_book()
   {
       cout << " NEW BOOK ENTRY... ";
       cout << " Enter The book no.";
       cin >> bno;
       cout << " Enter The Name of The Book ";
       gets(bname);
       cout << " Enter The Author's Name ";
       gets(aname);
       cout << " Book Created..";
   }

   void show_book()
   {
       cout << " Book no. : " << bno;
       cout << " Book Name : ";
       puts(bname);
       cout << "Author Name : ";
       puts(aname);
   }

   void modify_book()
   {
       cout << " Book no. : " << bno;
       cout << " Modify Book Name : ";
       gets(bname);
       cout << " Modify Author's Name of Book : ";
       gets(aname);
   }

   char* retbno()
   {
       return bno;
   }

   void report()
   {
       cout << bno << setw(30) << bname << setw(30) << aname << endl;
   }


}; //class ends here

class journals
{
   char jno[6];
   char jname[50];
   char aname[20];
public:
   void create_journal()
   {
       cout << " NEW JOURNAL ENTRY... ";
       cout << " Enter The journal no.";
       cin >> jno;
       cout << " Enter The Name of The Journal ";
       gets(jname);
       cout << " Enter The Author's Name ";
       gets(aname);
       cout << " Journal Created..";
   }

   void show_journal()
   {
       cout << " journal no. : " << jno;
       cout << " journak Name : ";
       puts(jname);
       cout << "journal Name : ";
       puts(aname);
   }

   void modify_journal()
   {
       cout << " journal no. : " << jno;
       cout << " Modify journal Name : ";
       gets(aname);
       cout << " Modify Author's Name of journal : ";
       gets(aname);
   }

   char* retjno()
   {
       return jno;
   }

   void report()
   {
       cout << jno << setw(30) << jname << setw(30) << aname << endl;
   }


}; //class ends here

class user
{
   char admno[6];
   char name[20];
   char stbno[6];
   int token;
public:
   void create_student()
   {

       cout << " NEW STUDENT ENTRY... ";
       cout << " Enter The admission no. ";
       cin >> admno;
       cout << " Enter The Name of The Student ";
       gets(name);
       token = 0;
       stbno[0] = '/0';
       cout << " Student Record Created..";
   }

   void show_student()
   {
       cout << " Admission no. : " << admno;
       cout << " Student Name : ";
       puts(name);
       cout << " No of Book issued : " << token;
       if (token == 1)
           cout << " Book No " << stbno;
   }

   void modify_student()
   {
       cout << " Admission no. : " << admno;
       cout << " Modify Student Name : ";
       gets(name);
   }

   char* retadmno()
   {
       return admno;
   }

   char* retstbno()
   {
       return stbno;
   }

   int rettoken()
   {
       return token;
   }

   void addtoken()
   {
       token = 1;
   }

   void resettoken()
   {
       token = 0;
   }

   void getstbno(char t[])
   {
       strcpy_s(stbno, t);
   }

   void report()
   {
       cout << " " << admno << setw(20) << name << setw(10) << token << endl;
   }

}; //class ends here


fstream fp, fp1;
book bk;
user st;


void write_book()
{
   char ch;
   fp.open("book.dat");
   do
   {

       bk.create_book();
       fp.write((char*)&bk, sizeof(book));
       cout << " Do you want to add more record..(y/n?)";
       cin >> ch;
   } while (ch == 'y' || ch == 'Y');
   fp.close();
}

void write_user()
{
   char ch;
   fp.open("user.dat");
   do
   {
       st.create_student();
       fp.write((char*)&st, sizeof(user));
       cout << " do you want to add more record..(y/n?)";
       cin >> ch;
   } while (ch == 'y' || ch == 'Y');
   fp.close();
}


void display_spb(char n[])
{
   cout << " BOOK DETAILS ";
   int flag = 0;
   fp.open("book.dat", ios::in);
   while (fp.read((char*)&bk, sizeof(book)))
   {
       if (_strcmpi(bk.retbno(), n) == 0)
       {
           bk.show_book();
           flag = 1;
       }
   }

   fp.close();
   if (flag == 0)
       cout << " Book does not exist";
   _getch();
}

void display_sps(char n[])
{
   cout << " STUDENT DETAILS ";
   int flag = 0;
   fp.open("student.dat", ios::in);
   while (fp.read((char*)&st, sizeof(user)))
   {
       if ((_strcmpi(st.retadmno(), n) == 0))
       {
           st.show_student();
           flag = 1;
       }
   }

   fp.close();
   if (flag == 0)
       cout << " Student does not exist";
   _getch();
}


void modify_book()
{
   char n[6];
   int found = 0;

   cout << " MODIFY BOOK REOCORD.... ";
   cout << " Enter The book no. of The book";
   cin >> n;
   fp.open("book.dat", ios::in | ios::out);
   while (fp.read((char*)&bk, sizeof(book)) && found == 0)
   {
       if (_strcmpi(bk.retbno(), n) == 0)
       {
           bk.show_book();
           cout << " Enter The New Details of book" << endl;
           bk.modify_book();
           int pos = -1 * sizeof(bk);
           fp.seekp(pos, ios::cur);
           fp.write((char*)&bk, sizeof(book));
           cout << " Record Updated";
           found = 1;
       }
   }

   fp.close();
   if (found == 0)
       cout << " Record Not Found ";
   _getch();
}

void delete_student()
{
   char n[6];
   int flag = 0;

   cout << " DELETE STUDENT...";
   cout << " Enter The admission no. of the Student You Want To Delete : ";
   cin >> n;
   fp.open("student.dat", ios::in | ios::out);
   fstream fp2;
   fp2.open("Temp.dat", ios::out);
   fp.seekg(0, ios::beg);
   while (fp.read((char*)&st, sizeof(user)))
   {
       if (_strcmpi(st.retadmno(), n) != 0)
           fp2.write((char*)&st, sizeof(user));
       else
           flag = 1;
   }

   fp2.close();
   fp.close();
   remove("student.dat");
   rename("Temp.dat", "student.dat");
   if (flag == 1)
       cout << " Record Deleted ..";
   else
       cout << " Record not found";
   _getch();
}


void delete_book()
{
   char n[6];

   cout << " DELETE BOOK ...";
   cout << " Enter The Book no. of the Book You Want To Delete : ";
   cin >> n;
   fp.open("book.dat", ios::in | ios::out);
   fstream fp2;
   fp2.open("Temp.dat", ios::out);
   fp.seekg(0, ios::beg);
   while (fp.read((char*)&bk, sizeof(book)))
   {
       if (_strcmpi(bk.retbno(), n) != 0)
       {
           fp2.write((char*)&bk, sizeof(book));
       }
   }

   fp2.close();
   fp.close();
   remove("book.dat");
   rename("Temp.dat", "book.dat");
   cout << " Record Deleted ..";
   _getch();
}


void check_alls()
{
   fp.open("student.dat", ios::in);
   if (!fp)
   {
       cout << "ERROR!!! FILE COULD NOT BE OPEN ";
       _getch();
       return;
   }

   cout << " STUDENT LIST ";
   cout << "================================================================== ";
   cout << " Admission No." << setw(10) << "Name" << setw(20) << "Book Issued ";
   cout << "================================================================== ";

   while (fp.read((char*)&st, sizeof(user)))
   {
       st.report();
   }

   fp.close();
   _getch();
}

void display_allb()
{

   fp.open("book.dat", ios::in);
   if (!fp)
   {
       cout << "ERROR!!! FILE COULD NOT BE OPEN ";
       _getch();
       return;
   }

   cout << " Book LIST ";
   cout << "========================================================================= ";
   cout << "Book Number" << setw(20) << "Book Name" << setw(25) << "Author ";
   cout << "========================================================================= ";

   while (fp.read((char*)&bk, sizeof(book)))
   {
       bk.report();
   }
   fp.close();
   _getch();
}


void book_issue()
{
   char sn[6], bn[6];
   int found = 0, flag = 0;

   cout << " BOOK ISSUE ...";
   cout << " Enter The student's admission no.";
   cin >> sn;
   fp.open("student.dat", ios::in | ios::out);
   fp1.open("book.dat", ios::in | ios::out);
   while (fp.read((char*)&st, sizeof(user)) && found == 0)
   {
       if (_strcmpi(st.retadmno(), sn) == 0)
       {
           found = 1;
           if (st.rettoken() == 0)
           {
               cout << " Enter the book no. ";
               cin >> bn;
               while (fp1.read((char*)&bk, sizeof(book)) && flag == 0)
               {
                   if (_strcmpi(bk.retbno(), bn) == 0)
                   {
                       bk.show_book();
                       flag = 1;
                       st.addtoken();
                       st.getstbno(bk.retbno());
                       int pos = -1 * sizeof(st);
                       fp.seekp(pos, ios::cur);
                       fp.write((char*)&st, sizeof(user));
                       cout << " Book issued successfully Please Note: Write current data in backside of book and submit within 15 days fine Rs. 1 for each day after 15 days period";
                   }
               }
               if (flag == 0)
                   cout << "Book no does not exist";
           }
           else
               cout << "You have not returned the last book ";

       }
   }
   if (found == 0)
       cout << "Student record not exist...";
   _getch();
   fp.close();
   fp1.close();
}

void intro()
{
   cout << "LIBRARY";
   cout << "MANAGEMENT";
   cout << "SYSTEM";
   _getch();
}


void librarian_menu()
{

   int ch2;
   cout << " LIBRARIAN MENU";
   cout << " 1.CREATE STUDENT RECORD";
   cout << " 2.DISPLAY ALL STUDENTS RECORD";
   cout << " 3.DISPLAY SPECIFIC STUDENT RECORD ";
   cout << " 4.MODIFY STUDENT RECORD";
   cout << " 5.DELETE STUDENT RECORD";
   cout << " 6.CREATE BOOK ";
   cout << " 7.DISPLAY ALL BOOKS ";
   cout << " 8.DISPLAY SPECIFIC BOOK ";
   cout << " 9.MODIFY BOOK ";
   cout << " 10.DELETE BOOK ";
   cout << " 11.BACK TO MAIN MENU";
   cout << " Please Enter Your Choice (1-11) ";
   cin >> ch2;
   user a;

   switch (ch2)
   {
   case 1:

       a.create_student(); break;
   case 2: display_allb(); break;
   case 3:
       char num[6];
       cout << " Please Enter The Admission No. ";
       cin >> num;
       display_sps(num);
       break;
   case 4:a.modify_student(); break;
   case 5: delete_student(); break;
   case 6:
       write_book(); break;
   case 7: display_allb(); break;
   case 8: {
       char num[6];

       cout << " Please Enter The book No. ";
       cin >> num;
       display_spb(num);
       break;
   }
   case 9: modify_book(); break;
   case 10: delete_book(); break;
   case 11: return;
   default:cout << "";
   }
   librarian_menu();
}

void main()
{
   char ch;
   intro();
   book b;
   do
   {

       cout << " MAIN MENU";
       cout << " 01. BOOK ISSUE";
       cout << " 02. BOOK DEPOSIT";
       cout << " 03. ADMINISTRATOR MENU";
       cout << " 04. EXIT";
       cout << " Please Select Your Option (1-4) ";
       ch = _getche();
       switch (ch)
       {
       case '1':
           book_issue();
           break;
       case '2':b.create_book();
           break;
       case '3':librarian_menu();
           break;
       case '4':exit(0);
       default:cout << "";
       }
   } while (ch != '4');
   system("pause");
}

Errors I'm Receiving:

1. identifier "gets" is undefined (line 21, 40, 70, 89, 121, 141)

2. 'gets': identifier not found (line 21, 23, 40, 42, 70, 72, 89, 91, 121, 141)

3. negative integral constant converted to unsigned type (line 274, 424)

Write a C++ program to manage a library system. The main user is the librarian. Build Specifications (35 points) 1. The system should load a catalog of books, journals, and magazines at the start of the program 2. A user can search the catalog: The user of the system can search the library's catalog by using the name of the item. Also, a user can list books by category (Book, Journal, or magazine). If you are looking specifically for a book, you can search by the name ofthe author. 3. A user can check out books, journals, or magazines: The user needs to find the item first, then they can check it out. A user cannot check out an item that is already checked out. 4. A user can return books, journals, or magazines: A user can return an item. The user needs to find the item first, then they can return it.

Explanation / Answer

1. identifier "gets" is undefined (line 21, 40, 70, 89, 121, 141)
2. 'gets': identifier not found (line 21, 23, 40, 42, 70, 72, 89, 91, 121, 141)

The gets function was considered too dangerous as it doesn't perform bound checking and therfore can cause buffer overflow. so it was removed from the latest revisions of C++ and is replaced with gets_s(). You are suppose to use either gets_s() or fgets()

gets_s(buf);
or
fgets(buf, sizeof(buf), stdin);

---------------------------------------------------------------------------------------------------------

3. negative integral constant converted to unsigned type (line 274, 424)

Solution is to cast sizeof(object) to int before multiplication. On line 274, simply replace
int pos = -1 * sizeof(bk);
by
int pos = -1 * (int)sizeof(bk);


* And similarly on line 424 replace
int pos = -1 * sizeof(st); with int pos = -1 * (int)sizeof(st);