Здесь изображение проблемы я должен решить: http://i.imgur.com/WLHntVC.pngпереопределение ошибки параметра Формат
У меня есть приличное количество сделать, но я действительно застрял.
код у меня до сих пор находится ниже
Заголовочный файл: voter.h
#include <string>
#include <iostream>
#include <vector>
class Voter {
int id;
std::string votes;
public:
Voter(int id, std::string votes) {
this->id = id;
this->votes = votes;
}
char getVote(int i) {
return votes[i];
}
std::string getVotes() {
return votes;
}
int getID() {
return id;
}
};
Source1.cpp
#include "Voter.h"
#include <fstream>
#include <algorithm>
#include <iomanip>
const int TALLY_MAX = 9;
void readFile(std::string fileName, Voter** v, int& size) {
std::ifstream is(fileName);
Voter** v = nullptr;
int id;
size = 0;
std::string str;
while (!is.eof()){
std::getline(is,str);
size++;
}
v = new Voter*[size];
int i = 0;
while (!is.eof()){
is >> id >> str;
v[i] = new Voter(id, str);
i++;
}
for(int i = 0; i < size; i++)
delete v[i];
delete [] v;
}
void tallyVotes(std::vector<Voter> v, int tally[]) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < TALLY_MAX/2; j++) {
int vote = v[i].getVote(j) - 'A';
tally[vote]++;
}
}
}
// sort using a custom function object
struct {
bool operator()(Voter a, Voter b)
{
return a.getID() < b.getID();
}
} customLess;
int main(){
std::vector<Voter> v = readFile("votes.txt");
int tally[TALLY_MAX];
for (int i = 0; i < TALLY_MAX; i++)
tally[i] = 0;
tallyVotes(v, tally);
std::sort(v.begin(), v.end(), customLess);
for (int i = 0; i < v.size(); i++) {
std::cout << std::setfill('0') << std::setw(4) << v[i].getID() << " " << v[i].getVotes() << "\n";
}
std::cout << "\n\nVote Totals\n";
for (int i = 0; i < TALLY_MAX; i++)
std::cout << (char)(i + 'A') << " " << tally[i] << "\n";
//return 0;
std::cin.get();
std::cin.ignore();
}
Любая помощь будет принята с благодарностью.
Ваш вопрос не задать вопрос. Какую часть вы застряли? –
** близко ** без вопросов. –