65,211
社区成员
发帖
与我相关
我的任务
分享
//string.cpp
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Employee {
string name;
string birthday;
public:
void setName(string s) {
name = s;
}
void setBirthday (string t) {
birthday = t;
}
char getName { //此处不知道该如何使用
return name;
}
char getBirthday { //此处也是一样,不知道该如何使用
return birthday;
}
void display() {
cout << "姓名" << name << "生日" << birthday << endl;
cout << "姓名" << getName() << "生日" << getBirthday() << endl;
};
void main () {
Employee e;
e.setName("小李");
e.setBirthday("1988-11-11");
e.display();
}
class Employee { //基类employee,含有职工姓名和出生日期的信息简表
char name[10]; //姓名
char birthday[10]; //生日
public:
void setName(char s[]) {
strcpy(name,s);
}
char *getName() {
return name;
}
void setBirthday(char b[]) {
strcpy(birthday,b);
}
char *getBirthday() {
return birthday;
}
virtual void display() {
cout << getName() << "\t" << getBirthday();
}
};
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Employee
{
string name;
string birthday;
public:
void setName(string s) {
name = s;
}
void setBirthday (string t) {
birthday = t;
}
//const char* getName()const { //此处不知道该如何使用
// return name.c_str();
//}
string getName()const { //此处不知道该如何使用
return name;
}
// const char* getBirthday()const { //此处也是一样,不知道该如何使用
// return birthday.c_str();
//}
string getBirthday()const { //此处也是一样,不知道该如何使用
return birthday;
}
void display() {
cout << "姓名" << name << "生日" << birthday << endl;
cout << "姓名" << getName() << "生日" << getBirthday() << endl;
}
};
void main()
{
Employee e;
e.setName("小李");
e.setBirthday("1988-11-11");
e.display();
}
string getName {
return name;
}
string getBirthday {
return birthday;
}
//声明什么;返回什么;