Mọi người cho mình xin phép hỏi 1 số vấn đề sau với ạ
- Trong lớp student có thuộc tính là LopSinhHoat nhưng mình đã khai báo forward nhưng vẫn bị lỗi là sao ạ.
- Tại lớp Lecturer dù mình đã định nghĩa rõ hàm dựng và hàm dựng sao chép nhưng khi đưa vào hàm dựng của lớp LopSInhHoat thì vẫn bị lỗi.
- Nếu mình muốn tạo ra danh sách học sinh là 1 con trỏ thì có cần đa năng hóa new ko.
dưới là code thử của mình (chỉ compile chứ chưa viết ct chính) và danh sách lỗi
#include<bits/stdc++.h>
using namespace std;
class LopSinhHoat;
class Student;
class Person{
protected:
string name, adress;
int age;
bool gender;
public:
Person(string , int, string, bool);
Person(const Person&);
virtual ~Person();
};
Person::Person(string nm, int tuoi, string dc, bool gt){
name=nm;
age=tuoi;
adress=dc;
gender=gt;
}
Person::Person(const Person& a){
name = a.name;
age = a.age;
adress = a.adress;
gender = a.gender;
}
Person::~Person(){
}
class Student: public Person{
protected:
string Id;
LopSinhHoat *Lop;
double Diem;
public:
Student(string , int , string, bool, string, double);
~Student();
const Student &operator=(const Student&);
friend istream& operator>>(istream& , Student&);
friend ostream& operator<<(ostream&, const Student&);
string& operator[](int);
};
Student::Student(string nm, int tuoi, string dc, bool gt, string ms, double diem):Person(nm,tuoi,dc,gt){
Id=ms;
Diem=diem;
}
Student::~Student()
{
}
istream& operator>>(istream& in, Student& a){
cout<<"Nhap ten"; getline(in,a.name);
cout<<"Nhap tuoi"; in>>a.age;
cout<<"Nhap dia chi"; getline(in,a.adress);
cout<<"Nhap gioi tinh (true:nam, false:nu)"; in>>a.gender;
cout<<"Nhap ma so"; getline(in,a.Id);
cout<<"Nhap diem"; in>>a.Diem;
}
ostream& operator<<(ostream& out, const Student& a){
out<<"Ten: "<<a.name<<endl;
out<<"Tuoi: "<<a.age<<endl;
out<<"Dia chi: "<<a.adress<<endl;
if(a.gender == true) out<<"Gioi tinh: nam\n";
else out<<"Gioi tinh: nu\n";
out<<"Ma so: "<<a.Id<<endl;
out<<"Diem trung binh: "<<a.Diem;
}
const Student& Student::operator=(const Student& a){
if(this!=&a){
this->name = a.name;
this->age = a.age;
this->adress = a.adress;
this->gender = a.gender;
this->Id = a.Id;
this->Diem = a.Diem;
}
return *this;
}
string& Student::operator[](int i){
return (this->Id);
}
class Lecturer: public Person{
protected:
string Id, Cap;
public:
Lecturer();
Lecturer(string, int, string, bool, string, string);
~Lecturer();
Lecturer(const Lecturer&);
friend istream& operator>>(istream& , Lecturer&);
friend ostream& operator<<(ostream&, const Lecturer&);
const Lecturer &operator=(const Lecturer&);
};
Lecturer::Lecturer(string nm, int tuoi, string dc, bool gt, string id, string cb):Person(nm,tuoi,dc,gt){
Id = id;
Cap=cb;
}
Lecturer::~Lecturer(){
}
Lecturer::Lecturer(const Lecturer& a):Person(a.name,a.age,a.adress,a.gender){
Id = a.Id;
Cap = a.Cap;
}
const Lecturer& Lecturer::operator=(const Lecturer& a){
if(this!=&a){
this->name = a.name;
this->age = a.age;
this->adress = a.adress;
this->gender = a.gender;
this->Id = a.Id;
this->Cap = a.Cap;
}
return *this;
}
istream& operator>>(istream& in, Lecturer& a){
cout<<"Nhap ten"; getline(in,a.name);
cout<<"Nhap tuoi"; in>>a.age;
cout<<"Nhap dia chi"; getline(in,a.adress);
cout<<"Nhap gioi tinh (true:nam, false:nu)"; in>>a.gender;
cout<<"Nhap ma so"; getline(in,a.Id);
cout<<"Nhap cap bac"; getline(in,a.Cap);
}
ostream& operator<<(ostream& out, const Lecturer& a){
out<<"Ten: "<<a.name<<endl;
out<<"Tuoi: "<<a.age<<endl;
out<<"Dia chi: "<<a.adress<<endl;
if(a.gender == true) out<<"Gioi tinh: nam\n";
else out<<"Gioi tinh: nu\n";
out<<"Ma so: "<<a.Id<<endl;
out<<"Cap bac: "<<a.Cap;
}
class LopSinhHoat{
protected:
string name;
Student *ds;
Lecturer gv;
int SL;
public:
LopSinhHoat();
LopSinhHoat(string Tl, Lecturer &a, int n);
~LopSinhHoat();
LopSinhHoat(string, const LopSinhHoat&);
void Add(string , int , string, bool, string, double);
void Delete(string&);
};
LopSinhHoat::LopSinhHoat(string Tl, Lecturer &a, int n)
{
this->name = Tl;
this->gv = a;
SL = 0;
}
LopSinhHoat::LopSinhHoat(string Tl, const LopSinhHoat& a){
name = Tl;
this->gv = a.gv;
this->SL=0;
}
void LopSinhHoat::Add(string nm, int tuoi, string dc, bool gt, string id, double diem){
Student a(nm,tuoi,dc,gt,id,diem);
ds->Student[SL] = a.Lop;
++SL;
}


phải
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?