Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- fstream plik, config;
- string nazin, fileKey, keyConfig, ynConfig, newTab, newTabFS;
- int x, y, ynCheck;
- int showTables()
- {
- string keyConfig, coutConfig = "\n Dostępne tabele w bazie:";
- config.open("tablelist.cfg", ios::in);
- config >> ynConfig >> keyConfig;
- if (ynConfig != "1")
- {
- cout << "\n ERROR: Konfiguracja zablokowana do odczytu!\n";
- system("PAUSE");
- return 0;
- }
- if (keyConfig != ".DKTABCFGCPP")
- {
- cout << "\n ERROR: Niepoprawny format!\n";
- system("PAUSE");
- return 0;
- }
- while(!config.eof())
- {
- cout << " " << coutConfig << endl;
- config >> coutConfig;
- }
- cout << " #EOF\n";
- config.close();
- }
- int loadData()
- {
- plik.open(nazin.c_str(), ios::in);
- plik >> ynCheck;
- plik >> fileKey;
- if (ynCheck == 1)
- {
- if (fileKey == ".DKTABCPP")
- {
- plik >> x >> y;
- int tab[x][y];
- system("PAUSE");
- system("CLS");
- cout << "\n Loading data...\n";
- for (int i = 0; i<x; i++)
- {
- for (int j = 0; j<y; j++)
- {
- plik >> tab[i][j];
- cout << "Position: [" << i+1 << "][" << j+1 << "] loaded!\n";
- }
- }
- cout << " Data loaded.\n";
- for (;;)
- {
- cout << "\n 1.Edytuj otwartą tablicę.\n 2.Wyświetl otwartą tablicę.\n 3.Zapisz tablice.\n 4.Przejdz do głównego menu.\n$$: ";
- char pickOne;
- while (cin >> pickOne && pickOne != '1' && pickOne != '2' && pickOne != '3' && pickOne != '4');
- if (pickOne == '1')
- {
- int x1, y1, nValue, n;
- cout << "\n Podaj: N(ILOŚĆ ZMIAN)\n KOLEJNO: X Y NOWA_WARTOŚĆ. \n$$: ";
- cin >> n;
- if (n<=0)
- {
- cout << "\n ERROR: Nieprawidłowa wartość dla N. (N!<=0). \n";
- } else {
- for (int u = 0; u<n; u++)
- {
- cout << "$" << -(u-n) << ": ";
- cin >> x1 >> y1 >> nValue;
- x1 -= 1;
- y1 -= 1;
- if (x1 < 0 || y1 < 0 )
- {
- cout << "\n ERROR: X/Y nie mogą być mniejsze/równe \"0\"!\n";
- u--;
- } else {
- int oldValue = tab[x1][y1];
- tab[x1][y1] = nValue;
- cout << "\n INFO: Komórka: [" << x1+1 << "][" << y1+1 << "] zmieniła wartość z: \"" << oldValue << "\" na: \"" << nValue << "\".\n";
- }
- }
- }
- }
- else if (pickOne == '2')
- {
- if(plik.is_open())
- {
- cout << endl;
- for (int i = 0; i<x; i++)
- {
- for (int j = 0; j<y; j++)
- {
- cout << " " << tab[i][j];
- if (j==y-1)
- {
- cout << endl;
- }
- }
- }
- } else {
- cout << "ERROR: Żadena tablica nie jest otwarta!\n";
- }
- }
- else if (pickOne == '3')
- {
- system("CLS");
- cout << "\n Zapisywanie...\n";
- plik.close();
- plik.open(nazin.c_str(), ios::out);
- plik << ynCheck << " " << fileKey << endl << x << " "<< y << endl;
- for (int i = 0; i<x; i++)
- {
- for (int j = 0; j<y; j++)
- {
- plik << tab[i][j] << " ";
- cout << "Position: [" << i+1 << "][" << j+1 << "] with score: \"" << tab[i][j] << "\" saved!\n";
- }
- }
- plik.close();
- plik.open(nazin.c_str(), ios::in);
- cout << " INFO: Dane zapisane do pliku.\n";
- system("PAUSE");
- }
- else if (pickOne == '4')
- {
- plik.close();
- break;
- }
- }
- } else {
- cout << "\n ERROR! Niepoprawne rozszerzenie pliku!\n";
- system("PAUSE");
- }
- } else {
- cout << "\n ERROR: Wyłączona edycja. Włącz spowrotem w pliku!\n";
- system("PAUSE");
- }
- }
- int openTable()
- {
- system("CLS");
- showTables();
- cout << "\nPodaj nazwe tablicy [By wyjść - exit]:\n$$: ";
- cin >> nazin;
- if (nazin == "exit") {
- return 0;
- }
- for (;;) {
- nazin += ".txt";
- fstream exist;
- exist.open(nazin.c_str(), ios::in);
- if (exist.is_open()) {
- exist.close();
- loadData();
- break;
- } else {
- cout << " ERROR: Tablica o podanej nazwie nie istnieje. Spr\242buj ponownie:\n$$: ";
- cin >> nazin;
- }
- }
- }
- int createTable()
- {
- config.open("tablelist.cfg", ios::in);
- config >> ynConfig >> keyConfig;
- if (ynConfig != "1")
- {
- cout << "\n ERROR: Konfiguracja zablokowana do odczytu!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- if (keyConfig != ".DKTABCFGCPP")
- {
- cout << "\n ERROR: Niepoprawny format!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- config.close();
- config.open("tablelist.cfg", ios::app);
- system("CLS");
- cout << "Podaj nazwe tablicy:\n$$: ";
- cin >> newTab;
- for(;;)
- {
- fstream exist;
- newTabFS = newTab;
- newTab += ".txt";
- exist.open(newTab.c_str(), ios::in);
- if (exist.is_open()) {
- cout << "Plik o podanej nazwie już istnieje (TXT ONLY ALLOWED). Spr\242buj ponownie:\n$$: ";
- exist.close();
- cin >> newTab;
- } else {
- config << newTabFS << endl;
- config.close();
- int X, Y, xxx;
- fstream newTabb;
- newTabb.open(newTab.c_str(), ios::out);
- newTabb << "1 .DKTABCPP" << endl;
- cout << "\n Podaj: X Y i w kolejnch liniach kolejne wartości tabeli.\n$$: ";
- cin >> X >> Y;
- newTabb << X << " " << Y << endl;
- for (int i = 0; i<X; i++)
- {
- for (int j = 0; j<Y; j++)
- {
- cout << "[" << i+1 << "]" << "[" << j+1 << "]\n$$: ";
- cin >> xxx;
- newTabb << xxx << " ";
- }
- }
- system("CLS");
- cout << "\n INFO: Tablica \"" << newTab << "\" została utworzona!\n";
- system("PAUSE");
- newTabb.close();
- break;
- }
- }
- }
- int deleteTab()
- {
- system("CLS");
- showTables();
- string deletetab;
- cout << "\n Podaj nazwę tablicy do usunięcia:\n$$: ";
- cin >> deletetab;
- int change = 0;
- string keyConfig, output, read, ynConfig;
- config.open("tablelist.cfg", ios::in);
- config >> ynConfig >> keyConfig;
- if (ynConfig != "1")
- {
- cout << "\n ERROR: Konfiguracja zablokowana do odczytu!\n";
- system("PAUSE");
- return 0;
- }
- if (keyConfig != ".DKTABCFGCPP")
- {
- cout << "\n ERROR: Niepoprawny format!\n";
- system("PAUSE");
- return 0;
- }
- output += ynConfig + " " + keyConfig;
- while(!config.eof())
- {
- if (read != deletetab)
- {
- output += read + "\n";
- } else {
- change++;
- }
- config >> read;
- }
- config.close();
- if (change == 1)
- {
- deletetab += ".txt";
- config.open("tablelist.cfg", ios::in);
- config >> ynConfig >> keyConfig;
- if (ynConfig != "1")
- {
- cout << "\n ERROR: Konfiguracja zablokowana do odczytu!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- if (keyConfig != ".DKTABCFGCPP")
- {
- cout << "\n ERROR: Niepoprawny format!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- config.close();
- config.open("tablelist.cfg", ios::out);
- config << output;
- config.close();
- cout << "\n INFO: Pomyślnie usunięto tablicę: \"" << deletetab << "\".\n";
- cout << " Usunąć też plik z tablicą? [y/n]\n$$: ";
- char yndelete;
- while (cin >> yndelete && yndelete != 'y' && yndelete != 'n')
- {
- cout << "\n [y/n] Ponów próbę:\n$$: ";
- }
- if (yndelete == 'y')
- {
- if ( remove( deletetab.c_str() ) != 0 )
- {
- perror( "\n ERROR: Plik nie istnieje!" );
- } else {
- puts( "\n INFO: Plik został usunięty." );
- }
- }
- } else {
- cout << "\n ERROR: Podana tablica nie istnieje! Nie wprowadzono zmian.\n";
- }
- system("PAUSE");
- }
- int addTable()
- {
- system("CLS");
- cout << "\nPodaj nazwe tablicy do dodania [By wyjść - exit]:\n$$: ";
- cin >> nazin;
- if (nazin == "exit") {
- return 0;
- }
- string nazinFS = nazin;
- for (;;) {
- int X = 0, Y = 0;
- nazin += ".txt";
- fstream exist;
- exist.open(nazin.c_str(), ios::in);
- if (exist.is_open()) {
- exist.close();
- plik.open(nazin.c_str(), ios::in);
- plik >> ynCheck >> fileKey >> X >> Y;
- if (ynCheck == 1 && fileKey == ".DKTABCPP" && X != 0 && Y != 0)
- {
- config.open("tablelist.cfg", ios::in);
- config >> ynConfig >> keyConfig;
- if (ynConfig != "1")
- {
- cout << "\n ERROR: Konfiguracja zablokowana do odczytu!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- if (keyConfig != ".DKTABCFGCPP")
- {
- cout << "\n ERROR: Niepoprawny format!\n";
- system("PAUSE");
- config.close();
- return 0;
- }
- config.close();
- config.open("tablelist.cfg", ios::app);
- config << nazinFS << endl;
- config.close();
- cout << "\n INFO: Pomyślnie dodano tablice do bazy!\n";
- break;
- } else {
- cout << "\n ERROR: Tablica nie może być dodana! Zły format.\n";
- }
- } else {
- cout << " ERROR: Tablica o podanej nazwie nie istnieje. Spr\242buj ponownie:\n$$: ";
- cin >> nazin;
- }
- }
- system("PAUSE");
- }
- int main()
- {
- setlocale(LC_ALL, "polish");
- fstream exist;
- exist.open("tablelist.cfg", ios::in);
- if (exist.is_open()) {
- exist.close();
- } else {
- config.open("tablelist.cfg", ios::out);
- config << "1 .DKTABCFGCPP" << endl;
- config.close();
- }
- for (;;)
- {
- system("CLS");
- cout << "Witaj w menedzerze tablicą z danymi. Wybierz opcje:\n 1.Otwórz istniejącą tablice.\n 2.Stwórz nową tablice.\n 3.Usuń tablicę.\n 4.Wyświetl zapisane tablice.\n 5.Dodaj tablicę z pliku.\nCreated By Damian Kreński\n$$: ";
- char chose;
- while ( cin >> chose && chose != '1' && chose != '2' && chose != '3' && chose != '4' && chose != '5' );
- if (chose == '1')
- {
- openTable();
- }
- else if (chose == '2')
- {
- createTable();
- }
- else if (chose == '3')
- {
- deleteTab();
- }
- else if (chose == '4')
- {
- showTables();
- system("PAUSE");
- }
- else if (chose == '5')
- {
- addTable();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement