chapter10test2

Person.h

#ifndef PERSON_H_
#define PERSON_H_
#include<string>


class Person
{
private:
static const int limit = 25;
std::string lname;
char fname[limit];
public:
Person(){lname = "", fname[0] = '\0'; }
~Person();
Person(const std::string &ln, const char *fn="Heyyou");
void show();
void formalshow();
};


#endif


Person.cpp

#include<iostream>
#include"person.h"
Person::~Person()
{
std::cout << "Finished !";
}
Person::Person(const std::string &ln, const char *fn)
{
lname = ln;
int s = strlen(fn);
for (int i = 0; i <s; i++)
{
fname[i] = *(fn + i);
}
fname[s + 1] = '\0';
}
void Person::show()
{
std::cout << "Lname :" << lname << std::endl;
}
void Person::formalshow()
{
std::cout << "Fname :";
for (int i = 0; i <strlen(fname); i++)
std::cout << fname[i];
}


User.cpp

#include<iostream>
#include"person.h"
using namespace std;
int main()
{
Person one;
Person two{"seythecraft",};
Person three{ "Dimwindy", "Samba" };
one.show();
one.formalshow();
cout << endl;
two.show();
two.formalshow();
cout << endl;
three.show();
three.formalshow();
cout << endl;


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值