It's a speed tester.
I wrote this program with some of information I gathered from here. Please place the attached file on your C: partition and compile it. tell me your idea about the code, bugs and if possible your score and machine type.
Thank you.
All windows compilers should compile it, shouldn't they?Code:#include<math.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
//prototypes
void func(int);
int getrange(int minimum, int Maximum);
void showdata();
void func(int a)
{
a++;
a--;
a+=34;
a-=32;
a/=3;
}
void showdata()
{
ifstream dat_if;
int readn;
char readc[20];
dat_if.open("C:\\data.txt",ios::in | ios::nocreate);
if(!dat_if.good())
{
cout <<"Error opening data file!"<<endl;
dat_if.close();
return;
}
dat_if>>readc>>readn;
while(!dat_if.eof()&&dat_if.good())
{
cout<<readc<<" : "<<readn <<endl;
dat_if>>readc>>readn;
}
dat_if.close();
}
int getrange(int m, int M)
{
int inpv; //input value
cout <<"A number from "<< m<<" to " << M<<": ";
cin >>inpv;
if(inpv >3 || inpv <1)
{
cout<<"Not in range!"<<endl;
cin.clear();
cin.ignore(300,'\n');
inpv=getrange(m,M); //<=Look at this.
}
else
{
//cin.clear(); It seems not required
cout<<endl;
}
return inpv;
}
int main() //Salem forced me to use int instead of void for compatibility
{
cout<<"Define the program's precision:"<<endl;
//This function gets input in specified range;
int pric =getrange(1,3);
//////////////////////// Selfish function:
SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS );
////////////////////////
//Initializings
int x=0;
char ch[1000]="uv";
char ch2[]="j";
double doa[100];
double doa2[100];
double doub=33.3433;
DWORD TimeFrame = 1000 * 5 * pric;
cout<< "Freezing..." <<endl;
/*This function returns
miliseconds passed since Windows started.*/
DWORD StartTime = GetTickCount();
/*In this loop some simple operations execute to make CPU work
harder. Actually I didn't spend enough time to optimize this block.
Tell me your suggestions. */
while((GetTickCount() - StartTime) < TimeFrame)
{
(x<100) ? doa[x]=doa2[x]:doa[32]=doa2[23];
if(x<500) strcat(ch,ch2); else func(x);
doub+=3433.52234;
doub-=4334.3;
doub/=3.34;
doub*=4.544;
doub=sqrt(doub);
doub=x-(x*x*x)+19*x/3*x;
doub=doub/2-322343;
x++;
}
cout<<"Your score is: "<< int(x/(10000*pric))<<endl;
//This function reads some recent score records from a file.
showdata();
//This function sends the string as a command to system.
system("pause");//waits till user hits any key
return 0;
}