int num[N]; char name[20],sex; double score1,score2,score3;cout<<"请输入学生的学号:"; cin>>s.num[N]; cout<<"请输入学生的姓名:"; cin>>s.name; cout<<"请输入学生的性别(m或f):"; cin>>s.sex; cout<<"请输入学生的语文成绩:"; cin>>s.score1; cout<<"请输入学生的数学成绩:"; cin>>s.score2; cout<<"请输入学生的英语成绩:"; cin>>s.score3; i.v.push_back(s); cout<<"添加成功,继续添加请按1,否则将退出添加页面"<<endl; cin>>a; if(a==1){return _0843杨晓慧1();} return ;
时间: 2024-03-14 07:49:00 浏览: 15
在您提供的代码中,无法找到定义变量 `N` 的代码行。但是,从您的代码中可以看出,您将学生的学号存储在数组 `num` 中。如果输出了错误的学号,可能有以下几个原因:
1. 学生的学号没有存储成功,或者存储时发生了错误,导致输出的学号不正确。
2. 输出学号的代码有误,可能是打印数组 `num` 时下标错误,或者输出格式不正确。
3. 学号的长度超过了定义数组 `num` 的长度,导致输出错误的学号。
建议您检查存储学号的代码和输出学号的代码,以确定问题的具体原因。
相关问题
完善class _0843杨晓慧 { public: int num; string name; char sex; double score1,score2,score3; }; class _0843杨晓慧_1:public _0843杨晓慧 { public: vector<_0843杨晓慧>v; _0843杨晓慧_1() ; void _0843杨晓慧1() ; void _0843杨晓慧2() ; void _0843杨晓慧3()
好的,您的问题是关于完善一个名为“_0843杨晓慧”的类及其派生类“_0843杨晓慧_1”的代码。根据您提供的代码片段,我可以帮您进行以下完善:
1. 在类“_0843杨晓慧”中添加一个构造函数,初始化该类的成员变量。
2. 在类“_0843杨晓慧_1”中添加三个成员函数,分别用于实现以下功能:
- _0843杨晓慧1():向类中添加学生记录。
- _0843杨晓慧2():按照学生学号进行查询,并输出该学生的信息。
- _0843杨晓慧3():按照学生学号进行删除,并将删除的学生记录转存到另一个删除库中。
以下是完善后的代码:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class _0843杨晓慧
{
public:
int num;
string name;
char sex;
double score1, score2, score3;
// 添加构造函数
_0843杨晓慧(int n, string nm, char s, double s1, double s2, double s3): num(n), name(nm), sex(s), score1(s1), score2(s2), score3(s3) {}
};
class _0843杨晓慧_1: public _0843杨晓慧
{
public:
vector<_0843杨晓慧> v;
_0843杨晓慧_1() {}
// 添加向类中添加学生记录的函数
void _0843杨晓慧1()
{
int n;
string nm;
char s;
double s1, s2, s3;
cout << "请输入学号、姓名、性别、三门课的成绩:";
cin >> n >> nm >> s >> s1 >> s2 >> s3;
_0843杨晓慧 stu(n, nm, s, s1, s2, s3);
v.push_back(stu);
}
// 添加按照学生学号进行查询,并输出该学生的信息的函数
void _0843杨晓慧2()
{
int n;
cout << "请输入要查询的学生学号:";
cin >> n;
for (int i = 0; i < v.size(); i++)
{
if (v[i].num == n)
{
cout << "学号:" << v[i].num << endl;
cout << "姓名:" << v[i].name << endl;
cout << "性别:" << v[i].sex << endl;
cout << "成绩1:" << v[i].score1 << endl;
cout << "成绩2:" << v[i].score2 << endl;
cout << "成绩3:" << v[i].score3 << endl;
return;
}
}
cout << "未找到该学生记录!" << endl;
}
// 添加按照学生学号进行删除,并将删除的学生记录转存到另一个删除库中的函数
void _0843杨晓慧3()
{
int n;
cout << "请输入要删除的学生学号:";
cin >> n;
for (int i = 0; i < v.size(); i++)
{
if (v[i].num == n)
{
_0843杨晓慧 stu = v[i];
v.erase(v.begin() + i);
// 将删除的学生记录转存到另一个删除库中
// ...
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该学生记录!" << endl;
}
};
```
需要注意的是,上述代码只是在您提供的代码基础上进行的完善,可能还需要根据具体需求进行进一步修改和调整。
定义一个学生类Student 数据成员 (private): 学生姓名(char *name)、性别(bool sex)、学号、出生日期(Birthday birth)、专业课门数、专业课成绩(double *score) 成员函数 (public): 构造函数:对学生的姓名、性别、学号、出生日期、专业课门数进行初始化 Student(char *_name, bool _sex, int _sno, int year, int month, int day, int _num); 析构函数:释放系统资源(堆空间) 提供拷贝构造函数 录入专业课的成绩 void input(double *s); 修改某门专业课的成绩 void change(int i, double s); 获取某门专业课的成绩 double get(int i); 获取专业课门数 计算专业课平均成绩 计算不及格专业课的门数 显示学生基本信息
下面是一个基本的学生类Student的定义,包括数据成员和成员函数的实现:
```c++
#include <iostream>
#include <cstring>
using namespace std;
class Birthday {
public:
Birthday(int year, int month, int day) {
this->year = year;
this->month = month;
this->day = day;
}
void display() {
cout << year << "-" << month << "-" << day << endl;
}
private:
int year;
int month;
int day;
};
class Student {
public:
Student(char *_name, bool _sex, int _sno, int year, int month, int day, int _num) {
name = new char[strlen(_name) + 1];
strcpy(name, _name);
sex = _sex;
sno = _sno;
birth = new Birthday(year, month, day);
num = _num;
score = new double[num];
}
~Student() {
delete[] name;
delete birth;
delete[] score;
}
Student(const Student &stu) {
name = new char[strlen(stu.name) + 1];
strcpy(name, stu.name);
sex = stu.sex;
sno = stu.sno;
birth = new Birthday(*stu.birth);
num = stu.num;
score = new double[num];
for (int i = 0; i < num; i++) {
score[i] = stu.score[i];
}
}
void input(double *s) {
for (int i = 0; i < num; i++) {
score[i] = s[i];
}
}
void change(int i, double s) {
score[i] = s;
}
double get(int i) {
return score[i];
}
int getNum() {
return num;
}
double getAverage() {
double sum = 0;
for (int i = 0; i < num; i++) {
sum += score[i];
}
return sum / num;
}
int getFailNum() {
int cnt = 0;
for (int i = 0; i < num; i++) {
if (score[i] < 60) {
cnt++;
}
}
return cnt;
}
void display() {
cout << "姓名:" << name << endl;
cout << "性别:" << (sex ? "男" : "女") << endl;
cout << "学号:" << sno << endl;
cout << "出生日期:";
birth->display();
cout << "专业课门数:" << num << endl;
cout << "专业课成绩:";
for (int i = 0; i < num; i++) {
cout << score[i] << " ";
}
cout << endl;
cout << "专业课平均成绩:" << getAverage() << endl;
cout << "不及格专业课门数:" << getFailNum() << endl;
}
private:
char *name;
bool sex;
int sno;
Birthday *birth;
int num;
double *score;
};
```
然后可以在主函数中进行测试:
```c++
int main() {
double score[] = { 80, 90, 70 };
Student stu("张三", true, 1001, 1998, 5, 1, 3);
stu.input(score);
stu.display();
return 0;
}
```
输出结果为:
```
姓名:张三
性别:男
学号:1001
出生日期:1998-5-1
专业课门数:3
专业课成绩:80 90 70
专业课平均成绩:80
不及格专业课门数:0
```