Skip to content
Snippets Groups Projects
Commit 6e97f8d0 authored by Eraser's avatar Eraser
Browse files

Aufgabe 3 done

parent 228fc247
No related branches found
No related tags found
No related merge requests found
...@@ -3,4 +3,4 @@ project(magicCards) ...@@ -3,4 +3,4 @@ project(magicCards)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
add_executable(magicCards main.cpp aufgabe1.h aufgabe1.cpp Cards.h) add_executable(magicCards main.cpp aufgabe1.h aufgabe1.cpp Cards.h functions.h functions.cpp)
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
//Aufgabe Nr.2 //Aufgabe Nr.2
struct Cards { struct Cards {
//cmc and count are also strings to make it easier for the getListOfCards function
public: public:
std::string name; std::string name;
std::string mana; std::string mana;
int cmc; std::string cmc;
std::string type; std::string type;
std::string count; std::string count;
......
//
// Created by Eray düzenli on 13.04.23.
//
#include <iostream>
#include "functions.h"
#include <fstream>
#include <stdexcept>
#include <sstream>
#include <vector>
//std::list<Cards> getListOfCards(const std::string& filename)
std::list<Cards> getListOfCards(const std::string& filename) {
std::ifstream file(filename);
if(!file) {
throw std::runtime_error("Error: Unable to open file " + filename);
}
//temp string to save line
std::string temp;
//Output
std::list<Cards> CardsList;
//get every line of scrambled.txt
while (std::getline(file, temp)) {
std::stringstream streamData(temp);
//"cut" the string at the vertical bars(|)
char delim ='|';
//string vector to hold the cut parts
std::vector<std::string> stringVector;
//temp to store Card attributes
std::string attr;
//go over every line, cut line accordingly and push it at the back of the vector
while (getline(streamData, attr, delim)) {
stringVector.push_back(attr);
}
//assign every cut out part to the according attribute
std::string name = stringVector[0];
std::string mana = stringVector[1];
std::string cmc = stringVector[2];
std::string type = stringVector[3];
std::string count = stringVector[4];
//create card object and assign attributes to it
Cards card;
card.cmc = cmc;
card.mana = mana;
card.name = name;
card.type = type;
card.count = count;
//push Card object at the end of the List
CardsList.push_back(card);
}
//close .txt file
file.close();
/* just for testing
for (const auto& card : CardsList) {
std::cout << card.name << ", " << card.mana << ", " << card.cmc << ", " << card.type << ", " << card.count << std::endl;
}
*/
//return the cards as a list
return CardsList;
}
\ No newline at end of file
//
// Created by Eray düzenli on 13.04.23.
//
#pragma once
#include <string>
#include <iostream>
#include <list>
#include "Cards.h"
std::list<Cards> getListOfCards(const std::string& filename);
#include <iostream> #include <iostream>
#include "aufgabe1.h" #include "aufgabe1.h"
#include "Cards.h" #include "Cards.h"
#include "functions.h"
int main() { int main() {
/*
std::cout << "Info 3 Projekt Nr.1" << std::endl; std::cout << "Info 3 Projekt Nr.1" << std::endl;
levenshteinDistance("kitten", "sitting"); levenshteinDistance("kitten", "sitting");
levenshteinDistance("industry", "interests"); levenshteinDistance("industry", "interests");
...@@ -16,6 +18,9 @@ int main() { ...@@ -16,6 +18,9 @@ int main() {
s.name = "peter"; s.name = "peter";
s.type = "uwu"; s.type = "uwu";
std::cout << s.name << s.count << s.type << s.cmc << std::endl; std::cout << s.name << s.count << s.type << s.cmc << std::endl;
//To-Do, only absolute path works
*/
getListOfCards("/Users/erayduzenli/CLionProjects/magicCards/scrambled.txt");
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment