定义日期类Date,具有三个数据成员yy,mm,dd,通过构造函数初始化;
再定义Person类,具有出生日期birthday和姓名name两个成员,以及输出个人信息的成员函数print.在主函数中定义一个Person对象,并显示其个人信息.C+...
再定义Person类,具有出生日期birthday和姓名name两个成员,以及输出个人信息的成员函数print.在主函数中定义一个Person对象,并显示其个人信息.
C++ 求速度 谢谢 展开
C++ 求速度 谢谢 展开
2个回答
展开全部
public class Date
{
int year;
int month;
int day;
public Date(int yy, int mm, int dd)
{
year=yy;
month=mm;
day=dd;
}
};
public class Person
{
string birth;
string name;
publci Person(string birth, string name)
{
this.birth=birth;
this.name=name;
}
public void Print()
{
Console.writeline("birthday is {0}, name is{1}", birth, name);// 这是c#的输出格式,你可以参考一下,最后换成c++的就可以了
}
};
main()
{
Person p=new Person(birhday, name);
p.Print();
}
{
int year;
int month;
int day;
public Date(int yy, int mm, int dd)
{
year=yy;
month=mm;
day=dd;
}
};
public class Person
{
string birth;
string name;
publci Person(string birth, string name)
{
this.birth=birth;
this.name=name;
}
public void Print()
{
Console.writeline("birthday is {0}, name is{1}", birth, name);// 这是c#的输出格式,你可以参考一下,最后换成c++的就可以了
}
};
main()
{
Person p=new Person(birhday, name);
p.Print();
}
展开全部
#include <iostream>
#include <cstring>
using namespace std;
struct birthday
{
int year;
int mouth;
int day;
};
class Person
{
public:
Person();
void example();
void print();
private:
birthday m_birthday;
string m_name;
};
Person::Person()
{
m_birthday.year = 0;
m_birthday.mouth = 0;
m_birthday.day = 0;
m_name = "";
}
void Person::example()
{
m_birthday.year = 2013;
m_birthday.mouth = 12;
m_birthday.day = 1;
m_name = "柯南";
print();
}
void Person::print()
{
cout<<"birthday : year:"<<m_birthday.year<<" mouth:"<<m_birthday.mouth<<" day:"<<m_birthday.day<<endl;
cout<<"name :"<<m_name.c_str()<<endl;
}
int main()
{
Person person;
person.example();
system("pause");
return 0;
}
#include <cstring>
using namespace std;
struct birthday
{
int year;
int mouth;
int day;
};
class Person
{
public:
Person();
void example();
void print();
private:
birthday m_birthday;
string m_name;
};
Person::Person()
{
m_birthday.year = 0;
m_birthday.mouth = 0;
m_birthday.day = 0;
m_name = "";
}
void Person::example()
{
m_birthday.year = 2013;
m_birthday.mouth = 12;
m_birthday.day = 1;
m_name = "柯南";
print();
}
void Person::print()
{
cout<<"birthday : year:"<<m_birthday.year<<" mouth:"<<m_birthday.mouth<<" day:"<<m_birthday.day<<endl;
cout<<"name :"<<m_name.c_str()<<endl;
}
int main()
{
Person person;
person.example();
system("pause");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询