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;
}