#include <iostream> using namespace std;//命名空间 class classmanger { public: string student_name; void setname(string student_name); string getname(); string subject; void setsubject(string subject); string getsubject(); int student_score; void setscore(int student_score); int getscore(); void print_data(); private: }; void classmanger::setname() { this->student_name=student_name; } string classmanger::getname() { return this->student_name; } void classmanger::setsubject(string subject) { this->subject=subject; } string classmanger::getsubject() { return this->subject; } void classmanger::setscore(int student_score) { this->student_score=student_score; } int classmanger::getscore() { return student_score; } void classmanger::print_data() { cout<<student_name<<endl; cout<<subject<<endl; cout<<student_score<<endl; } int main() { cout << "Hello World!" << endl; classmanger student1; student1.setname("lingyu"); student1.setsubject("math"); student1.setscore(10); student1.getname(); student1.getsubject(); student1.getscore(); student1.print_data(); return 0; }
时间: 2024-01-07 20:03:27 浏览: 296
#include <iostream> #include<iomanip> using namespace std;九九乘法表
这段代码有一些问题,主要是在classmanger类的成员函数中出现了参数未定义的情况。下面是修改后的代码:
```
#include <iostream>
using namespace std;
class classmanger {
public:
string student_name;
void setname(string name);
string getname();
string subject;
void setsubject(string subject);
string getsubject();
int student_score;
void setscore(int score);
int getscore();
void print_data();
private:
};
void classmanger::setname(string name) {
this->student_name = name;
}
string classmanger::getname() {
return this->student_name;
}
void classmanger::setsubject(string subject) {
this->subject = subject;
}
string classmanger::getsubject() {
return this->subject;
}
void classmanger::setscore(int score) {
this->student_score = score;
}
int classmanger::getscore() {
return this->student_score;
}
void classmanger::print_data() {
cout << "Name: " << student_name << endl;
cout << "Subject: " << subject << endl;
cout << "Score: " << student_score << endl;
}
int main() {
cout << "Hello World!" << endl;
classmanger student1;
student1.setname("lingyu");
student1.setsubject("math");
student1.setscore(10);
student1.print_data();
return 0;
}
```
这个程序定义了一个classmanger类,包含学生的名字、科目和分数。setname、setsubject和setscore函数用来设置这些属性,而getname、getsubject和getscore则用来获取这些属性。print_data用于输出学生的信息。在main函数中,我们创建了一个学生对象,设置了他的名字、科目和分数,并输出了他的信息。
阅读全文