Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- #include <cstdlib>
- #define Row 8
- #define Column 10
- using namespace std;
- string FileName = "Null", excel[Column * Row], Text, Space, Token, Saveas, CopyExcel[10], Temp[10], UndoTile[80], UnCE[10], temp[8], SaveFile, Line, Savedata, LoadName, LoadTile[80];
- int WordLength, TileNum, DelTile1, DelTile2, CopyTile1, CopyTile2, FileAmount = 0, Largest, TempNum;
- char Choice;
- void Choose(), Menu(), New(), Insert(), Delete(), Overwrite(), Load(), Save(), Copy(), Clipboard(), Cut(), Paste(), Find(), Undo(), BeforeUndo();
- int main()
- {
- cout << "*============================================" << endl << endl;
- cout << "File Name : Null" << endl << endl;
- Choose();
- for (int i = 0; i < 80; i++) //put all " " element in array
- {
- excel[i] = " ";
- }
- Insert();
- system("pause");
- return 0;
- }
- void Choose()
- {
- cout << "[N]ew, [I}nsert, [D]elete, [O]verwrite, [L]oad, [S]save," << endl
- << "[C]opy, show - clip[B]oard, [X]cut, [P]aste, [F]ind, [U]ndo, [E]nd" << endl
- << "==>";
- cin >> Choice;
- char convert = (toupper(Choice)); //convert lowercase to uppercase
- while (cin.fail()) //avoid error input
- {
- cin.clear();
- cin.ignore();
- cout << "Invalid input, please enter again." << endl << endl
- << "*============================================"
- << endl << endl
- << "[N]ew, [I}nsert, [D]elete, [O]verwrite, [L]oad, [S]save," << endl
- << "[C]opy, show - clip[B]oard, [X]cut, [P]aste, [F]ind, [U]ndo, [E]nd " << endl
- << "==>";
- cin >> Choice;
- }
- switch (convert)
- {
- case 'N':
- New();
- Choose();
- break;
- case 'I':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Insert();
- Menu();
- Choose();
- break;
- case 'D':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Delete();
- Menu();
- Choose();
- break;
- case 'O':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Overwrite();
- Menu();
- Choose();
- break;
- case 'C':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Copy();
- Menu();
- Choose();
- break;
- case 'B':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- Clipboard();
- Choose();
- break;
- case 'X':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Cut();
- Menu();
- Choose();
- break;
- case 'P':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- BeforeUndo();
- Paste();
- Menu();
- Choose();
- break;
- case 'F':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- Find();
- Menu();
- Choose();
- break;
- case 'U':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- Undo();
- Menu();
- Choose();
- break;
- case 'S':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- Save();
- Menu();
- Choose();
- break;
- case 'L':
- if (FileName == "Null")
- {
- cout << "Please create a new file first." << endl;
- Choose();
- }
- Load();
- Menu();
- Choose();
- break;
- case 'E':
- exit(0);
- break;
- default:
- cout << "Enter again." << endl;
- Choose();
- }
- }
- void Menu()
- {
- for (int j = 0; j < 8; j++)
- {
- TempNum = 0;
- for (int i = j; i< 80; i+=8)
- {
- Largest = excel[i].length();
- if (Largest >= TempNum)
- {
- temp[j] = excel[i];
- TempNum = Largest;
- }
- }
- }
- cout << endl << "------------------------ new screen ------------------------" << endl;
- cout << endl << "File Name: " << FileName << endl;
- cout << "|----"; //1st line
- for (int i = 0; i < 8;i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength+2, '-');
- }
- cout << "|" << endl;
- cout << "| |";//2nd line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << " " << i + 1 << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//3rd line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 00 |";//4th line
- for (int i = 0; i < 8; i++)
- {
- int Longest = temp[i].length();
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//5th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 08 |";//6th line
- int j = 0;
- for (int i = 8; i < 16; i++)
- {
- int Longest = temp[j].length();
- j++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//7th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 16 |";//8th line
- int a = 0;
- for (int i = 16; i < 24; i++)
- {
- int Longest = temp[a].length();
- a++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//9th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 24 |";//10th line
- int b = 0;
- for (int i = 24; i < 32; i++)
- {
- int Longest = temp[b].length();
- b++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//11th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 32 |";//12th line
- int c = 0;
- for (int i = 32; i < 40; i++)
- {
- int Longest = temp[c].length();
- c++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//13th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 40 |";//14th line
- int d = 0;
- for (int i = 40; i < 48; i++)
- {
- int Longest = temp[d].length();
- d++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//15th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 48 |";//16th line
- int e = 0;
- for (int i = 48; i < 56; i++)
- {
- int Longest = temp[e].length();
- e++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//17th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 56 |";//18th line
- int f = 0;
- for (int i = 56; i < 64; i++)
- {
- int Longest = temp[f].length();
- f++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//19th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 64 |";//20th line
- int g = 0;
- for (int i = 64; i < 72; i++)
- {
- int Longest = temp[g].length();
- g++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//21th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << "| 72 |";//22th line
- int h=0;
- for (int i = 72; i < 80; i++)
- {
- int Longest = temp[h].length();
- h++;
- int Short = excel[i].length();
- if (excel[i] == "")
- {
- excel[i] = " ";
- }
- WordLength = Longest - Short +1;
- cout << " " << excel[i] << string(WordLength, ' ') << "|";
- }
- cout << endl << "|----";//23th line
- for (int i = 0; i < 8; i++)
- {
- WordLength = temp[i].length();
- if (WordLength == 0)
- {
- WordLength = 1;
- }
- cout << "+" << string(WordLength + 2, '-');
- }
- cout << "|";
- cout << endl << endl;
- }
- void New()
- {
- cout << "New file name ==> ";
- cin >> FileName;
- if (FileName == "Null")
- {
- cout << "Your file name cannot be Null, please create as another file name." << endl;
- Choose();
- }
- for (int i = 0; i < 80; i++) //reset array to blank array
- {
- excel[i] = " ";
- }
- Menu();
- Choose();
- }
- void Insert()
- {
- cout << "Tile Number ==> ";
- cin >> TileNum;
- cout << "Text ==> ";
- cin.ignore();
- getline(cin,Text);
- Space = " ";
- if (excel[TileNum-1] != " ")
- {
- for (int i = 0; i < 10; i++)
- {
- Temp[i] = " ";
- }
- int i = 0;
- size_t pos = 0;
- while ((pos = Text.find(Space)) != string::npos)
- {
- Token = Text.substr(0, pos);
- Temp[i] = Token;
- i++;
- Text.erase(0, pos + Space.length());
- }
- for (int i = 68; i >= (TileNum-1); i--)
- {
- excel[i+11] = excel[i];
- excel[i] = " ";
- }
- for (int i = 0; i < 10; i++)
- {
- excel[TileNum-1] = Temp[i];
- TileNum ++;
- }
- }
- size_t pos = 0;
- Text = Text+" ";
- while ((pos = Text.find(Space)) != string::npos) //(while space is not found will return string::npos, so when found it will not return string::npos)//
- {
- Token = Text.substr(0, pos);//Text.substr(position, length), example: Text = "abc def ghi" , 0 is a, 1 is b. until the length of the abc is 3//
- excel[TileNum-1] = Token;
- TileNum = TileNum +1;
- Text.erase(0, pos + Space.length());//erase from the first position to the size of word + a space//
- }
- for (int i= 0; i<78; i++)
- {
- for(int j = i+1; j<80;j++)
- {
- if ((excel[i] == " ") && (excel[j]!=" "))
- {
- excel [i] = excel[j];
- excel[j] = " ";
- break;
- }
- }
- }
- }
- void Delete()
- {
- cout << "From Tile Number == > ";
- cin >> DelTile1;
- cout << "To Tile Number == > ";
- cin >> DelTile2;
- for (int i = DelTile1-1; i < DelTile2; i++)
- {
- excel[i] = " ";
- }
- for (int i= 0; i<78; i++)
- {
- for(int j = i+1; j<80;j++)
- {
- if ((excel[i] == " ") && (excel[j]!=" "))
- {
- excel [i] = excel[j];
- excel[j] = " ";
- break;
- }
- }
- }
- }
- void Overwrite()
- {
- cout << "Tile Number ==> ";
- cin >> TileNum;
- cout << "Text ==> ";
- cin.ignore();
- getline(cin,Text);
- Space = " ";
- size_t pos = 0;
- Text = Text+" ";
- while ((pos = Text.find(Space)) != string::npos)
- {
- Token = Text.substr(0, pos);
- excel[TileNum-1] = Token;
- TileNum = TileNum +1;
- Text.erase(0, pos + Space.length());
- }
- for (int i= 0; i<78; i++)
- {
- for(int j = i+1; j<80;j++)
- {
- if ((excel[i] == " ") && (excel[j]!=" "))
- {
- excel [i] = excel[j];
- excel[j] = " ";
- break;
- }
- }
- }
- }
- void Load()
- {
- for (int i=0; i<80; i++)
- {
- LoadTile[i] = " ";
- }
- cout << "File name ==>" ;
- cin.ignore();
- getline(cin,LoadName);
- LoadName = LoadName+".txt";
- ifstream Read(LoadName.c_str());
- if (Read.is_open())
- {
- Read.ignore();
- (getline(Read,Line));
- Read.close();
- }
- else
- {
- cout << "No File Loaded.";
- }
- Space = " ";
- int i = 0;
- size_t pos = 0;
- while ((pos = Line.find(Space)) != string::npos)
- {
- Token = Line.substr(0, pos);
- LoadTile[i] = Token;
- i++;
- Line.erase(0, pos + Space.length());
- }
- for (int i = 0; i<80; i++)
- {
- excel[i] = LoadTile[i];
- }
- }
- void Save()
- {
- cout << "File name (enter= "+FileName+".txt) ==> ";
- cin.ignore();
- getline(cin,SaveFile);
- cout << "File saved."<<endl;
- if (SaveFile.empty())
- {
- SaveFile = FileName;
- cout << "File saved."<<endl;
- }
- SaveFile = SaveFile+".txt";
- ofstream Create(SaveFile.c_str());
- for (int i = 0; i < 80; i++)
- {
- Saveas = Saveas + excel[i]+" ";
- }
- Create << Saveas <<endl;
- Create.close();
- }
- void Copy()
- {
- for (int i = 0; i < 10; i++)
- {
- CopyExcel[i] = " ";
- }
- cout << "From Tile Number == > ";
- cin >> CopyTile1;
- cout << "To Tile Number == > ";
- cin >> CopyTile2;
- if (CopyTile2 - CopyTile1 > 10)
- {
- cout << "You can only copy 10 words" <<endl;
- Choose();
- }
- int j = 0;
- for (int i = CopyTile1-1; i < CopyTile2; i++)
- {
- CopyExcel[j]= excel[i];
- j++;
- }
- }
- void Clipboard()
- {
- cout << "Clipboard : " << endl;
- for (int i = 0 ; i < 10; i++)
- {
- cout << CopyExcel[i] << " ";
- }
- cout << endl << endl
- << "------------------------ new screen ------------------------"
- <<endl << endl;
- }
- void Cut()
- {
- for (int i = 0; i < 10; i++)
- {
- CopyExcel[i] = " ";
- }
- cout << "From Tile Number == > ";
- cin >> CopyTile1;
- cout << "To Tile Number == > ";
- cin >> CopyTile2;
- if (CopyTile2 - CopyTile1 > 10)
- {
- cout << "You can only cut 10 words" <<endl;
- Choose();
- }
- int j = 0;
- for (int i = CopyTile1-1; i < CopyTile2; i++)
- {
- CopyExcel[j]= excel[i];
- j++;
- }
- for (int i = CopyTile1-1; i < CopyTile2; i++)
- {
- excel[i] = " ";
- }
- for (int i= 0; i<78; i++)
- {
- for(int j = i+1; j<80;j++)
- {
- if ((excel[i] == " ") && (excel[j]!=" "))
- {
- excel [i] = excel[j];
- excel[j] = " ";
- break;
- }
- }
- }
- }
- void Paste()
- {
- cout << "Tile Number ==> ";
- cin >> TileNum;
- for (int i = 68; i >= (TileNum-1); i--)
- {
- excel[i+11] = excel[i];
- excel[i] = " ";
- }
- for (int i = 0; i < 10; i++)
- {
- excel[TileNum-1] = CopyExcel[i];
- TileNum ++;
- }
- for (int i= 0; i<78; i++)
- {
- for(int j = i+1; j<80;j++)
- {
- if ((excel[i] == " ") && (excel[j]!=" "))
- {
- excel [i] = excel[j];
- excel[j] = " ";
- break;
- }
- }
- }
- }
- void Find()
- {
- cout << "Enter text to find : ";
- cin >> Text;
- for(int i = 0; i < 80; i++)
- {
- if (Text == excel[i])
- {
- excel[i] = "*"+excel[i]+"*";
- }
- }
- }
- void BeforeUndo()
- {
- for (int i = 0; i <10; i++)
- {
- UnCE[i] = CopyExcel[i];
- }
- for (int i=0; i<80 ; i++)
- {
- UndoTile[i] = excel[i];
- }
- }
- void Undo()
- {
- for (int i = 0; i<10;i++)
- {
- CopyExcel[i] = UnCE[i];
- }
- for (int i=0; i<80 ; i++)
- {
- excel[i] = UndoTile[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement