二重リンク リスト クラスを使用して学生のリストを作成しようとしています。これを行うために、学生とノードクラスを組み合わせることになりました。これを実装するためのより良い方法があることは理解していますが、これが私が選んだ道であり、それを機能させようとしています。ノード (Student) を push_back すると、Node クラスが呼び出され、次に Record クラスが呼び出され、次に Course クラスが呼び出されます。
メイン関数でノードのコンストラクターを呼び出すと、「(名前、コース、学期) がこのスコープで宣言されていない」というエラーが表示されます。これが混乱している可能性があることは承知していますが、なぜこれが機能しないのかについて誰かが私に考えを与えることができますか?
#include <iostream>
#include "LinkedList.h"
#include "Stack.h"
#include "Queue.h"
using namespace std;
int main () {
LinkedList* list = new LinkedList();
list->push_back(John, Math34, Summer2012);
return 0;
}
私のLinkedListクラス。読みやすく、問題の根本を見つけやすいように、ほとんどの関数を削除しました。
#ifndef LinkedList_H
#define LinkedList_H
#include "Node.h"
#include <iostream>
using namespace std;
class LinkedList{
public:
LinkedList()
{
front = NULL;
back = NULL;
size = 0;
}
void aCourse(string n, Course* c, string s)
{
if (front == NULL)
return;
Node *temp = front;
for(int i = 0; i < size; i++)
{
if(n == temp->name)
front->addCourse(c, s);
} }
void push_back(string n, Course* c, string s)
{
if (back == NULL)
{
back = new Node(NULL, NULL, n);
front = back;
size++;
back->addCourse(c, s);
return;
}
else {
Node *newnode = new Node(NULL, NULL, n);
newnode->addCourse(c, s);
back->next = newnode;
newnode->prev = back;
back = newnode;
}
#endif
私のノード/学生クラス:
#ifndef NODE_H
#define NODE_H
#include "Record.h"
#include "Course.h"
class Node
{
public:
Node(Node* n = NULL, Node* p = NULL, string v = NULL)
{
prev = p;
next = n;
name = v;
rec = new Record;
}
void addCourse(Course* c, string sem)
{
rec->addCourse(c, sem);
}
void dropCourse(Course* c)
{
rec->dropCourse(c);
}
Record* getRecord() { return rec; }
void printAllRecords()
{
rec->print();
}
void setStudentScore(Course* c, int score)
{
rec->setCourseScore(c, score);
}
string name;
Record* rec;
Node* next;
Node* prev; //for double linked list
char value;
};
#endif
私の記録クラス:
#ifndef Record_H
#define Record_H
#include "Course.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class Record
{
public:
Record()
{
courses = new vector<Course*>();
semesters = new vector<string>();
scores = new vector<int>();
}
~Record()
{
delete courses;
delete semesters;
delete scores;
}
void addCourse(Course* c, string sem)
{
courses->push_back(c);
semesters->push_back(sem);
scores->push_back(0);
}
void dropCourse(Course* c)
{
vector<Course*>::iterator it = courses->begin();
vector<string>::iterator it2 = semesters->begin();
while ( it != courses->end() && it2 != semesters->end())
{
if (c == *it)
break;
it++;
it2++;
}
courses->erase(it);
semesters->erase(it2);
}
void setCourseScore(Course* c, int g)
{
vector<Course*>::iterator it = courses->begin();
vector<int>::iterator it2 = scores->begin();
while ( it != courses->end() && it2 != scores->end())
{
if (c == *it)
break;
it++;
it2++;
}
it2 = scores->insert(it2, g);
}
void computeAccGPA()
{
}
vector<Course*>* getCourses() { return courses; }
void print(){
vector<Course*>::iterator it = courses->begin();
vector<string>::iterator it2 = semesters->begin();
vector<int>::iterator it3 = scores->begin();
while ( it != courses->end() && it2 != semesters->end() && it3 != scores->end())
{
(*it)->print();
cout<<" "<<*it2<<" "<<*it3<<endl;
it++;
it2++;
it3++;
}
cout<<endl;
}
private:
vector<Course*>* courses;
vector<string>* semesters;
vector<int>* scores;
};
#endif
私のコースクラス:
#ifndef Course_H
#define Course_H
#include <string>
#include <iostream>
using namespace std;
class Course
{
public:
Course(string n, string f, int c)
{
name = n;
faculty = f;
credit =c;
}
~Course() {}
void print()
{
cout<<name<<" "<<faculty<<" ";//<<c<<" ";
}
private:
string name;
string faculty;
int credit;
};
#endif