Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. // Lab 1 Eshaghzadeh, Mathew T TH
  2.  
  3. #include <iostream>
  4. #include <fstream> // File stream: fstream
  5. #include <cstdlib> // die
  6. #include <string>
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. class Inventory {
  11. public:
  12. //Inventory(int number); // ctor
  13. void showMenu();
  14. void inventoryUnsorted(Inventory object, string line);
  15. //accessor
  16. //mutator
  17. // Make a function that reads the file
  18. private:
  19. int _number;
  20. int _ID;
  21. string _name;
  22. };
  23.  
  24. bool die(const string & msg);
  25. void readUnsortedArray(int ar[], int size);
  26.  
  27. // IMPORTANT
  28. // The point of this program is to extract all the content of the txt file and inserting it into an array.
  29. int main() {
  30. fstream Menu; // Menu is of type fStream (file) <-- Read & Write
  31. int choice;
  32. string line;
  33. Inventory record;
  34. const int arrsize = 10;
  35. int arr[arrsize];
  36.  
  37.  
  38. Menu.open("Menu.txt"); // Opening txt file
  39. /*
  40. int i = 0;
  41. Menu >> arr[i];
  42. while (!Menu.eof()) {
  43. i++;
  44. if (Menu.eof()) break;
  45. }
  46. */
  47.  
  48.  
  49.  
  50. do {
  51. record.showMenu(); //cout
  52. cin >> choice;
  53. cout << endl;
  54.  
  55. switch (choice) {
  56. case 1: // Inventory Unsorted
  57. /*while (getline(Menu, line)) {
  58. cout << line << endl;
  59. }
  60. cout << endl;
  61. */
  62. readUnsortedArray(arr, arrsize, Menu);
  63.  
  64.  
  65. case 2: // Inventory Sorted
  66.  
  67. case 3: // Search for an Item by ID or name
  68.  
  69. case 4: // Print Results
  70.  
  71. case 5: break;
  72. }
  73.  
  74.  
  75.  
  76. } while (choice != 5);
  77.  
  78.  
  79.  
  80. Menu.close(); // Closes the file
  81. }
  82.  
  83. bool die(const string & msg) {
  84. cout << "Fatal error: " << msg << endl;
  85. exit(EXIT_FAILURE);
  86. }
  87.  
  88. void Inventory::showMenu() {
  89. cout << "Menu: " << endl;
  90. cout << "1: Print the Inventory Unsorted " << endl;
  91. cout << "2: Print the Inventory Sorted (In ascending order) " << endl;
  92. cout << "3: Search for an item by ID or name " << endl;
  93. cout << "4: Print report " << endl;
  94. cout << "5: Quit " << endl << endl;
  95. cout << "Enter a number: ";
  96. }
  97.  
  98. void readUnsortedArray(int ar[], int size, fstream file) {
  99. int i = 0;
  100. while (i < size && file >> ar[i]) {
  101. i++;
  102. if (!ar[i]) break;
  103. cout << ar[i] << " ,";
  104. }
  105. }
  106.  
  107. void Inventory::inventoryUnsorted(Inventory object, string line) {
  108. /*int count;
  109. for (int i = 0; i < count; i++)
  110. {
  111.  
  112. }
  113.  
  114. while () {
  115. cout << line << endl;
  116. }
  117. cout << endl;
  118. */
  119.  
  120.  
  121. }
  122.  
  123. //Inventory::Inventory(int number) {}
  124.  
  125. /*
  126. Notes:
  127. Menu << "Writing this to a file.\n"; // Writes this to txt file
  128.  
  129.  
  130. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement