类测试p93

#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>

using namespace std;
using namespace std;
class Person{
    int no;
    char name[10];
public:
    void setdata(int bh,char xm[]){
        no = bh;
        strcpy(name,xm);
    }
    //void dispdata(void){
    void dispdata(){
        cout << setw(5) << no << setw(10) << name << endl;
    }
};

int main(){
    Person emp[5];
    emp[0].setdata(1,"张华");
    emp[1].setdata(5,"张1华");
    emp[2].setdata(3,"张2华");
    emp[3].setdata(4,"张3华");
    emp[4].setdata(2,"张4华");

    cout<<" 编号 姓名 "<<endl;
    cout<<" ---- ---- "<<endl;
    for(int i=0;i<5;i++)  emp[i].dispdata();

    return 0;
}
//warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
//李春葆p93

全部评论

相关推荐

03-14 21:18
已编辑
上海交通大学 产品经理
被迫内卷的man:24年工作乱杀了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务