每日100!生日快乐!
拷贝构造函数
Date.h
#include
#include “string.h”
using namespace std;
class Date {
//没有限定,默认为public
int Month,Day,Yeal;
public:
Date(int m1, int d1, int y1 ){
Month = m1;
Day = d1;
Yeal = y1;
}
Date(Date &d){
Month = d.Month;
Month = d.Day;
Month = d.Yeal;
}
int M(){return Month;}
int D(){return Day;}
int Y(){return Yeal;}
};
class People{
char Name[10];
char Address[15];
Date Birthday;
public:
//初始化1
People(char *name,char *address);
//初始化2
People(char *name,char *address,int mn,int dy,int yr);
//初始化3
People(char *name,char *address,Date &d);
//输出函数
void Show_print();
};
People::People(char *name, char *address): Birthday(8,15,1999) {
strncpy(Name,name,10);
strncpy(Address,address,15);
}
People::People(char *name, char *address, int mn, int dy, int yr): Birthday(mn,dy,yr) {
strncpy(Name,name,10);
strncpy(Address,address,15);
}
People::People(char *name, char *address, Date &d): Birthday(d) {
strncpy(Name,name,10);
strncpy(Address,address,15);
}
void People::Show_print() {
cout << “姓名:” << Name << endl << “地址是:” << Address << endl;
cout << “生日是:” << Birthday.M() << “.”<< Birthday.D() << “.” << Birthday.Y() << endl;
}
Main.cpp
#include “Date.h”
int main() {
/People boy(“niuer”,“格尔木”,8,15,1999);
boy.Show_print();/
People girl(“cuihua”,“乐都区”,11,9,2000);
girl.Show_print();
float x,y,a;
for(y = 1.5f;y > -1.5f;y -= 0.1f)
{
for(x = -1.5f;x < 1.5f;x += 0.03f)
{
a = x*x + y*y - 1;
if(a*a*a-x*x*y*y*y <=0.0f)
printf("*");
else
cout << " " ;
}
cout << endl;
}
return 0;
}