Add to Favorites    Make Home Page 48213 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » Program to calculate the Typing Speed.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Program to calculate the Typing Speed.
Author Adarsh Ramamurthy
Author Email adarsh83 [at] rediffmail.com
Description Calculates typing speed accurately.
Category C » Beginners / Lab Assignments
Hits 322752
Code Select and Copy the Code
#include <stdio.h> #include <dos.h> #include <conio.h> #define ESC 0x1b #define BSPACE 0x08 const unsigned long far * const dosTime = (const unsigned long far * const)MK_FP( 0x40, 0x6C ); class Timer { public: Timer(); void start(); void stop(); void reset(); int status(); double time(); static double resolution(); private: static unsigned adjust; static unsigned calibrate(); int running; struct TIME { unsigned long dosCount; unsigned timerCount; }; TIME startTime; double time_; }; inline double Timer::time() { return time_/1.E6; } inline double Timer::resolution() { return 839/1.E9; } unsigned Timer::adjust = calibrate(); Timer::Timer() : time_(0), running(0) { } void Timer::start() { if( !running ) { outportb( 0x43, 0x34 ); asm jmp __1; __1: outportb( 0x40, 0 ); asm jmp __2; __2: outportb( 0x40, 0 ); startTime.dosCount = *dosTime; startTime.timerCount = 0; running = 1; } } void Timer::stop() { outportb( 0x43, 0 ); unsigned char temp = inportb( 0x40 ); TIME stopTime; stopTime.timerCount = (inportb( 0x40 ) << 8) + temp; stopTime.dosCount = *dosTime; TIME elapsedTime; elapsedTime.dosCount = stopTime.dosCount - startTime.dosCount; elapsedTime.timerCount = -( stopTime.timerCount - adjust ); const double fudge = 83810.0/100000.0; time_ += ((elapsedTime.dosCount << 16) + elapsedTime.timerCount)*fudge; running = 0; } void Timer::reset() { time_ = 0; if( running ) start(); } unsigned Timer::calibrate() { adjust = 0; unsigned long sum = 0; Timer w; for( int i = 0; i < 100; i++ ) { w.start(); w.stop(); sum += w.time(); w.reset(); } return (unsigned)((sum+5)/100); } void main() { clrscr(); Timer t; char text[1000]; int i = 0, space_count = 0, letter_count = 0; float duration; printf(" PROGRAM TO TEST TYPING SPEED - Adarsh Ramamurthy "); printf("Hit any key to start timer... "); if(getch()) { printf("Your time has started. Start typing. Hit Esc when done. "); t.start(); } while(1) { text[i] = getche(); letter_count++; if(text[i] == ' ') space_count++; if(text[i] == ' ') printf(" "); if(text[i] == BSPACE) printf(" "); // to erase previous character instead of cursoring over if(text[i] == ESC) { printf(" "); // to eliminate a special character that is printed for Esc // A Backspace followed by Space erases previous character. break; } } t.stop(); duration = t.time(); printf(" Your typing speed is : "); printf("%6.2f characters per minute ",60*letter_count/duration); printf("%6.2f words per minute (Actual) ",60*space_count/duration); printf("%6.2f words per minute (Average)",60*letter_count/duration/5); getch(); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi դ ? ??
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2022 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=432


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review