Thursday, July 30, 2009

My C++ program has only 3 error...so pl correct them and send correct code?

#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;fstream.h%26gt;


const TAG_VALUE=1;


const int TAG_END_OF_STREAM=2;


class mergesort


{


private:


int a[],b[],c[10],i,j,t,k;


public:


void enter_numbers()


{


cout%26lt;%26lt;"plz enter 5 numbers"%26lt;%26lt;endl;


cin%26gt;%26gt;a[k];


cout%26lt;%26lt;"plz enter another 5 numbers"%26lt;%26lt;endl;


cin%26gt;%26gt;b[k];


}


void display_numbers()


{


c[]=a[]+b[];


for(i=0;i%26lt;=10;i++);


{


for(j=1;j%26lt;=10;j++);


if(c[i]%26gt;c[j])


{


t=c[i];


c[i]=c[j];


c[j]=t;


}


}


cout%26lt;%26lt;"The MERGE_SORTED NUMBERS were:"%26lt;%26lt;c[]%26lt;%26lt;endl;


}


};


void main()


{


mergesort m1;


fstream f1,f2,f3;


f1.open("file.dat",ios::in|ios::out|io...


while(f1)


{


m1.enter_numbers();


f1.write(%26amp;m1,sizeof(mergesort));


}


f2.open("file.dat",ios::in|ios::out|io...


while(f2)


{


m1.enter_numbers();


f2.write(%26amp;m1,sizeof(mergesort));


}


f3.open("file.dat",ios::in|ios::out|io...


while(f3)


{


m1.display_numbers();


f3.read(%26amp;m1,sizeof(mergesort));


}


f3.close();


getch();


}

My C++ program has only 3 error...so pl correct them and send correct code?
Dude.. send entire code and errors that the compiler throws up.





One error I can notice is usage of a[] Array size should be declared in definition itself; like you have done for c[10]





That style of declaration is allowed only in function calls.
Reply:1) const TAG_VALUE=1; // need a type like int!





2) c[]=a[]+b[];// no positions c[i] = a[i] + b[i];





3) cout%26lt;%26lt;"The MERGE_SORTED NUMBERS were:"%26lt;%26lt;c[]%26lt;%26lt;endl; // again missing the position.





and this might be 'while(f1)' probbably better to check for EOF, also whats with the ... never do that, its horrible.
Reply:I'd recommend doing your own homework... And a please would be nice...


No comments:

Post a Comment