use fstream to get the number from notepad file

I am using visual c++ express edition, but cannot take the data from the notepad file .txt
So the code cannot go out the calculation function. Hope you guy can save my problem.

Download my code as below...thank you for view it

http://www.mediafire.com/?mjmjnymvinh
i won´t download ur code... post it in here!
// i wonder know why there is no calculation number function one ?? Thank for viewing
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <iomanip.h>
#include <conio.h>

#define LAJUR 6
#define BARIS 1036

void data();
int count=0, number,i,j;
char k;
double newcase[LAJUR];
double localsim[BARIS][LAJUR];

int oldCases[BARIS][LAJUR+1];

fstream infile;
fstream outfile;

void main(){
data();
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Car Classify System *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\n";
//INPUT NEW CASE

cout << "\n\n1st data : Buying --> v-high[1], high[2], med[3], low[4]\n"
<< "2nd data : Maint --> v-high[1], high[2], med[3], low[4]\n"
<< "3rd data : Doors --> 2,3,4,5-more [5]\n"
<< "4th data : Person --> 2,4,more [5]\n"
<< "5th data : Lug_boot --> big[1], med[2], small[3]\n"
<< "6th data : Safety --> high[1], med[2], low[3]\n\n";
for(i=0;i<LAJUR;i++){
cout << "Insert data " <<i+1 <<":\n";
cin >> newcase[i];
}
cout << "New Case: {";
for(i=0;i<LAJUR;i++){
cout << newcase[i] <<",";
}
cout << "}\n\n";

//CALCULATE WEIGHT

int weight[LAJUR]={1,1,1,1,1,1};
int sumweight=0;
double normWeight[LAJUR]={0,0,0,0,0,0};

for(i=0;i<LAJUR;i++){
sumweight= sumweight + weight[i];
}
cout << "sumweight: " << sumweight << "\n";
for(i=0;i<LAJUR;i++){
normWeight[i] = double(weight[i])/double(sumweight);
}

//CALCULATE LOCAL SIMILARITY

for(i=0;i<BARIS;i++){
for(j=1;j<LAJUR+1;j++)
{
if(newcase[j-1]==oldCases[i][j]){
localsim[i][j]=1;
}
else{
localsim[i][j]=0;
}
}
}
//CALCULATE GLOBAL SIMILARITY
double globalsim[BARIS]={0,0,0,0,0,0};
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Global Similarity *";
cout << "\n***************************************";
cout << "\n\nGlobal Similarity " << "Class\n";

for (i=0;i<BARIS;i++){
for(j=0;j<LAJUR;j++){
globalsim[i] = (globalsim[i] + localsim[i][j+1]*normWeight[j]);
}
globalsim[i]= globalsim[i]*100;
//cout << "\n";
//cout << globalsim[i] << "% "<< oldCases[i][0];
}
for(i=0;i<10;i++){
cout << "\n";
cout << globalsim[i] << "% " << oldCases[i][0];
}

//SORT SIMILARITY RESULT
double temp;
double tempClass[BARIS];
for(i=0;i<BARIS;i++){
tempClass[i]=oldCases[i][0];
}
for(i=0;i<BARIS;i++){
for(j=0;j<BARIS;j++){
if(globalsim[j]<globalsim[j+1]){
temp=globalsim[j];
globalsim[j]=globalsim[j+1];
globalsim[j+1]=temp;

temp=tempClass[j];
tempClass[j]=tempClass[j+1];
tempClass[j+1]=temp;
}
else{
}
}
}
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Sorted Similarity Result *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\nGlobal Similarity (Sort) "<<"Class\n\n";

for(i=0;i<10;i++){
cout << globalsim[i] << "% " << tempClass[i] <<"\n";
}
//MAJORITY VOTING
int class1 =0,class2=0,class3=0,class4=0;
cout << "\n\n*************************************";
cout << "\n* *";
cout << "\n* Majority Voting *";
cout << "\n* *";
cout << "\n*************************************";
cout << "\n\nGlobal Similarity "<<" Class\n\n";
for(i=0;i<10;i++){
if(globalsim[i] > 80.00)
{
cout << globalsim[i] << "% " << tempClass[i] << "\n";
{ if(tempClass[i]==1)
class1=class1+1;
else if (tempClass[i]==2)
class2=class2+1;
else if (tempClass[i]==3)
class3=class3+1;
else if (tempClass[i]==4)
class4=class4+1;
}
}
}
int tempValue;
int array[4];
array[0]=class1;
array[1]=class2;
array[2]=class3;
array[3]=class4;

for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(array[i] <= array[j])
{
tempValue=array[i];
array[i]=array[j];
array[j]=tempValue;
}
}
}
//PRINT RESULT
cout << "\n\n";
cout<<"Class 1 ="<< class1<<endl;
cout<<"Class 2 ="<< class2<<endl;
cout<<"Class 3 ="<< class3<<endl;
cout<<"Class 4 ="<< class4<<endl;

cout << "\nThe class for the new case is ";
if(array[3]==class1)
cout << "v-good"<<endl;
else if(array[3]==class2)
cout << "good"<<endl;
else if(array[3]==class3)
cout << "acc"<<endl;
else if(array[3]==class4)
cout << "unacc"<<endl;
else {
cout << " Sorry, system cannot define the car's class!";

}
cout << "\n\n";
}
void data()
{
infile.open("car1.txt",ios::in);
//cout<<"No Class Buying Maint Doors Persons "
//<<"Lug_boot Safety\n\n";
for(i=0;i<BARIS;i++)
{
infile>>oldCases[i][0];
infile>>oldCases[i][1];
infile>>oldCases[i][2];
infile>>oldCases[i][3];
infile>>oldCases[i][4];
infile>>oldCases[i][5];
infile>>oldCases[i][6];
}
//Knowledge base output
/*for(i=0;i<10;i++)
{ number=i+1;
cout<<setw(4)<<setiosflags(ios::left)<<number
<<oldCases[i][0]<<" "
<<oldCases[i][1]<<" "
<<oldCases[i][2]<<" "
<<oldCases[i][3]<<" "
<<oldCases[i][4]<<" "
<<oldCases[i][5]<<" "
<<oldCases[i][6]<<endl;
}
cout<<"Count = "<<count;*/
}
//This is the car1.txt file...
1 1 2 2 3 4 unacc
1 1 2 2 3 3 unacc
1 1 2 2 3 2 unacc
1 1 2 2 3 4 unacc
1 1 2 2 3 3 unacc
1 1 2 2 3 2 unacc
1 1 2 2 1 4 unacc
1 1 2 2 1 3 unacc
1 1 2 2 1 2 unacc
1 1 2 4 3 4 unacc
1 1 2 4 3 3 unacc
1 1 2 4 3 2 unacc
1 1 2 4 3 4 unacc
1 1 2 4 3 3 unacc
1 1 2 4 3 2 unacc
// In my sourcecode variable BARIS means by line and LAJUR is the column. TQ
Topic archived. No new replies allowed.