Mọi người giúp em với ạ. Khi em chạy debug thì thấy các hàm getter trong class Student đều không return giá trị được và nó hiện thông báo unable reading memory. Mọi người có thể dành thời gian xem qua code của em và chỉ em cách fix đc ko ạ. Em xin cảm ơn trước.
Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::string;
class Student
{
protected:
string _code; //student code
string _id; //citizen identity
string _fullName;
int _gender{};
//birthday
int _day{};
int _month{};
int _year{};
//point
float _pointM{}; //grade of math
float _pointL{}; //grade of literature
float _pointE{}; //grade of english
float _GPA{ (_pointM + _pointL + _pointE) / 3 }; //grade point average
public:
void setCode(string& code)
{
cout << "Nhap ma so sinh vien: ";
cin >> code;
fflush(stdin);
this->_code = code;
}
string getCode()
{
return this->_code;
}
void setId(string& id)
{
cout << "Nhap so CMND/ CCCD/ Ho chieu: ";
cin >> id;
fflush(stdin);
this->_id = id;
}
string getId()
{
return this->_id;
}
void setName(string& fullName)
{
cin.ignore();
cout << "Nhap ho va ten: ";
getline(cin, fullName);
this->_fullName = fullName;
}
string getName()
{
return this->_fullName;
}
void setGender(int& gender)
{
cout << "Nhap gioi tinh (nam nhap 1, nu nhap 0): ";
cin >> gender;
this->_gender = gender;
}
int getGender()
{
return this->_gender;
}
void setBirthday(int& day, int& month, int& year)
{
cout << "Nhap ngay sinh: ";
cin >> day;
this->_day = day;
cout << "Nhap thang sinh: ";
cin >> month;
this->_month = month;
cout << "Nhap nam sinh: ";
cin >> year;
this->_year = year;
}
int getDay()
{
return this->_day;
}
int getMonth()
{
return this->_month;
}
int getYear()
{
return this->_year;
}
void setPoint(float& pointM, float& pointL, float& pointE)
{
cout << "Nhap diem mon toan: ";
cin >> pointM;
this->_pointM = pointM;
cout << "Nhap diem mon van: ";
cin >> pointL;
this->_pointL = pointL;
cout << "Nhap diem mon anh: ";
cin >> pointE;
this->_pointE = pointE;
}
float getPointM()
{
return this->_pointM;
}
float getPointL()
{
return this->_pointL;
}
float getPointE()
{
return this->_pointE;
}
float getGPA()
{
return this->_GPA;
}
void setData()
{
string code;
string id;
string fullName;
int gender{};
int day{};
int month{};
int year{};
float pointM{};
float pointL{};
float pointE{};
setCode(code);
setId(id);
setName(fullName);
setGender(gender);
setBirthday(day, month, year);
setPoint(pointM, pointL, pointE);
}
};
#endif // !STUDENT_H
LinkedList.h
#ifndef NODE_H
#define NODE_H
#include "Student.h"
class Node : public Student
{
public:
Student* student;
Node* pNext;
Node(Student* student)
{
this->student = student;
pNext = nullptr;
}
};
class LinkedList
{
private:
Node* pHead;
Node* pTail;
int size{};
public:
LinkedList() : pHead(nullptr), pTail(nullptr), size(0) {};
~LinkedList() {};
int getSize()
{
return size;
}
void createNode()
{
Student* student = new Student;
Node* node = new Node(student);
student->setData();
if (pHead == nullptr)
{
pHead = node;
pTail = node;
}
else
{
pTail->pNext = node;
pTail = node;
}
size++;
}
void display()
{
Node* current = pHead;
while (current != nullptr)
{
cout << "Ma so sinh vien: " << current->getCode() << '\n';
cout << "So CMND/ CCCD/ Ho chieu: " << current->getId() << '\n';
cout << "Ho va ten: " << current->getName() << '\n';
cout << "Gioi tinh: " << current->getGender() << '\n';
cout << "Ngay thang nam sinh: " << current->getDay() << "/" << current->getMonth() << "/" << current->getYear() << '\n';
cout << "Diem mon toan: " << current->getPointM() << '\n';
cout << "Diem mon van: " << current->getPointL() << '\n';
cout << "Diem mon anh: " << current->getPointE() << '\n';
cout << "GPA: " << current->getGPA() << '\n';
current = current->pNext;
}
}
};
#endif // !NODE_H
Main.cpp
#include "Student.h"
#include "LinkedList.h"
#include <Windows.h>
#include <conio.h>
int main()
{
int choice{};
LinkedList list;
do
{
system("cls");
cout << "===============QUAN LY SINH VIEN===============\n";
cout << "1 - Nhap\n";
cout << "2 - Xuat\n";
cout << "3 - Them\n";
cout << "4 - Xoa\n";
cout << "5 - Sua\n";
cout << "6 - Tim kiem\n";
cout << "7 - Sap xep\n";
cout << "8 - Thong ke\n";
cout << "9 - Xuat file\n";
cout << "0 - Thoat\n";
cout << "\tNhap lenh: ";
cin >> choice;
switch (choice)
{
case 1:
{
long number{}; //number of students
while (true)
{
cout << "\n(!) Nhap so luong sinh vien: ";
cin >> number;
if (number < 1)
{
cout << "Vui long nhap dung so luong!\n";
continue;
}
else break;
}
if (number == 1)
{
cout << "Nhap thong tin sinh vien:" << '\n';
list.createNode();
cout << "Nhap thong tin sinh vien thanh cong\n";
}
else
{
for (long i = 1; i <= number; i++)
{
cout << "Nhap thong tin sinh vien thu " << i << ":\n";
list.createNode();
cout << "Nhap thong tin sinh vien thu " << i << "thanh cong\n";
}
}
cout << "Nhap phim bat ki de tiep tuc";
_getch();
break;
}
case 2:
{
list.display();
break;
}
/* case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 0:
exit(0);
break;
default:
;*/
}
} while (choice != 0);
system("pause");
return 0;
}