i am new to c++ and have this assigment to do and i am having problems with all of it basically, reading in from a file, creating the functions etc. i ended up deleting the code i wrote for it because there was just too many errors. can anyone give me code for this and give lots of comments so i could go through it step by step to see whats goin on? it would be a great help to me. i am not to use classes in this program. and i am to use selection sort to sort the numbers from high to low.
the assigment is below.
"The following Program sorts a list of integer numbers read in from the file numbers.dat (obviously not sorted in this file ). The maximum number of integers in the file is 20. The first number in the file is the number of integers in the file. The values when sorted will be printed to the file sorted.txt. Write this program will 3 function to read in, sort and write out the data."
#include <iostream.h>
…….any required header files ???
void getvalues( int array[], int size ) ;
void sort( int array[], int size ) ;
void outvalues( int array[], int size ) ;
main()
{
.........put in code
return 0;
}
ok thats fair enough.
here is what i have written for the function to read in from the file. i think the funtion is close enough to doing what i want but i amn't sure how to call it in the main program,in particular what goes in the brackets after getvalues.. these are the errors i got
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 2 error C2660: 'getvalues' : function does not take 0 arguments
main()
{
getvalues() ;
return 0;
}
void getvalues( int array[], int size )
{
ifstream ip("c:\\numbers.dat");
ofstream op("c:\\sorted.txt");
ip>>size;
for(int num=0; num< size; num++)
ip>>array[num];
ip.close();
Where is the return type for your main function?
And also, your function has no default arguments(args), and it takes two args so you cannot call it without passing the two args of the specified type.