From f2bdfe964b6ac9a86846f0f4d47e3768e6502344 Mon Sep 17 00:00:00 2001 From: maaz1996 Date: Fri, 4 Sep 2020 17:14:40 +0530 Subject: [PATCH 1/4] code worked: incomplete --- Screening-Assignment/maaz.abdullah.cpp | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Screening-Assignment/maaz.abdullah.cpp diff --git a/Screening-Assignment/maaz.abdullah.cpp b/Screening-Assignment/maaz.abdullah.cpp new file mode 100644 index 0000000..c4935c6 --- /dev/null +++ b/Screening-Assignment/maaz.abdullah.cpp @@ -0,0 +1,49 @@ +//maaz.abdullah111@gmail.com +#include +using namespace std; + +int main() +{ + + string line; + vector lines; + + srand(time(0)); + + //input file stream + ifstream file("shakespeare.txt"); + + //count number of total lines in the file and store the lines in the string vector + int total_lines = 0; + while (getline(file, line)) + { + + total_lines++; + lines.push_back(line); + } + + for (int i = 0; i < 5; i++) + { + + //generate a random number between 0 and count of total lines + int random_number = rand() % total_lines; + + //fetch the line where line index (starting from 0) matches with the random number + + cout << lines[random_number] << endl; + } + + int t = 5; + string messageVar; + cout << "Type your message: " << endl; + ; + //istream& ignore (streamsize n = 0, int delim = EOF); + while (t--) + { + + getline(cin, messageVar); + cout << "You typed: " << messageVar << endl; + cout << messageVar.size() << endl; + } + return 0; +} From 7bd2749e81a218dd57df181c095d407b6986c43c Mon Sep 17 00:00:00 2001 From: maaz1996 Date: Fri, 4 Sep 2020 17:38:58 +0530 Subject: [PATCH 2/4] display of random lines; sum of characters added --- Screening-Assignment/maaz.abdullah.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Screening-Assignment/maaz.abdullah.cpp b/Screening-Assignment/maaz.abdullah.cpp index c4935c6..b461ae7 100644 --- a/Screening-Assignment/maaz.abdullah.cpp +++ b/Screening-Assignment/maaz.abdullah.cpp @@ -22,28 +22,24 @@ int main() lines.push_back(line); } + string messageVar; + long long int sum = 0; for (int i = 0; i < 5; i++) { - //generate a random number between 0 and count of total lines + //generate a random number betfirnween 0 and count of total lines int random_number = rand() % total_lines; //fetch the line where line index (starting from 0) matches with the random number - cout << lines[random_number] << endl; - } - - int t = 5; - string messageVar; - cout << "Type your message: " << endl; - ; - //istream& ignore (streamsize n = 0, int delim = EOF); - while (t--) - { - + cout << "Line to type: " << lines[random_number] << endl; + cout << "Type your message: " << endl; getline(cin, messageVar); cout << "You typed: " << messageVar << endl; - cout << messageVar.size() << endl; + sum = sum + messageVar.size(); + cout << endl; } + cout << "Total Character Typed: " << sum; + return 0; } From e7161835bacd3d15038f8ecee7192d0226b35d20 Mon Sep 17 00:00:00 2001 From: maaz1996 Date: Fri, 4 Sep 2020 17:53:53 +0530 Subject: [PATCH 3/4] complete code --- Screening-Assignment/maaz.abdullah.cpp | 11 ++++++++--- Screening-Assignment/{shakespeare.txt => shakespeare} | 0 2 files changed, 8 insertions(+), 3 deletions(-) rename Screening-Assignment/{shakespeare.txt => shakespeare} (100%) diff --git a/Screening-Assignment/maaz.abdullah.cpp b/Screening-Assignment/maaz.abdullah.cpp index b461ae7..c789c54 100644 --- a/Screening-Assignment/maaz.abdullah.cpp +++ b/Screening-Assignment/maaz.abdullah.cpp @@ -24,6 +24,8 @@ int main() string messageVar; long long int sum = 0; + time_t begin, end; + time(&begin); for (int i = 0; i < 5; i++) { @@ -33,13 +35,16 @@ int main() //fetch the line where line index (starting from 0) matches with the random number cout << "Line to type: " << lines[random_number] << endl; - cout << "Type your message: " << endl; + cout << "Type your line: " << endl; getline(cin, messageVar); cout << "You typed: " << messageVar << endl; sum = sum + messageVar.size(); cout << endl; } - cout << "Total Character Typed: " << sum; - + time(&end); + time_t timetaken = end - begin; + cout << "Total Character Typed: " << sum << endl; + cout << "Time of typing character: " << timetaken << " seconds" << endl; + cout << "Speed of typing character: " << std::setprecision(2) << (double)sum / timetaken << " character/second" << endl; return 0; } diff --git a/Screening-Assignment/shakespeare.txt b/Screening-Assignment/shakespeare similarity index 100% rename from Screening-Assignment/shakespeare.txt rename to Screening-Assignment/shakespeare From f185d21741ea41815a5081c538db8a0b001cf886 Mon Sep 17 00:00:00 2001 From: Maaz Abdullah Date: Wed, 9 Sep 2020 10:06:50 +0530 Subject: [PATCH 4/4] Rename shakespeare to shakespeare.txt --- Screening-Assignment/{shakespeare => shakespeare.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Screening-Assignment/{shakespeare => shakespeare.txt} (100%) diff --git a/Screening-Assignment/shakespeare b/Screening-Assignment/shakespeare.txt similarity index 100% rename from Screening-Assignment/shakespeare rename to Screening-Assignment/shakespeare.txt