i am trying to use the text file to use for iteration to reduce the number of points using functions.
Code:
#include <iostream> // library that contain basic input/output functions
#include <fstream> // library that contains file input/output functions
using namespace std;
int main()
{
int array_size = 1024; // define the size of character array
char * array = new char[array_size]; // allocating an array of 1kb
int position = 0; //this will be used incremently to fill characters in the array
ifstream fin("input.txt"); //opening an input stream for file test.txt
/*checking whether file could be opened or not. If file does not exist or don't have read permissions, file
stream could not be opened.*/
if(fin.is_open())
{
//file opened successfully so we are here
cout << "File Opened successfully!!!. Reading data from file into array" << endl;
//this loop run until end of file (eof) does not occur
while(!fin.eof() && position < array_size)
{
fin.get(array[position]); //reading one character from file to array
position++;
}
array[position-1] = '\0'; //placing character array terminating character
cout << "Displaying Array..." << endl << endl;
//this loop display all the charaters in array till \0
for(int i = 0; array[i] != '\0'; i++)
{
cout << array[i];
}
}
else //file could not be opened
{
cout << "File could not be opened." << endl;
}
return 0;
}
// lang algorism started
public function lang(PointList[], Tolerance)
key=0
int pointList = input.txt; // use pointlist in text file used above
endP= PointList.length-1
do {
endP= PointList.length-1
if (key+1 != endP) // If there are intermediate points
line= new Line( PointList[key], PointList[endP])
/* Find the point with the furthest perpendicular distance */
maxIndex= key+1
maxD= perpendicularDistance(line, PointList[maxIndex])
for (i=maxIndex+1; i<endP; i++)
d= perpendicularDistance(line, PointList[i])
if (d > maxD)
maxIndex=i
maxD=d
if (maxD > Tolerance)
endP--;
else
for (i=key+1; i<endP; i++)
PointList.remove(i)
key= endP
} while ( endP != PointList.length-1 )
end
Comment