From 78faa840994e46132ed751fd534d1247488bf2bf Mon Sep 17 00:00:00 2001 From: Saphiraa <40579172+Saphiraa@users.noreply.github.com> Date: Sun, 6 Sep 2020 13:01:54 +0530 Subject: [PATCH] Add files via upload Respected Sir, This is the typing speed calculator I have attempted to make in C++. It is not a very clean code but am eager to learn more from the course that you will teach. Thank you for this project. Files: Contains one .cpp file --- .../typing_speed_SaaraaKazi.cpp | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Screening-Assignment/typing_speed_SaaraaKazi.cpp diff --git a/Screening-Assignment/typing_speed_SaaraaKazi.cpp b/Screening-Assignment/typing_speed_SaaraaKazi.cpp new file mode 100644 index 0000000..a580254 --- /dev/null +++ b/Screening-Assignment/typing_speed_SaaraaKazi.cpp @@ -0,0 +1,91 @@ +//saaraakazi@gmail.com + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +void single_line() { + //load the text file and put it into a single string: + ifstream in("/Users/saaraa/projects/typing_calculator/shakespeare.txt"); + stringstream buffer; + buffer << in.rdbuf(); + string test = buffer.str(); + //cout << test << endl << endl; + + //create variables that will act as "cursors". we'll take everything between them. + size_t pos1 = 0; + size_t pos2; + + string str[500]; + int r = 0; + + + for (int x=0; x<=500; x++){ + pos2 = test.find("\n", pos1); //search for the bar "\n". pos2 will be where the bar was found. + str[x] = test.substr(pos1, (pos2-pos1)); //make a substring, wich is nothing more than a copy of a fragment of the big string. + pos1 = pos2+1; // sets pos1 to the next character after pos2. so, it can start searching the next \n line. + } + + r = rand() % 500 + 1; + //cout << " \n" << r; + cout<< "\nType the following sentence. : " << "\n"; + cout << "\n" << str[r] << endl; +} + +int type(int lent) { + string typing; + getline(cin, typing); + lent += typing.length(); + return lent; +} + +int main() +{ + int len = 0; + float words_per_min, sec; + + single_line(); + + clock_t time_req; + time_req = clock(); + len = type(len); + + cout << "-----------" << "\n"; + single_line(); + time_req = clock(); + len = type(len); + + cout << "-----------" << "\n"; + single_line(); + time_req = clock(); + len = type(len); + + cout << "-----------" << "\n"; + single_line(); + time_req = clock(); + len = type(len); + + cout << "-----------" << "\n"; + single_line(); + time_req = clock(); + len = type(len); + + cout << "\n The number of characters you typed are : "<