#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
class Student {
public:
//~Student();
void Instudent(void);
void Outstudent(void);
string name;
private:
Student* stu;
int n;
int Chinese;
int Math;
int English;
int Average;
};
//Student::~Student() {
//delete(stu);
//}
void Student::Instudent(void) {
int number;
cout << "请输入学生人数" << endl;
cin >> number;
n = number;
for (int i = 0; i < n; i++) {
cout << "请输入第" << i + 1 << "个学生的姓名:" << endl;
cin >> stu[i+1].name;
cout << "请输入第" << i + 1 << "个学生的语文成绩:" << endl;
cin >> stu[i+1].Chinese;
cout << "请输入第" << i + 1 << "个学生的数学成绩:" << endl;
cin >> stu[i+1].Math;
cout << "请输入第" << i + 1 << "个学生的英语成绩:" << endl;
cin >> stu[i+1].English;
stu[i + 1].Average = (stu[i + 1].Chinese + stu[i + 1].English + stu[i + 1].Math) / 3;
}
}
void Student::Outstudent(void) {
cout << "学生的姓名\t语文成绩\t数学成绩\t英语成绩\t平均成绩" << endl;
for (int i = 0; i < n; i++) {
cout << stu[i + 1].name << "\t\t" << stu[i + 1].Chinese << "\t\t" << stu[i + 1].Math
<< "\t\t" << stu[i + 1].English << "\t\t" << stu[i + 1].Average << endl;
if (stu[i + 1].Chinese < 60 || stu[i + 1].English < 60 || stu[i + 1].Math < 60) {
}
}
}
void main() {
Student s;
s.Instudent();
s.Outstudent();
}
这是一个空指针,它没有被初始化,使用一个空指针会导致内存错误