Text Practice Mode
Only for pro players!!
created Yesterday, 04:23 by Anshul Kumar
1
621 words
1 completed
0
Rating visible after 3 or more votes
saving score / loading statistics ...
00:00
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
// Function to print color text
void printColor(const string &text, const string &color) {
if (color == "blue") cout << "\033[1;34m" << text << "\033[0m";
else if (color == "green") cout << "\033[1;32m" << text << "\033[0m";
else if (color == "yellow") cout << "\033[1;33m" << text << "\033[0m";
else if (color == "red") cout << "\033[1;31m" << text << "\033[0m";
else cout << text;
}
// CodeSnippet structure
struct CodeSnippet {
string heading;
string explanation;
vector<string> codeLines;
vector<string> lineExplain;
};
class WordPool {
public:
vector<string> words;
WordPool() {
words = {
"int","float","double","if","else","for","while","class",
"public","private","protected","virtual","override","friend",
"+","-","*","/","%","&&","||","==","!=","<",">",
"{","}","(",")","[","]","::","->","<<",">>", ";",
// ... Expand this list up to 1000 words
};
}
string getRandomWord() {
return words[rand() % words.size()];
}
};
class LearningTutor {
vector<CodeSnippet> snippets;
public:
LearningTutor() {
addArrayExample();
addLoopExample();
addFunctionExample();
// Add 20+ such examples here
}
void addArrayExample() {
CodeSnippet arr;
arr.heading = "ARRAY EXAMPLE";
arr.explanation = "Is code me hum ek array banate hain aur uski values print karte hain.";
arr.codeLines = {
"int arr[5] = {1, 2, 3, 4, 5};",
"for (int i = 0; i < 5; i++) {",
" cout << arr[i] << endl;",
"}"
};
arr.lineExplain = {
"Yaha hum ek array declare kar rahe hain.",
"Loop start hota hai, i=0 se i<5 tak.",
"Array ke har element ko print kar rahe hain.",
"Loop khatam hota hai."
};
snippets.push_back(arr);
}
void addLoopExample() {
CodeSnippet loop;
loop.heading = "LOOP EXAMPLE";
loop.explanation = "Is code me ek simple for loop likha hai jo numbers print karta hai.";
loop.codeLines = {
"for (int i = 1; i <= 10; i++) {",
" cout << i << \" \";",
"}"
};
loop.lineExplain = {
"Loop 1 se 10 tak chalega.",
"Har i ki value print ho rahi hai.",
"Loop block close hota hai."
};
snippets.push_back(loop);
}
void addFunctionExample() {
CodeSnippet func;
func.heading = "FUNCTION EXAMPLE";
func.explanation = "Is code me ek function banate hain jo do numbers ka sum return karta hai.";
func.codeLines = {
"int add(int a, int b) {",
" return a + b;",
"}"
};
func.lineExplain = {
"Function add declare hota hai jo 2 parameters leta hai.",
"Return statement a+b return kar raha hai.",
"Function ka end."
};
snippets.push_back(func);
}
void learnMode() {
for (auto &snip : snippets) {
cout << "\n";
printColor("[ " + snip.heading + " ]\n", "blue");
printColor("→ " + snip.explanation + "\n\n", "green");
for (size_t i = 0; i < snip.codeLines.size(); i++) {
printColor(snip.codeLines[i] + "\n", "yellow");
printColor(" Explanation: " + snip.lineExplain[i] + "\n", "green");
cout << "Type this line:\n> ";
string input;
getline(cin, input);
if (input == snip.codeLines[i])
printColor("✅ Correct!\n", "green");
else
printColor("❌ Error! Expected: " + snip.codeLines[i] + "\n", "red");
}
}
}
void typingChallenge(WordPool &pool, int count = 50) {
cout << "\n=== Typing Challenge ===\n";
int correct = 0;
string input;
time_t start = time(0);
for (int i = 0; i < count; i++) {
string word = pool.getRandomWord();
cout << "Word " << i + 1 << ": " << word << "\n> ";
cin >> input;
if (input == word) correct++;
}
time_t end = time(0);
double timeTaken = difftime(end, start);
double wpm = (correct / timeTaken) * 60;
cout << "\nResult: " << correct << "/" << count << " correct. Speed: " << wpm << " WPM.\n";
}
};
int main() {
srand(time(0));
WordPool pool;
LearningTutor tutor;
int choice;
cout << "=== MEGA C++ TYPING & LEARNING TUTOR ===\n";
cout << "1. Learn Mode (20+ Examples)\n";
cout << "2. Typing Challenge (1000 Words)\n";
cout << "3. Exit\n";
cout << "Choose: ";
cin >> choice;
cin.ignore();
if (choice == 1) tutor.learnMode();
else if (choice == 2) tutor.typingChallenge(pool, 50);
return 0;
}
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
// Function to print color text
void printColor(const string &text, const string &color) {
if (color == "blue") cout << "\033[1;34m" << text << "\033[0m";
else if (color == "green") cout << "\033[1;32m" << text << "\033[0m";
else if (color == "yellow") cout << "\033[1;33m" << text << "\033[0m";
else if (color == "red") cout << "\033[1;31m" << text << "\033[0m";
else cout << text;
}
// CodeSnippet structure
struct CodeSnippet {
string heading;
string explanation;
vector<string> codeLines;
vector<string> lineExplain;
};
class WordPool {
public:
vector<string> words;
WordPool() {
words = {
"int","float","double","if","else","for","while","class",
"public","private","protected","virtual","override","friend",
"+","-","*","/","%","&&","||","==","!=","<",">",
"{","}","(",")","[","]","::","->","<<",">>", ";",
// ... Expand this list up to 1000 words
};
}
string getRandomWord() {
return words[rand() % words.size()];
}
};
class LearningTutor {
vector<CodeSnippet> snippets;
public:
LearningTutor() {
addArrayExample();
addLoopExample();
addFunctionExample();
// Add 20+ such examples here
}
void addArrayExample() {
CodeSnippet arr;
arr.heading = "ARRAY EXAMPLE";
arr.explanation = "Is code me hum ek array banate hain aur uski values print karte hain.";
arr.codeLines = {
"int arr[5] = {1, 2, 3, 4, 5};",
"for (int i = 0; i < 5; i++) {",
" cout << arr[i] << endl;",
"}"
};
arr.lineExplain = {
"Yaha hum ek array declare kar rahe hain.",
"Loop start hota hai, i=0 se i<5 tak.",
"Array ke har element ko print kar rahe hain.",
"Loop khatam hota hai."
};
snippets.push_back(arr);
}
void addLoopExample() {
CodeSnippet loop;
loop.heading = "LOOP EXAMPLE";
loop.explanation = "Is code me ek simple for loop likha hai jo numbers print karta hai.";
loop.codeLines = {
"for (int i = 1; i <= 10; i++) {",
" cout << i << \" \";",
"}"
};
loop.lineExplain = {
"Loop 1 se 10 tak chalega.",
"Har i ki value print ho rahi hai.",
"Loop block close hota hai."
};
snippets.push_back(loop);
}
void addFunctionExample() {
CodeSnippet func;
func.heading = "FUNCTION EXAMPLE";
func.explanation = "Is code me ek function banate hain jo do numbers ka sum return karta hai.";
func.codeLines = {
"int add(int a, int b) {",
" return a + b;",
"}"
};
func.lineExplain = {
"Function add declare hota hai jo 2 parameters leta hai.",
"Return statement a+b return kar raha hai.",
"Function ka end."
};
snippets.push_back(func);
}
void learnMode() {
for (auto &snip : snippets) {
cout << "\n";
printColor("[ " + snip.heading + " ]\n", "blue");
printColor("→ " + snip.explanation + "\n\n", "green");
for (size_t i = 0; i < snip.codeLines.size(); i++) {
printColor(snip.codeLines[i] + "\n", "yellow");
printColor(" Explanation: " + snip.lineExplain[i] + "\n", "green");
cout << "Type this line:\n> ";
string input;
getline(cin, input);
if (input == snip.codeLines[i])
printColor("✅ Correct!\n", "green");
else
printColor("❌ Error! Expected: " + snip.codeLines[i] + "\n", "red");
}
}
}
void typingChallenge(WordPool &pool, int count = 50) {
cout << "\n=== Typing Challenge ===\n";
int correct = 0;
string input;
time_t start = time(0);
for (int i = 0; i < count; i++) {
string word = pool.getRandomWord();
cout << "Word " << i + 1 << ": " << word << "\n> ";
cin >> input;
if (input == word) correct++;
}
time_t end = time(0);
double timeTaken = difftime(end, start);
double wpm = (correct / timeTaken) * 60;
cout << "\nResult: " << correct << "/" << count << " correct. Speed: " << wpm << " WPM.\n";
}
};
int main() {
srand(time(0));
WordPool pool;
LearningTutor tutor;
int choice;
cout << "=== MEGA C++ TYPING & LEARNING TUTOR ===\n";
cout << "1. Learn Mode (20+ Examples)\n";
cout << "2. Typing Challenge (1000 Words)\n";
cout << "3. Exit\n";
cout << "Choose: ";
cin >> choice;
cin.ignore();
if (choice == 1) tutor.learnMode();
else if (choice == 2) tutor.typingChallenge(pool, 50);
return 0;
}
