我尝试为学生信息(姓名、IDno 和学位)编写一个类,这些信息将打印在屏幕上;但我不知道错误在哪里?!
#include <iostream>
#include <conio.h>
using namespace std;
class Student {
private:
char name;
int idnumber;
char degree;
public:
Student(char,int,char);
void setName(char n){name = n;}
int getName(){return name;}
void setIdnumber(char id){idnumber = id;}
int getIdnumber(){return idnumber;}
void setDegree(char d){degree = d;}
int getDegree(){return degree;}
};
Student::Student(char n,int id,char d){
name = n;
idnumber = id;
degree = d;
}
int main(){
Student s1, s2;
s1.setName(Sara);
s1.setIdnumber(333);
s1.setDegree(A);
s2.setName(Jack);
s2.setIdnumber(222);
s2.setDegree(B);
cout << "name: " << s1.getName() << ",IDnumber: " << s1.getIdnumber() << ",Degree: " << s1.getDegree() << endl;
cout << "name: " << s2.getName() << ",IDnumber: " << s2.getIdnumber() << ",Degree: " << s2.getDegree() << endl;
getch();
return 0;
}