Skip to content

Commit

Permalink
A new convenient menu has been developed
Browse files Browse the repository at this point in the history
Redesigned:
    - all output functions
  • Loading branch information
git-user-cpp authored Jun 6, 2022
1 parent ccb05d1 commit e36e97c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 70 deletions.
32 changes: 23 additions & 9 deletions Translator/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ void saveData(std::vector<Word> &words, const std::string &file_name)
}
else
{
std::cout << "Error(file recording)" << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Error(file recording) |" << std::endl
<< "|_____________________________________________________________|" << std::endl;
}

std::cout << "Data is recorded" << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Data is recorded |" << std::endl
<< "|_____________________________________________________________|" << std::endl;
}

//to read data from file to vector
Expand Down Expand Up @@ -85,10 +89,14 @@ void readData(std::vector<Word> &words, const std::string &file_name)
}
else
{
std::cout << "Error(file reading)" << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Error(file reading) |" << std::endl
<< "|_____________________________________________________________|" << std::endl;
}

std::cout << "Data is red" << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Data is red |" << std::endl
<< "|_____________________________________________________________|" << std::endl;
}

//function for test mode
Expand All @@ -97,11 +105,13 @@ void test(std::vector<Word> &words)
std::string answer;
int score = 0;

std::cout << " _____________________________________________________________" << std::endl;

for(auto &element : words)
{
std::cout << "Write a word on English: ";
std::cout << "| Write a word on English: ";
std::cout << element.Get_translation() << std::endl;
std::cout << "Your answer: ";
std::cout << "| Your answer: ";
getline(std::cin, answer);

//lambda function for evaluation
Expand All @@ -115,17 +125,21 @@ void test(std::vector<Word> &words)
result(); //calling the lambda function
}

std::cout << "========================================================================" << std::endl;
std::cout << "|_____________________________________________________________" << std::endl;

//derivation of the general estimation
std::cout << "Your mark is: " << score << "/" << words.capacity() << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Your mark is: " << score << "/" << words.capacity() << std::endl
<< "|_____________________________________________________________" << std::endl;
}

