Hello I am having problems getting this code to work in VS after it worked fine in Borland... I think it has somethign to do with the header files.... Actually I am sure it is I keep getting errors from them
Thanks
Code:
#pragma hdrstop
//---------------------------------------------------------------------------
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<math.h>
#pragma argsused
////////////////////////////////////////////////////////////////////
// declaring functions
void GenerateData(int, int *);
int Hash(int, int *, int, int );
void Prime(int &, int);
////////////////////////////////////////////////////////////////////
//main fuction
int main(int argc, char* argv[])
{
//declaring local variables
int *Data;//pointers arrays
int N = 2, count=0, i, x =15, TableSize;
ofstream out;
//open a file for output called data.txt
out.open("data.txt");
//if file does not open
if(out.fail())
{
cout << "Data file did not open";
system("pause");
exit(0);
}
//creat loop to write data to file
for (i =0; i < x; i++)
{
out << N << " ";
N *=2;
}
out << endl;
for (int k =0; k < 2; k++)
{
N =2;
for (i =0; i < x; i++)
{
Data= new int[N];
GenerateData(N,Data);
Prime(TableSize,N);
count = Hash(N,Data,TableSize,k);
N*=2;
out << count << " ";
delete [] Data;
}
out << endl;
}
//close data.text file
out.close();
system ("pause");
return 0;
}//end of main function
////////////////////////////////////////////////////////////////
void Prime(int &TS, int N)
{
int EndNum, StartNum, Remainder;
bool NotPrime=false;
TS = 2*N +1;
EndNum = ceil( pow(TS,.5)) +1;
while (1)
{
for (StartNum=2; StartNum <= EndNum; StartNum++)
{
Remainder = TS % StartNum;
if (Remainder == 0)
{
NotPrime = true;
break;
}
}
if (NotPrime == true)
{
TS++;
EndNum = ceil( pow(TS,.5)) + 1;
NotPrime = false;
}
else break;
}
}
////////////////////////////////////////////////////////////////
//generating data and putting them in the arrays.
void GenerateData(int n, int *Data)
{
double sum;
//loop n times to generate data in the the arrays a,b,c from 0 to 999
for (int i =0; i<n; i++)
{
sum = 0;
for(int j =0; j < 5; j++)
{
sum = (double)(rand()%26)*pow(26.,j) + sum;
}
Data[i] = sum;
}
}//end of GenerateData fuciton
/////////////////////////////////////////////////////////////////
int Hash(int n, int *Data,int TS, int k)
{
int *HashData;
int counter = 0, Start, Index, i;
HashData = new int[TS];
for (Start=0; Start<TS; Start++)
{
HashData[Start] = -1;
}//end of for loop
if (k == 0)
{
//linear hashing
for (Start=0; Start < n; Start++)
{
Index = Data[Start] % TS;
if(HashData[Index] == -1)
{
HashData[Index] = Data[Start];
counter++;
}//end if
else
{
Index++;
while(1)
{
counter++;
if(HashData[Index % TS] == -1)
{
HashData[Index % TS] = Data[Start];
break;
}
else
Index++;
}//end of while loop
}//end of else
}//end of for loop
delete [] HashData;
}//end of if statement
else
{
//Quadratic Hashing
for (Start=0; Start < n; Start++)
{
Index = Data[Start] % TS;
if(HashData[Index] == -1)
{
HashData[Index] = Data[Start];
counter++;
}//end of if
else
{
i =1;
while(1)
{
counter++;
if(HashData[(Index + i*i) % TS] == -1)
{
HashData[(Index + i*i) % TS] = Data[Start];
break;
}
else
i++;
}
}//end of else
}//end of for loop
delete [] HashData;
}
return (counter);
}
//---------------------------------------------------------------------------