Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ISf-17/1, Pavel Trostianko. Stack controller (1.0).
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <windows.h>
- #include <cstdlib>
- using namespace std;
- int amount, stck[1000], add_a, rem_a, exmpl; //how many items are in the stack
- bool menu_check = 0;
- string pasirinkitefaila; //for ifstream to work with our text files
- void File() //enter the name of our file
- {
- //We specify the path to our text file
- cout << "Please specify the path to text file with your stack.\n";
- cout << "Text: ";
- getline (cin, pasirinkitefaila);
- ifstream fin(pasirinkitefaila.c_str());
- }
- void Checking() //Through this function, we check whether the file is empty
- {
- Sleep(1000);
- int length = 0, a; //variable for writing length of file
- cout << "\nChecking...\n\n";
- ifstream fin(pasirinkitefaila.c_str()); //read the text file of the stack
- fin.open(pasirinkitefaila.c_str(), ios::binary); //open file to read it
- fin.seekg(0, ios::end);
- length = fin.tellg(); //Characters number
- Sleep(3000);
- if(length == 0) //if empty
- {
- cout<<"Error! File is empty!\n"; //error
- File();
- }
- else //if not
- {
- cout<<"File exist!\n";
- }
- fin.close();
- }
- void StackScan()
- {
- ifstream fin(pasirinkitefaila.c_str());
- Sleep(1500);
- cout << "\nReading our stack...\n\n";
- Sleep(3000);
- fin >> amount;
- for(int i=0;i<amount;i++)
- {
- fin >> stck[i];
- }
- }
- void StackShow()
- {
- cout << "\n\t\tOur stack right now:\n\n";
- for(int z=0;z<amount;z++)
- {
- if(z==0)
- {
- cout << "Number of elements in our stack: " << stck[z] << endl;
- cout << "Our stack elements : " << endl;
- }
- else
- {
- cout << stck[z] << " ";
- }
- }
- cout << "\n";
- }
- void AddItems()
- {
- Sleep(1500);
- cout << "\nAdding elements to stack\n\n";
- Sleep(1500);
- cout << "How many elements yo want to add? : ";
- cin >> add_a;
- Sleep(1500);
- cout << "\nnow you can add your elements:\n";
- for(int q=0;q<add_a;q++)
- {
- cin >> stck[amount+q];
- }
- amount += add_a;
- Sleep(2000);
- StackShow();
- }
- void RemoveItems()
- {
- Sleep(1500);
- cout << "\nRemoving elements from stack\n\n";
- Sleep(1500);
- cout << "How many elements yo want to remove? : ";
- cin >> rem_a;
- Sleep(1000);
- cout << "\nRemoving elements...\n";
- Sleep(3000);
- for(int l=0;l<rem_a;l++)
- {
- stck[amount+l] = 0;
- }
- amount -= rem_a;
- Sleep(2000);
- StackShow();
- }
- void Menu()
- {
- Sleep(4000);
- int x;
- if(menu_check == 0)
- {
- cout << "\n\t\tWelcome! This is controller Menu!\n\n";
- menu_check = 1;
- }
- else
- {
- cout << "\n\t\tWelcome back to the menu!\n\n";
- }
- Sleep(1000);
- cout<<"\nPress 0 to add items, press 1 to remove items: ";
- cin >> x;
- if(x == 0)
- {
- AddItems();
- }
- else
- {
- RemoveItems();
- }
- }
- int main()
- {
- Sleep(3000);
- cout << "\n\t\tWelcome to Stack controller (1.0)!\n\n";
- Sleep(3000);
- //enter the name of our file
- File();
- //We check if the stack is empty, through the function Checking
- Checking();
- //Our stack and work with it
- StackScan();
- StackShow(); //Showing our stack first time
- //Menu for managing our program
- Menu();
- Menu();
- Menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement