Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Screening-Assignment/typing-speed-sabasultana.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//[email protected]
//Saba Sultana

#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main(){

int r;
std::ifstream infile("shakespeare.txt");
std::string line;
string lines[2000];

if (infile.is_open()){ //checking whether the file is open

int i=0;
while(getline(infile,line)){ //read data from file object and put it into string.

lines[i]=line;
//cout<<lines[i]<< "\n"; //print the data of the string
i++;
}
}

infile.close(); //close the file object.

//Displaying time and read 5 random lines
cout<<"Please type the lines given below , All the Best!"<<endl<<endl;
std:string msg;
int count;
time_t begin, end;
time(&begin);
for(int j=0;j<2;j++)
{
cout<<endl<<lines[rand()%2000]<<endl;
getline(cin,msg);
count=msg.size();
}

time(&end);



float elapsed = end - begin;
float elapsedMin = elapsed/60.0;
float speed = (count/5)/elapsedMin;


cout<<endl<<endl<<"Result :"<<endl;
cout<<"You typed "<<count<<" characters in "<<elapsedMin<<" min "<<elapsed<<" sec"<<endl<<endl;
cout<<"Your typing speed is "<<speed<<" WPM."<<endl;


}