Take a look to new version
Code:
/* Freezer ver 1.8
* - New CPU work stuff
* - Security hole patched (no shell command anymore)
* - Now searches for data file. If not found asks user for path
* - Better search for data file(NEW)
* - Tests for priority(NEW)
* - Very modular design(NEW)
* - Goes to high priority only in needed time(NEW)
*/
int cpuburner(int);
void testfunc(int);
int getrange(int minimum, int Maximum);
void showdata(char *);
void getpath(char* );
int main(int argc , char *argv[])
{
cout<<"Define the program's precision:"<<endl;
int pric =getrange(1,3);
cout<< "Freezing..." ;
SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS );
//cout<< "Priority: "<< GetPriorityClass(GetCurrentProcess()) <<endl;
if(200>GetPriorityClass(GetCurrentProcess()))
cout<<" (Could not swicth to highest priority)"<<endl;
else
cout<<endl;
cout<<"Your score is: "<< cpuburner(pric)<<endl;
SetPriorityClass( GetCurrentProcess(), NORMAL_PRIORITY_CLASS );
char pat[100];
strncpy(pat,argv[0],99);
strcpy(strrchr(pat,92),"\\freez.dat");
showdata(pat);
cout<< "Press a key to exit...";
cout.flush();
getch();
return 0;
}
void getpath(char *pat)
{
cout<<"Enter path of freez.dat: " ;
cin.ignore(1,'\n'); //Tell me why this should be here
cin.getline(pat,30,'\n');
}
void showdata(char *pat)
{
ifstream dat_if;
int readn;
char readc[10];
dat_if.open(pat,ios::in | ios::nocreate);
if(!dat_if.good())
{
dat_if.clear();
getpath(pat);
strcat(pat, "\\freez.dat");
dat_if.open(pat,ios::in | ios::nocreate);
if(!dat_if.good())
{
cerr <<"Error opening data file from path: "<<pat<<endl;
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;
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);
}
else
{
cout<<endl;
}
return inpv;
}
int cpuburner(int pric)
{
int x=0;
int sigma(int);
int fac(int);
char ch[1000]="sa";
char ch2[]="j";
double doa[100];
int c;
int n=GetTickCount()%10000;
int seed=120+100*cos(n);
double doa2[100];
double doub=33.3433;
DWORD TimeFrame = 1000 * 5 * pric;
DWORD StartTime = GetTickCount();
while((GetTickCount() - StartTime) < TimeFrame)
{
x<100 ? doa[x]=doa2[x]:doa[32]=doa2[23];
if(x<500) strcat(ch,ch2); else testfunc(x);
doub+=3433.52234;
doub-=4334.3+x;
doub/=3.34+x;
doub*=4.544;
testfunc(doub);
doub=sqrt(doub);
doub=x-(x*x*x)+19*x/3*x;
doub=doub/2-322343/(x+1);
/*ofstream ofile;
*ofile.open("C:\\randnum.txt");
*for(int n=0;n<6000;n++){
*This is a random number generator*/
c=(fac(n+3)*seed-(floor((pow(60*n,3)*cos(n)*seed)-sigma(n+seed)))+100*seed/
(n-pow(floor(log(n)),3)));
c=abs((int)(c+10*cos(n))%10000+(doub));
doub-=4334.2323+x;
doub/=3.342+x;
doub*=43.54423223;
doub=sqrt(doub)-1*x;
doub=x-(x*x*x+12/(x+2))+19*x/3*x*x;
doub=doub/2-322343*x;
//ofile<<c<<endl;
//cout<<c<<endl; //Enable it for wathing random nums.
//}
x++;
}
return (x/(10*pric));
}
void testfunc(int a)
{
a++;
a--;
a+=35564;
a-=320;
a/=3;
}
int sigma(int n)
{
double dub; //It is random so no need to be initialized
for(int i=1;i<=n;i++)
{
dub+=(i*i)/(i+i*2);
}
return floor(dub);
}
int fac(int n)
{
int f=1;
for(int i=1;i<=n;i++)
{
f*=i;
}
return f;
}