cleanup #4
@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
class FileHelper {
|
class FileHelper {
|
||||||
public:
|
public:
|
||||||
FileHelper();
|
FileHelper() = default;
|
||||||
|
|
||||||
~FileHelper();
|
~FileHelper() = default;
|
||||||
|
|
||||||
static bool FileExists(char *path);
|
static bool fileExists(char *path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -4,13 +4,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class FileReader {
|
class FileReader {
|
||||||
public:
|
public:
|
||||||
FileReader();
|
FileReader() = default;
|
||||||
|
|
||||||
~FileReader();
|
~FileReader() = default;
|
||||||
|
|
||||||
static std::string GetFile(char *path);
|
static string getFile(char *path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -8,11 +8,12 @@ using namespace std;
|
|||||||
|
|
||||||
class NumberHelper {
|
class NumberHelper {
|
||||||
public:
|
public:
|
||||||
NumberHelper();
|
NumberHelper() = default;
|
||||||
|
|
||||||
~NumberHelper();
|
~NumberHelper() = default;
|
||||||
|
|
||||||
static vector<int> GetNumbers(string csv);
|
static vector<int> getRolls(string csv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -7,12 +7,12 @@ using namespace std;
|
|||||||
|
|
||||||
class PrintFrames {
|
class PrintFrames {
|
||||||
public:
|
public:
|
||||||
PrintFrames();
|
PrintFrames() = default;
|
||||||
|
|
||||||
~PrintFrames();
|
~PrintFrames() = default;
|
||||||
|
|
||||||
static void PrintHeader(vector<int> rolls);
|
static void printHeader(vector<int> rolls);
|
||||||
static void PrintValue(vector<int> rolls);
|
static void printValue(vector<int> rolls);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -8,11 +8,11 @@ using namespace std;
|
|||||||
|
|
||||||
class ScoreCalculator {
|
class ScoreCalculator {
|
||||||
public:
|
public:
|
||||||
ScoreCalculator();
|
ScoreCalculator() = default;
|
||||||
|
|
||||||
~ScoreCalculator();
|
~ScoreCalculator() = default;
|
||||||
|
|
||||||
static int GetScore(vector<int> rolls);
|
static int getScore(vector<int> rolls);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,10 +1,7 @@
|
|||||||
#include "../include/FileHelper.h"
|
#include "../include/FileHelper.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
FileHelper::FileHelper() {};
|
bool FileHelper::fileExists(char *path){
|
||||||
FileHelper::~FileHelper() {};
|
|
||||||
|
|
||||||
bool FileHelper::FileExists(char *path){
|
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
// Check if file exists, and if it isn't a folder.
|
// Check if file exists, and if it isn't a folder.
|
||||||
|
@ -2,15 +2,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
FileReader::FileReader() {};
|
string FileReader::getFile(char *path){
|
||||||
FileReader::~FileReader() {};
|
ifstream file(path);
|
||||||
|
|
||||||
std::string FileReader::GetFile(char *path){
|
|
||||||
std::ifstream file(path);
|
|
||||||
|
|
||||||
std::string line;
|
string line;
|
||||||
|
|
||||||
std::getline(file, line);
|
getline(file, line);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
@ -3,16 +3,14 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
NumberHelper::NumberHelper() {};
|
vector<int> NumberHelper::getRolls(string csv){
|
||||||
NumberHelper::~NumberHelper() {};
|
vector<int> rolls;
|
||||||
|
stringstream ss(csv);
|
||||||
std::vector<int> NumberHelper::GetNumbers(std::string csv){
|
string number;
|
||||||
std::vector<int> rolls;
|
|
||||||
std::stringstream ss(csv);
|
|
||||||
std::string number;
|
|
||||||
|
|
||||||
while (std::getline(ss, number, ',')) {
|
// Get number from the CSV file, split by comma, and convert to int.
|
||||||
rolls.push_back(std::stoi(number));
|
while (getline(ss, number, ',')) {
|
||||||
|
rolls.push_back(stoi(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rolls;
|
return rolls;
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
#include "../include/PrintFrames.h"
|
#include "../include/PrintFrames.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
PrintFrames::PrintFrames() {};
|
void PrintFrames::printHeader(vector<int> rolls){
|
||||||
PrintFrames::~PrintFrames() {};
|
|
||||||
|
|
||||||
void PrintFrames::PrintHeader(vector<int> rolls){
|
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
@ -50,7 +47,7 @@ void PrintFrames::PrintHeader(vector<int> rolls){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFrames::PrintValue(vector<int> rolls){
|
void PrintFrames::printValue(vector<int> rolls){
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#include "../include/ScoreCalculator.h"
|
#include "../include/ScoreCalculator.h"
|
||||||
|
|
||||||
ScoreCalculator::ScoreCalculator() {};
|
int ScoreCalculator::getScore(vector<int> rolls) {
|
||||||
ScoreCalculator::~ScoreCalculator() {};
|
|
||||||
|
|
||||||
int ScoreCalculator::GetScore(vector<int> rolls) {
|
|
||||||
int score = 0;
|
int score = 0;
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
|
||||||
|
12
src/main.cpp
12
src/main.cpp
@ -14,18 +14,18 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileHelper::FileExists(argv[1])) {
|
if (!FileHelper::fileExists(argv[1])) {
|
||||||
cerr << "Filepath: " << argv[1] << " doesn't exist.";
|
cerr << "Filepath: " << argv[1] << " doesn't exist.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string file = FileReader::GetFile(argv[1]);
|
string file = FileReader::getFile(argv[1]);
|
||||||
vector<int> rolls = NumberHelper::GetNumbers(file);
|
vector<int> rolls = NumberHelper::getRolls(file);
|
||||||
|
|
||||||
PrintFrames::PrintHeader(rolls);
|
PrintFrames::printHeader(rolls);
|
||||||
PrintFrames::PrintValue(rolls);
|
PrintFrames::printValue(rolls);
|
||||||
|
|
||||||
int score = ScoreCalculator::GetScore(rolls);
|
int score = ScoreCalculator::getScore(rolls);
|
||||||
cout << "Score: " << score << endl;
|
cout << "Score: " << score << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user