Witam ;) Stworzyłem już projekt który działa w 100% jeżeli jest w jednym pliku. Teraz muszę podzielić go na pliki źródłowe, ale po podzieleniu już niestety wyskakują mi błędy że np struktura jest zredefiniowana, poczytałem w błędzie i wynika to prawdopodobnie z tego że źle połączyłem pliki lub coś.
Tutaj wrzucam moje kody.
Task.h
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
struct Task
{
string question;
string answers[ 5 ];
char correct_answer;
int question_score;
void showTask();
Task( string q, string a1, string a2, string a3, string a4, string a5, char ca, int qs )
{
question = q;
answers[ 0 ] = a1;
answers[ 1 ] = a2;
answers[ 2 ] = a3;
answers[ 3 ] = a4;
answers[ 4 ] = a5;
correct_answer = ca;
question_score = qs;
}
};
Task.cpp
void Task::showTask()
{
cout << "\n";
cout << question << "\n";
for( int i = 0; i < 5; i++ ) {
cout << answers[ i ];
cout << endl;
}
}
TestContent.h
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
class TestContent
{
private:
char guess;
int total=0;
vector<Task> tasks;
public:
int get_total();
char get_guess();
string get_question(int it);
void set_total(int t);
void set_guess(char g);
void addTask(const Task& t);
void removeTask(size_t idx);
void accessQuestion(int it);
void showAllQuestions();
void askQuestion(const int& it);
};
TestContent.cpp
int TestContent::get_total(){
return total;
}
char TestContent::get_guess(){
return guess;
}
string TestContent::get_question(int it) //getter do vectora pytań
{
return tasks[it].question;
}
void TestContent::set_total(int t)
{
total = t;
}
void TestContent::set_guess(char g)
{
guess = g;
}
void TestContent::addTask(const Task& t) // funkcja dodawania Task do wektora
{
tasks.push_back(t);
}
void TestContent::removeTask(size_t idx) //funkcja usuwająca pytanie z wektora
{
assert(idx < tasks.size());
tasks.erase(begin(tasks) + idx);
}
void TestContent::accessQuestion(int it) // funkcja wyświetlania po indeksie w wektorze
{
assert(it < tasks.size());
tasks[it].showTask();
}
void TestContent::showAllQuestions() // funkcja wyswietlajaca wszystkie pytania z wektora
{
for(int i=0; i<tasks.size(); i++)
{
askQuestion(i);
}
cout<<"Your score is: "<<total<<endl;
if (total > 30)
cout <<"exam passed"<<endl;
else
cout<<"exam failed"<<endl;
}
void TestContent::askQuestion(const int& it) // funkcja showTask + żądanie odpowiedzi
{
no i main.cpp
Task t1( stworzone pytanie..);
Task t2(stworzone pytanie..);
Task t3(stworzone pytanie..);
// t2.showTask(); // działa
TestContent test; // działa
test.addTask(t1); // działa
test.addTask(t2);
test.addTask(t3);
test.showAllQuestions(); // działa
test.accessQuestion(1); // działa
test.removeTask(1); //działa
test.askQuestion(1); // działa
return 0;
}
Może mi ktoś powiedzieć, jaki #include mam zrobić do jakiego pliku? Pozdrawiam