Okay so I asked a question earlier about building arrays using a template class and I honestly still have no idea what I'm doing. So I'll just post what I have and the errors I got.
Main DSHW.cpp
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <cstdlib>
#include "GroupedArray.h"
using namespace std;
/**
* Add a string representing an integer to an existing integer value
* that represents a partial sum
* Returns the sum
*/
int convertAndAdd(int sum, string next) {
return sum + atoi(next.c_str());
}
int main()
{
// array of strings based on what you get if you download
// results from a quiz on Blackboard
string submission[] = {"aaa111", "Smith", "Sam",
"Question ID 1", "To optimize the query select * from books b, publisher p where b.publisherID = p.id and b.subjectID <> 1 and p.city = 'Chicago' , (",
"an index on the publisher table's id is only helpful if it is a hashing-based index",
"10", "0", "",
"Question ID 2", "Postgres (",
"supports multiple languages for writing stored procedures",
"10", "10", "",
"Question ID 3", "For a business rule object A can have several B's , (",
"should be implemented using a table other than the table representing A's",
"10", "10", ""
};
const int STUDENT_COLUMNS = 3;
const int NUM_QUESTIONS = 3;
const int GROUP_SIZE = 6;
const int MAX_SCORE_FIELD = 3;
const int SCORE_FIELD = 4;
GroupedArray<string, int> quiz((submission+STUDENT_COLUMNS), NUM_QUESTIONS, GROUP_SIZE);
int total_score;
int max_score;
cout << "This is a test driver for the GroupedArray class" << endl;
total_score = accumulate(quiz.nthField(SCORE_FIELD), quiz.end(), 0, convertAndAdd);
max_score = accumulate(quiz.nthField(MAX_SCORE_FIELD), quiz.end(), 0, convertAndAdd);
cout << "The score = " << total_score << endl;
cout << "The percentage = " << 100 * total_score / (float) max_score << endl;
// comment this next line out for Linux or Mac OS
system("pause");
return 0;
}
GroupedArray.h
#ifndef _GROUPEDARRAY
#define _GROUPEDARRAY
#include "stdafx.h"
#include <vector>
#include <string>
using namespace std;
template<class T>
class GroupedArray{
protected:
T container;
T col;
T num;
public:
GroupedArray(T a, T b, T c){ //constructor
container = a;
size = b;
col = c;
}
nthField(T place){ //goes through array searching for first instance of parameter
for(T i=0; i < place; i++);
}
end(){
for(int* it = std::begin(array); it!=std::end(array); ++it)
{
cout << *it << endl;
}
return 0;
}//takes no parameter and points to end of array.
~GroupedArray(); //Destrutor
};
#endif
And when I try to build I get the following errors
groupedarray.h(23): error C4430: missing type specifier -int assumed. Note: C++ does not support default-int
groupedarray.h(34) : see reference to class template instantiation 'GroupedArray' being compiled
groupedarray.h(25): warning C4183: 'nthField': missing return type; assumed to be a member function returning 'int'
groupedarray.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
groupedarray.h(32): warning C4183: 'end': missing return type; assumed to be a member function returning 'int'
dshw1.cpp(43): error C2977: 'GroupedArray' : too many template arguments
groupedarray.h(12) : see declaration of 'GroupedArray'
dshw1.cpp(43): error C2514: 'GroupedArray' : class has no constructors
groupedarray.h(12) : see declaration of 'GroupedArray' dshw1.cpp(50): error C2662: 'GroupedArray::end' : cannot convert 'this' pointer from 'GroupedArray' to 'GroupedArray &'
dshw1.cpp(50): error C2780: '_Ty std::accumulate(_InIt,_InIt,_Ty)' : expects 3 arguments - 4 provided
I'm getting pretty desperate here so all help is appreciated.