From ae43adea40ea4b55d78090b88de9fb0b9c8f8629 Mon Sep 17 00:00:00 2001 From: numan619 Date: Sun, 6 Sep 2020 08:34:09 +0530 Subject: [PATCH] first assignment --- Screening-Assignment/typing-speed-numan.cpp | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Screening-Assignment/typing-speed-numan.cpp diff --git a/Screening-Assignment/typing-speed-numan.cpp b/Screening-Assignment/typing-speed-numan.cpp new file mode 100644 index 0000000..43a0d7d --- /dev/null +++ b/Screening-Assignment/typing-speed-numan.cpp @@ -0,0 +1,44 @@ +// numan.ejaz1897@gmail.com + +#include +#include +#include +#include +#include +#include +using namespace std; + + +int main(){ + srand(time(0)); + std::fstream newfile; + newfile.open("shakespeare.txt",std::ios::out | std::ios::in); + string lines[2000]; + int count = 0; + if (newfile.is_open()){ + string tp; + while(getline(newfile, tp)){ + lines[count]=tp; + count++; + } + newfile.close(); + } + time_t begin, end; + time_t elapsed = 0; + int len_chars=0; + string user_input; + for (int j = 0; j < 5; j++){ + int rand_idx = int(count*(rand()/(RAND_MAX + 1.0))); + string rand_line = lines[rand_idx]; + cout << "Rewrite the following line:\n" << rand_line << endl; + time(&begin); + getline(cin, user_input); + time(&end); + elapsed += (end-begin); + len_chars += user_input.size(); + cout << endl; + } + cout << "Number of characters = " << len_chars << endl; + cout << "Time taken = " << elapsed << " seconds" << endl; + cout << "Typing speed = " << len_chars*60.0/elapsed << " characters per minute " << endl; +} \ No newline at end of file