//时钟类完整程序
/*
#include<iostream>
using namespace std;
class Clock
{
public:
void SetTime(int NewH=0,int NewM=0,int NewS=0);
void ShowTime();
private:
int Hour,Minute,Second;
};
//时钟类函数的具体实现
void Clock::SetTime(int NewH,int NewM,int NewS)
{
Hour=NewH;
Minute=NewM;
Second=NewS;
}
inline void Clock::ShowTime()
{
cout<<Hour<<":"<<Minute<<":"<<Second<<endl;
}
int main()
{
Clock myClock;
cout<<"First time set and output:"<<endl;
myClock.SetTime();
myClock.ShowTime();
cout<<"Second time set and output:"<<endl;
myClock.SetTime(8,30,30);
myClock.ShowTime();
cout<<"Third time set and output:"<<endl;
myClock.SetTime(9,30,30);
myClock.ShowTime();
}
*/
// 函数的参数传递-值调用
/*
#include<iostream>
using namespace std;
void Swap(int a,int b);
int main()
{
int x=5,int y=10;
cout<<"x="<<x<<" y="<<y<<endl;
Swap(x,y);//这里将实参5传递给形参x,将实参10传递给形参y.
cout<<"x="<<x<<" y="<<y<<endl;
}
void Swap(int a,int b)//形参发生变化不会影响实参
{
int t;
t=a;
a=b;
b=t;
}
*/
//函数的参数传递-引用调用
/*
#include<iostream>
using namespace std;
void Swap(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}
int main()
{
void Swap(int &a,int &b);
int x=5,y=10;
cout<<"x="<<x<<" y="<<y<<endl;
Swap(x,y);
cout<<"x="<<x<<" y="<<y<<endl;
}
*/
/*
#include<iostream>
#include<iomanip>
using namespace std;
void fiddle(int in1,int &in2)
{
in1=in1+100;
in2=in2+100;
cout<<"The values are";
cout<<setw(5)<<in1;
cout<<setw(5)<<in2<<endl;
}
int main()
{
void fiddle(int in1,int &in2);
int count=7,index=12;
cout<<"The values are";
cout<<setw(5)<<count;
cout<<setw(5)<<index<<endl;
fiddle(count,index);//引用调用关键 int &int2=index=12
//index=112.
cout<<"The value are";
cout<<setw(5)<<count;
cout<<setw(5)<<index<<endl;
}
*/
万事开头难,才开始学习C++就把自己的编写的代码放在网上,慢慢学习了。
相信一天我也会从一个菜鸟变成一个老鸟。