Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lab 1 Eshaghzadeh, Mathew T TH
- #include <iostream>
- #include <fstream> // File stream: fstream
- #include <cstdlib> // die
- #include <string>
- #include <iomanip>
- using namespace std;
- class Inventory {
- public:
- //Inventory(int number); // ctor
- void showMenu();
- void inventoryUnsorted(Inventory object, string line);
- //accessor
- //mutator
- // Make a function that reads the file
- private:
- int _number;
- int _ID;
- string _name;
- };
- bool die(const string & msg);
- void readUnsortedArray(int ar[], int size);
- // IMPORTANT
- // The point of this program is to extract all the content of the txt file and inserting it into an array.
- int main() {
- fstream Menu; // Menu is of type fStream (file) <-- Read & Write
- int choice;
- string line;
- Inventory record;
- const int arrsize = 10;
- int arr[arrsize];
- Menu.open("Menu.txt"); // Opening txt file
- /*
- int i = 0;
- Menu >> arr[i];
- while (!Menu.eof()) {
- i++;
- if (Menu.eof()) break;
- }
- */
- do {
- record.showMenu(); //cout
- cin >> choice;
- cout << endl;
- switch (choice) {
- case 1: // Inventory Unsorted
- /*while (getline(Menu, line)) {
- cout << line << endl;
- }
- cout << endl;
- */
- readUnsortedArray(arr, arrsize, Menu);
- case 2: // Inventory Sorted
- case 3: // Search for an Item by ID or name
- case 4: // Print Results
- case 5: break;
- }
- } while (choice != 5);
- Menu.close(); // Closes the file
- }
- bool die(const string & msg) {
- cout << "Fatal error: " << msg << endl;
- exit(EXIT_FAILURE);
- }
- void Inventory::showMenu() {
- cout << "Menu: " << endl;
- cout << "1: Print the Inventory Unsorted " << endl;
- cout << "2: Print the Inventory Sorted (In ascending order) " << endl;
- cout << "3: Search for an item by ID or name " << endl;
- cout << "4: Print report " << endl;
- cout << "5: Quit " << endl << endl;
- cout << "Enter a number: ";
- }
- void readUnsortedArray(int ar[], int size, fstream file) {
- int i = 0;
- while (i < size && file >> ar[i]) {
- i++;
- if (!ar[i]) break;
- cout << ar[i] << " ,";
- }
- }
- void Inventory::inventoryUnsorted(Inventory object, string line) {
- /*int count;
- for (int i = 0; i < count; i++)
- {
- }
- while () {
- cout << line << endl;
- }
- cout << endl;
- */
- }
- //Inventory::Inventory(int number) {}
- /*
- Notes:
- Menu << "Writing this to a file.\n"; // Writes this to txt file
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement