#include <iostream>
using namespace std;
class Time //定义Time类
{
public : //数据成员为公用的
int hour;
int minute;
int sec;
};
int main( )
{
Time t1;//定义t1为Time类对象
cin>>t1.hour;//输入设定的时间
cin>>t1.minute;
cin>>t1.sec;
//输出时间:
cout<<t1.hour<<":"<<t1.minute<<":"<<t1.sec<<endl;
return 0;
}
1232 43↙ 12:32:43
#include <iostream>
using namespace std;
class Time
{
public :
int hour;
int minute;
int sec;
};
int main( )
{
Time t1;//定义对象t1
cin>>t1.hour;//向t1的数据成员输入数据
cin>>t1.minute;
cin>>t1.sec;
cout<<t1.hour<<":"<<t1.minute<<":"<<t1.sec<<endl;//输出t1中数据成员的值
Time t2;//定义对象t2
cin>>t2.hour;//向t2的数据成员输入数据
cin>>t2.minute;
cin>>t2.sec;
cout<<t2.hour<<":"<<t2.minute<<":"<<t2.sec<<endl;//输出t2中数据成员的值
return 0;
}
1032 43↙ 10:32:43 22 32 43↙ 22:32:43
#include <iostream>
using namespace std;
class Time
{
public :
int hour;
int minute;
int sec;
};
int main( )
{
void set_time(Time&);//函数声明
void show_time(Time&);//函数声明
Time t1;//定义t1为Time类对象
set_time(t1);//调用set_time函数,向t1对象中的数据成员输入数据
show_time(t1);//调用show_time函数,输出t1对象中的数据
Time t2;//定义t2为Time类对象
set_time(t2);//调用set_time函数,向t2对象中的数据成员输入数据
show_time(t2);//调用show_time函数,输出t2对象中的数据
return 0;
}
void set_time(Time& t) //定义函数set_time,形参t是引用变量
{
cin>>t.hour;//输入设定的时间
cin>>t.minute;
cin>>t.sec;
}
void show_time(Time& t) //定义函数show_time,形参t是引用变量
{
cout<<t.hour<<":"<<t.minute<<":"<<t.sec<<endl;//输出对象中的数据
}
int main( )
{
void set_time(Time&,int hour=0,int minute=0,int sec=0);//函数声明
void show_time(Time&);//函数声明
Time t1;
set_time(t1,12,23,34);//通过实参传递时、分、秒的值
show_time(t1);
Time t2;
set_time(t2);//使用默认的时、分、秒的值
show_time(t2);
return 0;
}
void set_time(Time& t,int hour,int minute,int sec)
{
t.hour=hour;
t.minute=minute;
t.sec=sec;
}
void show_time(Time& t)
{
cout<<t.hour<<":"<<t.minute<<":"<<t.sec<<endl;
}
12:23:34 (t1中的时、分、秒) 0:0:0 (t2中的时、分、秒)
#include <iostream>
using namespace std;
class Time
{
public :
void set_time( );//公用成员函数
void show_time( );//公用成员函数
private : //数据成员为私有
int hour;
int minute;
int sec;
};
int main( )
{
Time t1;//定义对象t1
t1.set_time( );//调用对象t1的成员函数set_time,向t1的数据成员输入数据
t1.show_time( );//调用对象t1的成员函数show_time,输出t1的数据成员的值
Time t2;//定义对象t2
t2.set_time( );//调用对象t2的成员函数set_time,向t2的数据成员输入数据
t2.show_time( );//调用对象t2的成员函数show_time,输出t2的数据成员的值
return 0;
}
void Time::set_time( ) //在类外定义set_time函数
{
cin>>hour;
cin>>minute;
cin>>sec;
}
void Time::show_time( ) //在类外定义show_time函数
{
cout<< hour<<":"<< minute<<":"<< sec<< endl;
}
#include <iostream>
using namespace std;
class Array_max //声明类
{
public : //以下3行为成员函数原型声明
void set_value( ); //对数组元素设置值
void max_value( ); //找出数组中的最大元素
void show_value( ); //输出最大值
private :
int array[10]; //整型数组
int max; //max用来存放最大值
};
void Array_max::set_value( ) //成员函数定义,向数组元素输入数值
{
int i;
for (i=0;i<10;i++)
cin>> array[i];
}
void Array_max::max_value( ) //成员函数定义,找数组元素中的最大值
{
int i;
max=array[0];
for (i=1;i<10;i++)
if(array[i]> max) max=array[i];
}
void Array_max::show_value( ) //成员函数定义,输出最大值
{
cout<< "max="<< max;
}
int main( )
{
Array_max arrmax; //定义对象arrmax
arrmax.set_value( ); //调用arrmax的set_value函数,向数组元素输入数值
arrmax.max_value( ); //调用arrmax的max_value函数,找出数组元素中的最大值
arrmax.show_value( ); //调用arrmax的show_value函数,输出数组元素中的最大值
return 0;
}
12 12 39 -34 17 134 045 -91 76↙ (输入10个元素的值) max=134 (输入10个元素中的最大值)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有