void getdate(); //取日期值,格式为“year-month-day”
int getyear(); //取年份
int getmonth(); //取月份
int getday(); //取日期
void setdate(int y,int m,int d); //设置日期值
程序代码如下:
#include <iostream>
using namespace std;
class date
{
public:
void getdate();
int getyear();
int getmonth();
int getday();
void setdate(int y,int m,int d);
private:
int year,month,day;
};
int date::getyear(){ return year; }
int date::getmonth(){ return month; }
int date::getday(){ return day; }
void date::getdate()
{ cout<<"today is:"<<year<<"-"<<month<<"-"<<day<<endl; }
void date::setdate(int y,int m,int d)
{ year=y; month=m; day=d; }
int main()
{
date d;
d.setdate(2011,2,1);
cout<<"year="<<d.getyear()<<endl;
cout<<"month="<<d.getmonth()<<endl;
cout<<"day="<<d.getday()<<endl;
d.getdate();
return 0;
}
#include <iostream>
using namespace std;
class date
{
public:
date(int y=0,int m=0,int d=0)
{ year=y; month=m; day=d; }
date(date &d)
{ year=d.year; month=d.month; day=d.day; }
void getdate()
{ cout<<"today is:"<<year<<"-"<<month<<"-"<<day<<endl; }
int getyear() { return year; }
int getmonth() { return month; }
int getday() { return day; }
private:
int year,month,day;
};
int main()
{
date d1(2011,2,1),d2,d3(d1);
d1.getdate();
d2.getdate();
d3.getdate();
return 0;
}
#include <iostream>
using namespace std;
#define N 10
class array
{
public:
void input();
void output();
int max();
int min();
int sum();
float average();
private:
int a[N],maxnumber,minnumber,sumnumber;
float avenumber;
};
void array::input()
{
int i=0;
cout<<"Please input "<<N<<" numbers:"<<endl;
for(i=0;i<N;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
}
void array::output()
{
int i=0;
cout<<"array a is:"<<endl;
for(i=0;i<N;i++)
cout<<a[i]<<" ";
cout<<endl;
}
int array::max()
{
int i;
maxnumber=a[0];
for(i=1;i<N;i++)
if(maxnumber<a[i])
maxnumber=a[i];
return maxnumber;
}
int array::min()
{
int i;
minnumber=a[0];
for(i=1;i<N;i++)
if(minnumber>a[i])
minnumber=a[i];
return minnumber;
}
int array::sum()
{
int i;
sumnumber=a[0];
for(i=1;i<N;i++)
sumnumber+=a[i];
return sumnumber;
}
float array::average()
{
float ave=static_cast<float>(sumnumber/N);
return ave;
}
int main()
{
array a;
a.input();
a.output();
cout<<"The max number is "<<a.max()<<endl;
cout<<"The min number is "<<a.min()<<endl;
cout<<"The sum number is "<<a.sum()<<endl;
cout<<"The average number is"<<a.average()<<endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Cat
{
public:
Cat(string c="red",float w=1,int a=1);
string get_color();
float get_weight();
int get_age();
void display();
private:
string color;
float weight;
int age;
};
Cat::Cat(string c,float w,int a)
{
color=c;
weight=w;
age=a;
}
string Cat::get_color()
{
return color;
}
float Cat::get_weight()
{
return weight;
}
int Cat::get_age()
{
return age;
}
void Cat::display()
{
cout<<"The color of this cat is "<<get_color()<<endl;
cout<<"The weight of this cat is "<<get_weight()<<endl;
cout<<"The age of this cat is "<<get_age()<<endl;
}
int main()
{
Cat c1,c2("yellow",1,2);
cout<<"c1 is:"<<endl;
c1.display();
cout<<"c2 is:"<<endl;
c2.display();
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有