#include<iostream>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream>
#include<string.h>
#include<windows.h>
#include<fstream.h>
#include<ctime>
void checking();
void display(double);
enum check{correct,incorrect};
class words
{
public:
char word[20];
check cword;
check cchar[20];
};
void main()
{
ifstream fin("Book.txt");
char ch;
char wrd[20];
time_t start,end;
double dif;
cout<<"\n Enter the text below. Press 0 to finish typing. \n";
Sleep(100);
while(!fin.eof())
{
fin>>wrd;
cout<<wrd<<" ";
}
cout<<endl;
fin.close();
ofstream fout("Typed.txt");
time (&start);
while(ch!='0')
{
ch=getche();
if(ch!='0')
fout<<ch;
}
time (&end);
cout<<"\n Please wait while we process your result. \n";
dif = difftime (end,start);
fout.close();
checking();
display(dif);
}
void checking()
{
words w;
char wrd[20];
ifstream fin("Book.txt");
ifstream type("Typed.txt");
fstream fout;
fout.open("Corrected.dat",ios::out);
int i,j,k,l;
while(!type.eof())
{
fin>>wrd;
type>>w.word;
j=0;
k=0;
l=strlen(w.word);
for(i=0;w.word[i]!='\0';i++)
{
rajat:
if(w.word[i]==wrd[j])
w.cchar[i]=correct;
else
{
w.cchar[i]=incorrect;
k++;
if(i!=l)
{
i++;
goto rajat;
}
else
i=j;
}
j++;
}
if(k==0)
w.cword=correct;
else
w.cword=incorrect;
fout.write((char*)&w,sizeof(w));
}
fin.close();
type.close();
fout.close();
}
void display(double dif)
{
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
fstream fin;
fin.open("Corrected.dat",ios::in);
words w;
cout<<"\n You took "<<dif<<" seconds to enter the text.";
cout<<"\n The typed text with mistakes are highlighted in red. \n";
while(fin.read((char*)&w,sizeof(w)))
{
if(w.cword==correct)
{
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout<<w.word;
}
else
{
for(int i=0;w.word[i]!='\0';i++)
{
if(w.cchar[i]==correct)
{
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout<<w.word[i];
}
else
{
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout<<w.word[i];
}
}
}
cout<<" ";
}
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
cout<<endl;
}
ABOVE IS THE PROJECT TYPING TUTOR WHICH WORKS ABSOLUTELY FINE ON "NETBEANS" COMPILER..
BUT THE PROBLEM I AM FACING IS THAT EACH TIME THE USER HAS TO ENTER 0 AFTER FINISH TYPING.....IS THERE ANY WAY FOR THE USER TO ENTER "ENTER" TO FINISH TYPING....
ALSO....I WANTED TO KNOW THAT ..IS THERE ANY WAY TO REMOVE EXTRA CHARACTERS BY BACKSPACE...IF SUPPOSE SOMEONE ACCIDENTALLY TYPES A FEW EXTRA CHARACTERS, THEN IS THERE ANY WAY TO REMOVE THOSE EXTRA CHARACTERS BY BACKSPACE??? :/
NOW , IN THIS STATE WHENEVER I TYPE BACKSPACE, THE POINTER COMES BACKWARDS AND I CAN ONLY REPLACE THE CHARACTER...NOT REMOVE IT !! THATS THE PROBLEM :(
AND ALSO.... THIS PROJECT IS A BIT SHORT ....COULD YOU PLEASE SUGGEST SOME WAYS TO MAKE IT A BIT LONGER....... PLEASE PLEASE ITS A REQ. :((
ALSO, HOW CAN I ADD THE OPTION TO "CHANGE PASSWORD" IN THE "MENU OPTION"
AND HOW WILL IT SHOW UP IN ASTERISKS... LIKE THIS > ******** WHICH WILL NOT SHOW UP WHEN SOMEONE TYPES THEIR PASSWORD.....
PLEASE HELP ME WITH THESE THINGS.... I SHALL BE REALLY GRATEFUL ONCE AGAIN...
AND THE CURRENT OUTPUT OF THIS PROGRAM YOU CAN SEE HERE >> http://i53.tinypic.com/5kj9u8.png