[C++] Program to measure typing speed and accuracy. Done with the speed part, no idea how to deal with the accuracy thing
In order to determine accuracy, every character from the user input will be stacked up against the preset sentence. The formula for the accuracy will be correct words/total words
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
usingnamespace std;
int main ()
{
//Clock starts running, user is prompted to enter word on-screen
clock_t start, end;
start = clock();
cout<< "Enter the following words: \n \n";
string sentence;
//Program "reads" test.text through file streaming, clock still running
string line;
ifstream myfile ("test.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
//Code for data input, clock still running, this and above are visible to user from the start-up of the program
cout<<"\n";
cin >> sentence;
//Code to determine input accuracy
}
myfile.close();
}
//Clock ends running, data gathered is displayed to user
end = clock();
double seconds = (double)(end - start) / CLOCKS_PER_SEC;
cout << "\nTyping the sentence took " << seconds << " seconds.\n \n";
cout<<"Your typing speed is "<<(seconds/6) <<" words per second or "<< (seconds/6)*60<< " words per minute. \n \n";
cout<<"Your typing accuracy though is unknown. \n \n";
system("PAUSE");
return EXIT_SUCCESS;
//end of program
}
I think you should check based on the accuracy of each character and not by the accuracy of the words. It would be pretty hard for someone to mix up the words unless they are dyslexic or something but on the other hand mixing up a few letters would be an accuracy problem while typing. You could determine the accuracy by checking each letter from string a to string b.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <string>
int main()
{
std::string a = "The car went sixty miles per hour on the highway." ,
b = "the ccr want sixty mless per hour on the higgway/";
int errors = 0;
for( auto i( a.begin() ); i != a.end(); ++i )
{
if( *i != *( b.begin() + std::distance( a.begin() , i ) ) ) ++errors;
}
std::cout << "There was a total of " << errors << " errors in the sentence with " << a.size() << " letters." << std::endl;
std::cout << "Your accuracy is %" << static_cast<double>( ( a.size() - errors ) ) / a.size() * 100 << '.' << std::endl;
}