Advertisement
YasserZ

Untitled

Aug 9th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. struct Book
  5. {
  6.     char Title[50];
  7.     char ISBN[50];
  8.     char Author[50];
  9.     char publisher[50];
  10.     char Mobile[50];
  11. };
  12. istream& operator >> (istream& input, Book& s)
  13. {
  14.     cout << "Enter Book's Title: ";
  15.     input.getline(s.Title, 50);
  16.     cout << "Enter Book's ISBN: ";
  17.     input.getline(s.ISBN, 50);
  18.     cout << "Enter Book's Author: ";
  19.     input.getline(s.Author, 50);
  20.     cout << "Enter Book's publisher: ";
  21.     input.getline(s.publisher, 50);
  22.     cout << "Enter Book's Mobile: ";
  23.     input.getline(s.Mobile, 50);
  24.     return input;
  25. }
  26. void addBook(Book s)
  27. {
  28.     ofstream file("f.txt", ios::app);
  29.     if (!file)
  30.     {
  31.         cout << "File opening failed!" << endl;
  32.         return;
  33.     }
  34.     short recLength = 0;
  35.     //cin.ignore();
  36.  
  37.     recLength = strlen(s.publisher) + strlen(s.Title) + strlen(s.Mobile) + strlen(s.ISBN) + strlen(s.Author) + 10;
  38.  
  39.     file.write((char*)& recLength, sizeof(short));
  40.     short length = strlen(s.Title);
  41.     file.write((char*)& length, sizeof(short));
  42.     file.write((char*)& s.Title, length);
  43.     length = strlen(s.ISBN);
  44.     file.write((char*)& length, sizeof(short));
  45.     file.write((char*)& s.ISBN, length);
  46.     length = strlen(s.Author);
  47.     file.write((char*)& length, sizeof(short));
  48.     file.write((char*)& s.Author, length);
  49.     length = strlen(s.publisher);
  50.     file.write((char*)& length, sizeof(short));
  51.     file.write((char*)& s.publisher, length);
  52.     length = strlen(s.Mobile);
  53.     file.write((char*)& length, sizeof(short));
  54.     file.write((char*)& s.Mobile, length);
  55.     file.close();
  56.     cout << "Book added successfully!" << endl;
  57.  
  58. }
  59. /*
  60. void addIntoAvail()
  61. {
  62. fstream file("f.txt", ios::in | ios::out | ios::binary);
  63. short deleted = 0;
  64. file.read((char*)&deleted, sizeof(short));
  65. if (deleted == -1) //avail list is empty
  66. {
  67. addBook();
  68. return;
  69. }
  70. file.seekg(deleted, ios::beg);
  71. short availSize = 0;
  72. file.read((char*)&availSize, sizeof(short));
  73. Book s;
  74. short recLength = 0;
  75. //cin.ignore();
  76. cout << "Enter Book's Title: ";
  77. cin.getline(s.Title, 50);
  78. recLength += strlen(s.Title);
  79. cout << "Enter Book's ID: ";
  80. cin.getline(s.ID, 9);
  81. recLength += strlen(s.ID);
  82. cout << "Enter Book's Author: ";
  83. cin.getline(s.Author, 5);
  84. recLength += strlen(s.Author);
  85. cout << "Enter Book's publisher: ";
  86. cin.getline(s.publisher, 50);
  87. recLength += strlen(s.publisher);
  88. cout << "Enter Book's Mobile: ";
  89. cin.getline(s.Mobile, 12);
  90. recLength += strlen(s.Mobile);
  91. recLength += 10;
  92. if (recLength > availSize)
  93. {
  94. file.seekp(0, ios::end);
  95. file.write((char*)& recLength, sizeof(short));
  96. short length = strlen(s.Title);
  97. file.write((char*)& length, sizeof(short));
  98. file.write((char*)& s.Title, length);
  99. length = strlen(s.ID);
  100. file.write((char*)& length, sizeof(short));
  101. file.write((char*)& s.ID, length);
  102. length = strlen(s.Author);
  103. file.write((char*)& length, sizeof(short));
  104. file.write((char*)& s.Author, length);
  105. length = strlen(s.publisher);
  106. file.write((char*)& length, sizeof(short));
  107. file.write((char*)& s.publisher, length);
  108. length = strlen(s.Mobile);
  109. file.write((char*)& length, sizeof(short));
  110. file.write((char*)& s.Mobile, length);
  111. file.close();
  112. return;
  113. }
  114. file.seekp(deleted+3, ios::beg);
  115. short next = 0;
  116. file.read((char*)&next, sizeof(short));
  117. file.seekp(0, ios::beg);
  118. file.write((char*)&next, sizeof(short));
  119. file.seekp(deleted, ios::beg);
  120. file.write((char*)& availSize, sizeof(short));
  121. short length = strlen(s.Title);
  122. file.write((char*)& length, sizeof(short));
  123. file.write((char*)& s.Title, length);
  124. length = strlen(s.ID);
  125. file.write((char*)& length, sizeof(short));
  126. file.write((char*)& s.ID, length);
  127. length = strlen(s.Author);
  128. file.write((char*)& length, sizeof(short));
  129. file.write((char*)& s.Author, length);
  130. length = strlen(s.publisher);
  131. file.write((char*)& length, sizeof(short));
  132. file.write((char*)& s.publisher, length);
  133. length = strlen(s.Mobile);
  134. file.write((char*)& length, sizeof(short));
  135. file.write((char*)& s.Mobile, length);
  136. short thisRecordOffset = file.tellp();
  137. thisRecordOffset -= recLength + 2;
  138. cout << thisRecordOffset << endl;
  139. cout << "recLength" << recLength << endl;
  140. if (availSize - recLength < 5)
  141. {
  142. while (recLength < availSize)
  143. {
  144. file.put('#');
  145. recLength++;
  146. }
  147. file.close();
  148. return;
  149. }
  150. file.seekp(deleted, ios::beg);
  151. cout << "Avail Size: " << availSize << endl;
  152. short newSize = availSize - recLength - 2;
  153. cout << newSize << endl;
  154. //******************************************
  155.  
  156. while (1)
  157. {
  158. short currOffset = file.tellg();
  159. file.read((char*)&availSize, sizeof(short));
  160. file.seekg(1, ios::cur);
  161. short nextOffset = 0;
  162. file.read((char*)&nextOffset, sizeof(short));
  163. if (nextOffset == -1) //wselt lel a5er
  164. {
  165. file.seekp(-2, ios::cur);
  166. file.write((char*)&thisRecordOffset, sizeof(short));
  167. file.seekg(thisRecordOffset, ios::beg);
  168. file.write((char*)&newSize, sizeof(short));
  169. file.put('*');
  170. short temp = -1;
  171. file.write((char*)&temp, sizeof(short));
  172. short x = 3;
  173. while (x < newSize)
  174. {
  175. file.put('#');
  176. x++;
  177. }
  178. file.write((char*)&recLength, sizeof(short));
  179. length = strlen(s.Title);
  180. file.write((char*)& length, sizeof(short));
  181. file.write((char*)& s.Title, length);
  182. length = strlen(s.ID);
  183. file.write((char*)& length, sizeof(short));
  184. file.write((char*)& s.ID, length);
  185. length = strlen(s.Author);
  186. file.write((char*)& length, sizeof(short));
  187. file.write((char*)& s.Author, length);
  188. length = strlen(s.publisher);
  189. file.write((char*)& length, sizeof(short));
  190. file.write((char*)& s.publisher, length);
  191. length = strlen(s.Mobile);
  192. file.write((char*)& length, sizeof(short));
  193. file.write((char*)& s.Mobile, length);
  194. file.close();
  195. return;
  196. }
  197. }
  198.  
  199. }
  200. */
  201. void addIntoAvail(Book s)
  202. {
  203.     fstream file("f.txt", ios::in | ios::out | ios::binary);
  204.     short deleted = 0;
  205.     file.read((char*)&deleted, sizeof(short));
  206.     if (deleted == -1) //avail list is empty
  207.     {
  208.         addBook(s);
  209.         file.close();
  210.         return;
  211.     }
  212.     file.seekg(deleted, ios::beg);
  213.     short availSize = 0;
  214.     file.read((char*)&availSize, sizeof(short));
  215.     short recLength = strlen(s.publisher) + strlen(s.Title) + strlen(s.Mobile) + strlen(s.ISBN) + strlen(s.Author) + 10;
  216.     if (recLength > availSize)
  217.     {
  218.         addBook(s);
  219.         file.close();
  220.         return;
  221.     }
  222.     file.seekp(deleted + 3, ios::beg);
  223.     short next = 0;
  224.     file.read((char*)&next, sizeof(short));
  225.     file.seekp(0, ios::beg);
  226.     file.write((char*)&next, sizeof(short));
  227.     file.seekp(deleted, ios::beg);
  228.     file.write((char*)& availSize, sizeof(short));
  229.     short length = strlen(s.Title);
  230.     file.write((char*)& length, sizeof(short));
  231.     file.write((char*)& s.Title, length);
  232.     length = strlen(s.ISBN);
  233.     file.write((char*)& length, sizeof(short));
  234.     file.write((char*)& s.ISBN, length);
  235.     length = strlen(s.Author);
  236.     file.write((char*)& length, sizeof(short));
  237.     file.write((char*)& s.Author, length);
  238.     length = strlen(s.publisher);
  239.     file.write((char*)& length, sizeof(short));
  240.     file.write((char*)& s.publisher, length);
  241.     length = strlen(s.Mobile);
  242.     file.write((char*)& length, sizeof(short));
  243.     file.write((char*)& s.Mobile, length);
  244.     short thisRecordOffset = file.tellp();
  245.     thisRecordOffset -= recLength + 2;
  246.     if (availSize - recLength < 5)
  247.     {
  248.         while (recLength < availSize)
  249.         {
  250.             file.put('#');
  251.             recLength++;
  252.         }
  253.         file.close();
  254.         cout << "Book added successfully!" << endl;
  255.         return;
  256.     }
  257.     file.seekp(deleted, ios::beg);
  258.     short newSize = availSize - recLength - 2;
  259.     //******************************************
  260.  
  261.     while (1)
  262.     {
  263.         short currOffset = file.tellg();
  264.         file.read((char*)&availSize, sizeof(short));
  265.         file.seekg(1, ios::cur);
  266.         short nextOffset = 0;
  267.         file.read((char*)&nextOffset, sizeof(short));
  268.         if (nextOffset == -1) //wselt lel a5er
  269.         {
  270.             file.seekp(-2, ios::cur);
  271.             file.write((char*)&thisRecordOffset, sizeof(short));
  272.             file.seekg(thisRecordOffset, ios::beg);
  273.             file.write((char*)&newSize, sizeof(short));
  274.             file.put('*');
  275.             short temp = -1;
  276.             file.write((char*)&temp, sizeof(short));
  277.             short x = 3;
  278.             while (x < newSize)
  279.             {
  280.                 file.put('#');
  281.                 x++;
  282.             }
  283.             file.write((char*)&recLength, sizeof(short));
  284.             length = strlen(s.Title);
  285.             file.write((char*)& length, sizeof(short));
  286.             file.write((char*)& s.Title, length);
  287.             length = strlen(s.ISBN);
  288.             file.write((char*)& length, sizeof(short));
  289.             file.write((char*)& s.ISBN, length);
  290.             length = strlen(s.Author);
  291.             file.write((char*)& length, sizeof(short));
  292.             file.write((char*)& s.Author, length);
  293.             length = strlen(s.publisher);
  294.             file.write((char*)& length, sizeof(short));
  295.             file.write((char*)& s.publisher, length);
  296.             length = strlen(s.Mobile);
  297.             file.write((char*)& length, sizeof(short));
  298.             file.write((char*)& s.Mobile, length);
  299.             file.close();
  300.             cout << "Book added successfully!" << endl;
  301.             return;
  302.         }
  303.     }
  304. }
  305. int searchFile(char ISBN[])
  306. {
  307.     short tempLength = 0;
  308.     ifstream file("f.txt");
  309.     int indexOfRecord = 0;
  310.     file.read((char*)&tempLength, sizeof(short)); //header
  311.     while (1) {
  312.         indexOfRecord = file.tellg();
  313.         file.read((char*)&tempLength, sizeof(short));
  314.         if (file.fail())
  315.             break;
  316.         char c;
  317.         file.get(c);
  318.         if (c == '*')
  319.         {
  320.             file.seekg(-1, ios::cur);
  321.             file.seekg(tempLength, ios::cur);
  322.             continue;
  323.         }
  324.         else
  325.             file.seekg(-1, ios::cur);
  326.         file.read((char*)&tempLength, sizeof(short));
  327.         file.seekg(tempLength, ios::cur);
  328.         file.read((char*)&tempLength, sizeof(short));
  329.         char tempBuf[9];
  330.         file.read((char*)&tempBuf, tempLength);
  331.         tempBuf[tempLength] = 0;
  332.         bool flag = false;
  333.         for (int i = 0; i < strlen(tempBuf); i++)
  334.         {
  335.             if (tempBuf[i] != ISBN[i])
  336.             {
  337.                 flag = true;
  338.                 break;
  339.             }
  340.         }
  341.         if (!flag)
  342.         {
  343.             file.close();
  344.             return indexOfRecord;
  345.         }
  346.         file.read((char*)&tempLength, sizeof(short));
  347.         file.seekg(tempLength, ios::cur);
  348.         file.read((char*)&tempLength, sizeof(short));
  349.         file.seekg(tempLength, ios::cur);
  350.         file.read((char*)&tempLength, sizeof(short));
  351.         file.seekg(tempLength, ios::cur);
  352.     }
  353.     file.close();
  354.     return -1;
  355.  
  356.  
  357.  
  358. }
  359. void deleteBook(char temp[])
  360. {
  361.     fstream file("f.txt", ios::in | ios::out | ios::binary);
  362.     int offset = searchFile(temp);
  363.     if (offset == -1)
  364.     {
  365.         cout << "Record not found" << endl;
  366.         file.close();
  367.         return;
  368.     }
  369.     file.seekg(offset, ios::beg);
  370.     short recSize = 0;
  371.     file.read((char*)&recSize, sizeof(short));
  372.     file.seekg(0, ios::beg);
  373.     short deleted = 0;
  374.     file.read((char*)&deleted, sizeof(short));
  375.     if (deleted == -1)
  376.     {
  377.         file.seekp(0, ios::beg);
  378.         file.write((char*)&offset, sizeof(short));
  379.         file.seekp(offset + sizeof(short), ios::beg);
  380.         file.put('*');
  381.         offset = -1;
  382.         file.write((char*)&offset, sizeof(short));
  383.         file.close();
  384.         cout << "Book deleted successfully!" << endl;
  385.         return;
  386.     }
  387.     int prev = 0;//first it's the header
  388.     while (1)
  389.     {
  390.         file.seekg(deleted, ios::beg);
  391.         short size = 0;
  392.         file.read((char*)&size, sizeof(short));
  393.         if (recSize >= size)
  394.         {
  395.             file.seekp(deleted, ios::beg);
  396.             file.seekp(prev, ios::beg);
  397.             file.write((char*)&offset, sizeof(short));
  398.             file.seekp(offset + sizeof(short), ios::beg);
  399.             file.put('*');
  400.             file.write((char*)&deleted, sizeof(short));
  401.             file.close();
  402.             cout << "Book deleted successfully!" << endl;
  403.             return;
  404.         }
  405.  
  406.         file.seekg(1, ios::cur);
  407.         prev = file.tellg();
  408.         file.read((char*)&deleted, sizeof(short));
  409.         if (deleted == -1)
  410.         {
  411.             file.seekp(-2, ios::cur);
  412.             file.write((char*)&offset, sizeof(short));
  413.             file.seekp(offset + sizeof(short), ios::beg);
  414.             file.put('*');
  415.             file.write((char*)&deleted, sizeof(short));
  416.             file.close();
  417.             cout << "Book deleted successfully!" << endl;
  418.             return;
  419.         }
  420.  
  421.     }
  422.  
  423. }
  424. void printAvailList()
  425. {
  426.     ifstream file("f.txt");
  427.     short offset = 0;
  428.     file.read((char*)&offset, sizeof(short));
  429.     cout << "Avail List: \n";
  430.     while (offset != -1)
  431.     {
  432.         cout << offset << endl;
  433.         file.seekg(offset + sizeof(short)+1, ios::beg);
  434.         file.read((char*)&offset, sizeof(short));
  435.     }
  436. }
  437. void displayBook()
  438. {
  439.     cout << "Please enter Book's ISBN: ";
  440.     char ISBN[50];
  441.     cin.getline(ISBN, 50);
  442.     ISBN[10] = 0;
  443.     int offset = searchFile(ISBN);
  444.     if (offset == -1)
  445.     {
  446.         cout << "Book not found!\n";
  447.         return;
  448.     }
  449.     ifstream file("f.txt");
  450.     file.seekg(offset, ios::beg);
  451.     short length = 0;
  452.     file.read((char*)&length, sizeof(short));
  453.     char buf[51];
  454.     file.read((char*)&length, sizeof(short));
  455.     file.read((char*)&buf, length);
  456.     buf[length] = 0;
  457.     cout << "Title: " << buf << endl;
  458.     file.read((char*)&length, sizeof(short));
  459.     file.read((char*)&buf, length);
  460.     buf[length] = 0;
  461.     cout << "ISBN: " << buf << endl;
  462.     file.read((char*)&length, sizeof(short));
  463.     file.read((char*)&buf, length);
  464.     buf[length] = 0;
  465.     cout << "Author: " << buf << endl;
  466.     file.read((char*)&length, sizeof(short));
  467.     file.read((char*)&buf, length);
  468.     buf[length] = 0;
  469.     cout << "publisher: " << buf << endl;
  470.     file.read((char*)&length, sizeof(short));
  471.     file.read((char*)&buf, length);
  472.     buf[length] = 0;
  473.     cout << "Mobile: " << buf << endl;
  474.     file.close();
  475. }
  476. void updateBook()
  477. {
  478.     cout << "Enter Book's ISBN to be updated: " << endl;
  479.     char ISBN[50];
  480.     cin.getline(ISBN, 50);
  481.     short offset = searchFile(ISBN);
  482.     if (offset == -1)
  483.     {
  484.         cout << "Book not found!" << endl;
  485.         return;
  486.     }
  487.     fstream file("f.txt", ios::out | ios::in);
  488.     file.seekg(offset, ios::beg);
  489.     short oldSize = 0;
  490.     file.read((char*)&oldSize, sizeof(short));
  491.     cout << "Enter new data: " << endl;
  492.     Book s;
  493.     cin >> s;
  494.     short recLength = strlen(s.publisher) + strlen(s.Title) + strlen(s.Mobile) + strlen(s.ISBN) + strlen(s.Author) + 10;
  495.     if (recLength == oldSize)
  496.     {
  497.         file.seekp(offset, ios::beg);
  498.         file.write((char*)& recLength, sizeof(short));
  499.         short length = strlen(s.Title);
  500.         file.write((char*)& length, sizeof(short));
  501.         file.write((char*)& s.Title, length);
  502.         length = strlen(s.ISBN);
  503.         file.write((char*)& length, sizeof(short));
  504.         file.write((char*)& s.ISBN, length);
  505.         length = strlen(s.Author);
  506.         file.write((char*)& length, sizeof(short));
  507.         file.write((char*)& s.Author, length);
  508.         length = strlen(s.publisher);
  509.         file.write((char*)& length, sizeof(short));
  510.         file.write((char*)& s.publisher, length);
  511.         length = strlen(s.Mobile);
  512.         file.write((char*)& length, sizeof(short));
  513.         file.write((char*)& s.Mobile, length);
  514.         file.close();
  515.         cout << "Book updated successfully!" << endl;
  516.         return;
  517.     }
  518.     else
  519.     {
  520.         deleteBook(ISBN);
  521.         addIntoAvail(s);
  522.         cout << "Book updated successfully!" << endl;
  523.     }
  524. }
  525. void insertDeleted(short nodeSize, short startOffset)
  526. {
  527.     short range = startOffset + nodeSize;
  528.     fstream file("f.txt", ios::in | ios::out);
  529.     short deletedOffset;
  530.     file.read((char*)&deletedOffset, sizeof(short));
  531.     if (deletedOffset == startOffset)
  532.     {
  533.         return;
  534.     }
  535.     while (deletedOffset != -1)
  536.     {
  537.         if (deletedOffset > startOffset && deletedOffset < range)
  538.         {
  539.             file.seekg(3, ios::cur);
  540.             file.read((char*)&deletedOffset, sizeof(short));
  541.             continue;
  542.         }
  543.     }
  544. }
  545. void compactAvailList()
  546. {
  547.     short header = 0;
  548.     fstream file("f.txt", ios::in | ios::out);
  549.     file.read((char*)&header, sizeof(short));
  550.     if (header == -1)
  551.     {
  552.         cout << "Nothing to be comapcted!" << endl;
  553.         return;
  554.     }
  555.     file.seekg(2, ios::beg);
  556.     short cumulativeSize = 0;
  557.     short numOfAdjacentRec = 0;
  558.     short startOffset = 0;
  559.     while (!file.fail())
  560.     {
  561.         short curSize;
  562.         file.read((char*)&curSize, sizeof(short));
  563.         if (file.fail())
  564.             break;
  565.         char c;
  566.         file.get(c);
  567.         if (c == '*' && numOfAdjacentRec == 0)
  568.         {
  569.             file.seekg(-1, ios::cur);
  570.             startOffset = file.tellg();
  571.             startOffset -= 2;
  572.             cumulativeSize += curSize;
  573.             numOfAdjacentRec++;
  574.             file.seekg(curSize, ios::cur);
  575.         }
  576.         else if (c == '*')
  577.         {
  578.             cumulativeSize += curSize;
  579.             numOfAdjacentRec++;
  580.             file.seekg(-1, ios::cur);
  581.             file.seekg(curSize, ios::cur);
  582.         }
  583.         else
  584.         {
  585.             if (numOfAdjacentRec != 0)
  586.             {
  587.                 cumulativeSize += (numOfAdjacentRec - 1) * 2; //2 bytes for each short
  588.                 file.seekg(startOffset);
  589.                 file.write((char*)&cumulativeSize, sizeof(short));
  590.                 cumulativeSize = 0;
  591.                 numOfAdjacentRec = 0;
  592.                 continue;
  593.             }
  594.             file.seekg(-1, ios::cur);
  595.             file.seekg(curSize, ios::cur);
  596.         }
  597.  
  598.     }
  599.     if (numOfAdjacentRec != 0)
  600.     {
  601.         fstream f("f.txt", ios::in | ios::out);
  602.         cumulativeSize += (numOfAdjacentRec - 1) * 2; //2 bytes for each short
  603.         f.seekp(startOffset, ios::beg);
  604.         f.write((char*)&cumulativeSize, sizeof(short));
  605.         f.close();
  606.         return;
  607.     }
  608.  
  609. }
  610. void printAllData()
  611. {
  612.     fstream file("f.txt", ios::in);
  613.     file.seekg(2, ios::beg);
  614.     while (1)
  615.     {
  616.         short length = 0;
  617.         file.read((char*)&length, sizeof(short));
  618.         if (file.fail())
  619.             return;
  620.         char c;
  621.         file.get(c);
  622.         if (c == '*')
  623.         {
  624.             file.seekg(-1, ios::cur);
  625.             file.seekg(length, ios::cur);
  626.             continue;
  627.         }
  628.         file.seekg(-1, ios::cur);
  629.         char buf[51];
  630.         file.read((char*)&length, sizeof(short));
  631.         file.read((char*)&buf, length);
  632.         buf[length] = 0;
  633.         cout << "Title: " << buf << endl;
  634.         file.read((char*)&length, sizeof(short));
  635.         file.read((char*)&buf, length);
  636.         buf[length] = 0;
  637.         cout << "ISBN: " << buf << endl;
  638.         file.read((char*)&length, sizeof(short));
  639.         file.read((char*)&buf, length);
  640.         buf[length] = 0;
  641.         cout << "Author: " << buf << endl;
  642.         file.read((char*)&length, sizeof(short));
  643.         file.read((char*)&buf, length);
  644.         buf[length] = 0;
  645.         cout << "publisher: " << buf << endl;
  646.         file.read((char*)&length, sizeof(short));
  647.         file.read((char*)&buf, length);
  648.         buf[length] = 0;
  649.         cout << "Mobile: " << buf << endl;
  650.         file.close();
  651.     }
  652. }
  653. int main()
  654. {
  655.     fstream file("f.txt", ios::trunc | ios::out | ios::binary);
  656.     short header = -1;
  657.     file.write((char*)&header, sizeof(short));
  658.     file.close();
  659.     cout << "*********************************************************\n";
  660.     cout << "\t\tBook's Management System\n";
  661.     cout << "*********************************************************\n\n";
  662.     cout << "1) Add new Book" << endl;
  663.     cout << "2) Update Book" << endl;
  664.     cout << "3) Delete Book" << endl;
  665.     cout << "4) Display Book" << endl;
  666.     cout << "5) Compact available records list" << endl;
  667.     cout << "6) Exit\n" << endl;
  668.     cout << "Please enter Your choice: ";
  669.     int choice;
  670.     while (cin >> choice)
  671.     {
  672.         cin.ignore();
  673.         if (choice == 1){
  674.             Book s;
  675.             cin >> s;
  676.             addIntoAvail(s);
  677.         }
  678.         else if (choice == 2)
  679.         {
  680.             updateBook();
  681.         }
  682.         else if (choice == 3)
  683.         {
  684.  
  685.             cout << "Enter Book's ISBN to be deleted: " << endl;
  686.             char ISBN[10];
  687.             cin.getline(ISBN, 50);
  688.             deleteBook(ISBN);
  689.         }
  690.         else if (choice == 4)
  691.             displayBook();
  692.         else if (choice == 5)
  693.         {
  694.             compactAvailList();
  695.         }
  696.         else
  697.             break;
  698.         cout << "1) Add new Book" << endl;
  699.         cout << "2) Update Book" << endl;
  700.         cout << "3) Delete Book" << endl;
  701.         cout << "4) Display Book" << endl;
  702.         cout << "5) Compact available records list" << endl;
  703.         cout << "6) Exit" << endl;
  704.         cout << "Please enter Your choice: ";
  705.     }
  706.     //printAllData();
  707.     file.open("f.txt", ios::in);
  708.     file.seekg(59, ios::beg);
  709.     file.close();
  710. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement