帮忙用c++写一个类

来源:百度知道 编辑:UC知道 时间:2024/06/01 11:59:51
只要个类,要有数据和方法!
刚学c++什么也不懂,老师布置得题,大家帮忙给解决下!
我说的刚学就是说刚上了第一课,并不是说我刚学完,understand?!!
课我还是会好好上的,不要曲解了我的意思啊

class A
{
private:
int x;
public:
int get()
{
return x;
}
};

那你是怎么学的?
你应该问你自己

#include <iostream>
//#include <string>
using namespace std;
class Date
{
public:
Date();
Date(int a,int b,int c);
Date(const Date &p);
~Date();
private:
int year; //年
int month; //月
int day; //日
static int sn;
public:
int getYear() const;
int getMonth() const;
int getDay() const;
bool isLeap() const;
bool isLeap();

void print(){cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;}

};
int Date::sn = 1; //初始化静态变量

Date::Date():year(2007),month(10),day(1)
{
cout<<"无参数构造函数被调用"<<endl;
}
Date::Date(int a,int b,int c)
{
cout<<"有参数的构造函数被调用"<<e