//output data from the vector
void readFile(std::vector<Word> &words)
{
std::cout << " _____________________________________________________________" << std::endl;
for(auto &element : words)
{
std::cout << element.Get_word() << " " << element.Get_translation() << std::endl;
std::cout << "| " << element.Get_word() << "\t-->\t" << element.Get_translation() << std::endl;
}
std::cout << "|_____________________________________________________________" << std::endl;
}
113 changes: 52 additions & 61 deletions Translator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ std::string menu_str;
//main menu function
void Menu()
{
std::cout << "Choose option:" << std::endl
<< "1) Start test" << std::endl
<< "2) Entry new words" << std::endl
<< "3) Read the words" << std::endl
<< "4) Info about the creator and license" << std::endl
<< "0) Exit" << std::endl
<< "Your choise: ";
std::cout << " _____________________________________________________________" << std::endl
<< "| Choose option: |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< "| [1] Start test |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< "| [2] Entry new words |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< "| [3] Read the words |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< "| [4] Info about the creator and license |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< "| [0] Exit |" << std::endl
<< "|_____________________________________________________________|" << std::endl
<< " _____________________________________________________________ " << std::endl
<< " Your choise: ";

getline(std::cin, menu_str);
std::stringstream(menu_str) >> menu; //using stringstream to avoid the cin.ignore(); command
Expand All @@ -54,7 +62,7 @@ int main()
std::string bufer2;
std::string fileName;
std::vector<Word> dataBase;
std::string doubleDelimiter = "========================================================================";
std::string delimiter = "|_____________________________________________________________|\n";

srand(time(NULL)); //for using the random_shuffle() algorithm

Expand All @@ -65,15 +73,15 @@ int main()
{
//testing case
case 1:
std::cout << doubleDelimiter << std::endl;
std::cout << delimiter << std::endl;

std::cout << "Enter a file name for test (format: name.txt): ";
std::cout << " _____________________________________________________________" << std::endl
<< "| Enter a file name for test (format: name.txt): ";
getline(std::cin, fileName);
std::cout << "|_____________________________________________________________" << std::endl;

readData(dataBase, fileName); //entering data from a file into a vector

std::cout << doubleDelimiter << std::endl;

dataBase.shrink_to_fit(); //changing the size of the vector to the actual size of its capacity

#ifdef testing
Expand Down Expand Up @@ -102,8 +110,6 @@ int main()

test(dataBase); //start the test

std::cout << doubleDelimiter << std::endl;

dataBase.clear(); //deleting each vector element
dataBase.shrink_to_fit(); //changing the size of the vector to the actual size of its capacity

Expand All @@ -123,32 +129,34 @@ int main()
break;

case 2:
std::cout << doubleDelimiter << std::endl;

std::cout << "Enter a name to new file (format: name.txt): ";
std::cout << delimiter << std::endl;

std::cout << " _____________________________________________________________" << std::endl
<< "| Enter a name to new file (format: name.txt): ";
getline(std::cin, fileName);
std::cout << "|_____________________________________________________________" << std::endl;

std::cout << "Enter a number of words to emplace: ";
std::cout << " _____________________________________________________________" << std::endl
<< "| Enter a number of words to emplace: ";
getline(std::cin, action_str);
std::cout << "|_____________________________________________________________" << std::endl;
std::stringstream(action_str) >> action;

std::cout << doubleDelimiter << std::endl;

for(int i = 0; i < action; i++) //entering new words(depends on the number)
{
std::cout << "Enter a new word: ";
std::cout << " _____________________________________________________________" << std::endl
<< "| Enter a new word: ";
getline(std::cin, bufer1);
std::cout << "Enter translation for this word: ";
std::cout << "| Enter translation for this word: ";
getline(std::cin, bufer2);
std::cout << "|_____________________________________________________________" << std::endl;

new_word.DataEntry(bufer1, bufer2);

dataBase.push_back(new_word);
}

saveData(dataBase, fileName); //saving data into a file

std::cout << doubleDelimiter << std::endl;

dataBase.clear(); //deleting each vector element
dataBase.shrink_to_fit(); //changing the size of the vector to the actual size of its capacity
Expand All @@ -169,10 +177,12 @@ int main()
break;

case 3:
std::cout << doubleDelimiter << std::endl;
std::cout << delimiter << std::endl;

std::cout << "Enter a file name for reading (format: name.txt): ";
std::cout << " _____________________________________________________________" << std::endl
<< "| Enter a file name for reading (format: name.txt): ";
getline(std::cin, fileName);
std::cout << "|_____________________________________________________________" << std::endl;

readData(dataBase, fileName); //entering data from a file into a vector

Expand All @@ -188,12 +198,8 @@ int main()

#endif

std::cout << doubleDelimiter << std::endl;

readFile(dataBase); //output each element

std::cout << doubleDelimiter << std::endl;

dataBase.clear(); //deleting each vector element
dataBase.shrink_to_fit(); //changing the size of the vector to the actual size of its capacity

Expand All @@ -213,48 +219,33 @@ int main()
break;

case 4:
std::cout << doubleDelimiter << std::endl << std::endl
<< "---> Creator of this program: git-user-cpp (m!haly4) <---" << std::endl << std::endl
<< "---> Link: https://github.com/git-user-cpp <---" << std::endl << std::endl
<< doubleDelimiter << std::endl << std::endl

<< "MIT License\n\n"

<< "Copyright (c) 2022 m!haly4\n\n"

<< "Permission is hereby granted, free of charge, to any person obtaining a copy\n"
<< "of this software and associated documentation files (the \"Software\"), to deal\n"
<< "in the Software without restriction, including without limitation the rights\n"
<< "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
<< "copies of the Software, and to permit persons to whom the Software is\n"
<< "furnished to do so, subject to the following conditions:\n\n"

<< "The above copyright notice and this permission notice shall be included in all\n"
<< "copies or substantial portions of the Software.\n\n"

<< "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
<< "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
<< "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
<< "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
<< "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
<< "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
<< "SOFTWARE. "
<< std::endl << std::endl
<< doubleDelimiter << std::endl;
std::cout << delimiter << std::endl << std::endl
<< " _____________________________________________________________" << std::endl
<< "| ---> Creator of this program: git-user-cpp (m!haly4) <---" << std::endl
<< "|_____________________________________________________________" << std::endl
<< "| ---> Link: https://github.com/git-user-cpp <---" << std::endl
<< "|_____________________________________________________________" << std::endl
<< "| ---> License: https://github.com/git-user-cpp/translation_training/blob/main/LICENSE <---" << std::endl
<< "|_____________________________________________________________" << std::endl
<< std::endl << std::endl;

Menu();
break;

default:
std::cout << "Error" << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| Error: Invalid input |" << std::endl
<< "|_____________________________________________________________|" << std::endl;

Menu();
break;
}
}

std::cout << doubleDelimiter << std::endl;
std::cout << "The programm is stopped" << std::endl;
std::cout << delimiter << std::endl;
std::cout << " _____________________________________________________________" << std::endl
<< "| The programm is stopped |" << std::endl
<< "|_____________________________________________________________|" << std::endl;

return 0;
}

0 comments on commit e36e97c

Please sign in to comment.