Add Begin of CrimeStats
This commit is contained in:
parent
75fde4863d
commit
9b1c0ef213
@ -2,9 +2,11 @@
|
||||
#include "Aufg1/forLoop.h"
|
||||
#include "Aufg2/GuestList.h"
|
||||
#include "Aufg3/Phonebook.h"
|
||||
#include "Aufg4/CrimeStats.h"
|
||||
|
||||
int main() {
|
||||
// Aufg1Main();
|
||||
// Aufg2Main();
|
||||
Aufg3Main();
|
||||
// Aufg3Main();
|
||||
Aufg4Main();
|
||||
}
|
||||
|
109
Aufg4/CrimeStats.cpp
Normal file
109
Aufg4/CrimeStats.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include "CrimeStats.h"
|
||||
#include "../Aufg2/GuestList.h"
|
||||
|
||||
// cdatetime,
|
||||
// address,
|
||||
// district,
|
||||
// beat,
|
||||
// grid,
|
||||
// crimedescr,
|
||||
// ucr_ncic_code,
|
||||
// latitude,
|
||||
// longitude,
|
||||
typedef struct CRIME{
|
||||
std::string cdatetime;
|
||||
std::string address;
|
||||
std::string district;
|
||||
std::string beat;
|
||||
std::string grid;
|
||||
std::string crimedescription;
|
||||
std::string ucr_ncic_code;
|
||||
std::string latitude;
|
||||
std::string longitude;
|
||||
} Crime;
|
||||
|
||||
void split(const std::string& s, char c,std::vector<std::string>& v) {
|
||||
std::string::size_type i = 0;
|
||||
std::string::size_type j = s.find(c);
|
||||
|
||||
while (j != std::string::npos) {
|
||||
v.push_back(s.substr(i, j-i));
|
||||
i = ++j;
|
||||
j = s.find(c, j);
|
||||
|
||||
if (j == std::string::npos)
|
||||
v.push_back(s.substr(i, s.length()));
|
||||
}
|
||||
}
|
||||
|
||||
std::string readFile(std::string &fileName) {
|
||||
std::string content;
|
||||
std::ifstream infile(fileName);
|
||||
infile.open(fileName);
|
||||
|
||||
if (!infile.is_open()) {
|
||||
std::cout << "File does not exist" << std::endl;
|
||||
return "FAILED_TO_READ_FILE";
|
||||
}
|
||||
|
||||
std::string line;
|
||||
|
||||
while (std::getline(infile, line)) {
|
||||
std::cout << line << std::endl;
|
||||
content += line;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
Crime* stringToCrime(std::string &input) {
|
||||
std::vector<std::string> tokens;
|
||||
split(input, ',', tokens);
|
||||
|
||||
Crime* thisCrime = new Crime;
|
||||
for (int i = 0; i < tokens.size(); i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
thisCrime->cdatetime = tokens[0];
|
||||
break;
|
||||
case 1:
|
||||
thisCrime->address = tokens[1];
|
||||
break;
|
||||
case 2:
|
||||
thisCrime->district = tokens[2];
|
||||
break;
|
||||
case 3:
|
||||
thisCrime->beat = tokens[3];
|
||||
break;
|
||||
case 4:
|
||||
thisCrime->grid = tokens[4];
|
||||
break;
|
||||
case 5:
|
||||
thisCrime->crimedescription = tokens[5];
|
||||
break;
|
||||
case 6:
|
||||
thisCrime->ucr_ncic_code = tokens[6];
|
||||
break;
|
||||
case 7:
|
||||
thisCrime->latitude = tokens[7];
|
||||
break;
|
||||
case 8:
|
||||
thisCrime->longitude = tokens[8];
|
||||
default:
|
||||
}
|
||||
}
|
||||
return thisCrime;
|
||||
}
|
||||
|
||||
void Aufg4Main() {
|
||||
// std::string fileName = "../Aufg4/IO-Files/SacramentocrimeJanuary2006.csv";
|
||||
std::string fileName = "../Aufg4/IO-Files/debugging.test";
|
||||
std::string content = readFile(fileName);
|
||||
std::vector<Crime> vector;
|
||||
|
||||
|
||||
}
|
13
Aufg4/CrimeStats.h
Normal file
13
Aufg4/CrimeStats.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef CRIMESTATS_H
|
||||
#define CRIMESTATS_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void split(const std::string& s, char c,std::vector<std::string>& v);
|
||||
|
||||
void Aufg4Main();
|
||||
|
||||
std::string readFile(std::string &filename);
|
||||
|
||||
|
||||
#endif //CRIMESTATS_H
|
Loading…
Reference in New Issue
Block a user