设计学生类Student,成员数据包括学号(int Id)、姓名(char name[9])成绩(int score)。根据给定的main函数设计必要的成员函数。 main函数已给定,提交时只需要提交main函数外的代码部分。 #include<iostream> #include<cstring> using namespace std; //你提交的代码在这里 int main() { Student stu1; cout<<"Show object stu1:"; cout<<stu1.GetId()<<"-"<<stu1.GetName()<<"-"<<stu1.GetScore()<<endl; int no,s; char xm[9]; cin>>no>>xm>>s; Student stu2(no,xm,s); cout<<"Show object stu2:"; cout<<stu2.GetId()<<"-"<<stu2.GetName()<<"-"<<stu2.GetScore()<<endl; cin>>no>>xm>>s; cout<<"Reset and Show object stu1:"; stu1.Set(no,xm,s); stu1.Show(); cout<<"Reset and Show object stu2:"; stu2.Set(); stu2.Show(); return 0; }
时间: 2023-06-16 13:04:29 浏览: 115
```
#include<iostream>
#include<cstring>
using namespace std;
class Student {
private:
int Id;
char name[9];
int score;
public:
Student() {
Id = 0;
strcpy(name, "");
score = 0;
}
Student(int no, char* xm, int s) {
Id = no;
strcpy(name, xm);
score = s;
}
void Set(int no, char* xm, int s) {
Id = no;
strcpy(name, xm);
score = s;
}
void Set() {
int no, s;
char xm[9];
cin >> no >> xm >> s;
Id = no;
strcpy(name, xm);
score = s;
}
int GetId() {
return Id;
}
char* GetName() {
return name;
}
int GetScore() {
return score;
}
void Show() {
cout << Id << "-" << name << "-" << score << endl;
}
};
int main() {
Student stu1;
cout << "Show object stu1:";
cout << stu1.GetId() << "-" << stu1.GetName() << "-" << stu1.GetScore() << endl;
int no, s;
char xm[9];
cin >> no >> xm >> s;
Student stu2(no, xm, s);
cout << "Show object stu2:";
cout << stu2.GetId() << "-" << stu2.GetName() << "-" << stu2.GetScore() << endl;
cin >> no >> xm >> s;
cout << "Reset and Show object stu1:";
stu1.Set(no, xm, s);
stu1.Show();
cout << "Reset and Show object stu2:";
stu2.Set();
stu2.Show();
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)