So, I'm trying to write this program here are the listen instructions.
1. You are going to write a program that uses 3 input files and 3 output files
2. your program will include a function template that sorts an array of values in ascending order. the function will receive an unordered array and will return in an ordered array. The function will not perform any input or output. your template will contain two parameters: a generic array and an integer. The int indicates the number of elements in the array to be stored.
3. read the 3 input files into 3 arrays of 100 positions each. call the function template to sort them. Write the sorted data in the arrays to 3 output files.
4. Since none of the files contains 100 values you must count the number of values in each file as you read it. This number will be passed to the sort function to indicate how many values should be sorted.
I feel like I'm pretty much done, here is what I have so far
#include <iostream>
#include <fstream>
using namespace std;
template< typename T >
void sortArray ( const T * const array[], const int count)
{
int smallest;
for int ( i = 0; i < count; i++)
{
smallest = i;
for (int index = i +1; index < count; index++
if (array[index] < array [smallest])
smallest = index;
T temp = array[i]
array[i] = array[smallest];
array[smallest] = temp;
}
}
int main()
{
ifstream inputQuotes ("QuoteFile.txt");
ofstream outputQuotes ("outputQuotes.txt");
ifstream inputInts ("IntFile.txt");
ofstream outputInts ("outputInts.txt");
ifstream inputFloats ("FloatFile.txt");
ofstream outputFloats ("outputFloats.txt");
const int size = 100;
string quoteArray[size];
int intArray[size];
double floatArray[size];
sortArray(quoteArray, size);
cout << "Array with quotes in order contains:" << endl;
for (int i = 0; i < size; i++)
cout << quoteArray[i] << endl;
sortArray(intArray, size);
cout << "Array with ints in order contains:" << endl;
for (int i = 0; i < size; i++)
cout << intArray[i] << endl;
sortArray(floatArray, size);
cout << "Array with floats in order contains:" << endl;
for (int i = 0; i < size; i++)
cout << floatArray[i] << endl;
}
And here are my errors codes:
Error 1 error C2958: the left parenthesis '(' found at 'h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp(22)' was not matched correctly h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 29
Error 2 error C2784: 'void sortArray(const T *const [],const int)' : could not deduce template argument for 'const T *const []' from 'std::string [100]' h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 49
Error 3 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 53
Error 4 error C2784: 'void sortArray(const T *const [],const int)' : could not deduce template argument for 'const T *const []' from 'int [100]' h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 56
Error 5 error C2784: 'void sortArray(const T *const [],const int)' : could not deduce template argument for 'const T *const []' from 'double [100]' h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 63
6 IntelliSense: no instance of function template "sortArray" matches the argument list h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 49
7 IntelliSense: no operator "<<" matches these operands h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 53
8 IntelliSense: no instance of function template "sortArray" matches the argument list h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 56
9 IntelliSense: no instance of function template "sortArray" matches the argument list h:\c++\programming assignment 5\programming assignment 5\programming assignment 5\main.cpp 63
Not sure really where to go. I feel like it's me opening the multiple files that's messing me up. I've never had to do it before, so it's a bit new to me.