6週目アイテム1-スコアクラスの雛形(1)
1347 ワード
/*
*Copyright(C) 2016,
*All rights reserved.
* :test.cpp
* :
* :2016 4 9
* :v1.0
*
* : (1)。
*/
#include <iostream>
using namespace std;
class CFraction
{
private:
int nume; //
int deno; //
public:
CFraction(int nu=0,int de=1); // ,
void output(int style=0); // : 8/6 ,style 0 , 8/6;
};
CFraction::CFraction(int nu,int de)
{
if(de!=0)
{
nume=nu;
deno=de;
}
else
{
cout<<" ";
}
}
void CFraction::output(int style)
{
if(style==0)
cout<<nume<<"/"<<deno<<endl;
}
int main()
{
CFraction a1,a2(2,4),a3(3,6);
a1.output(0);
a2.output(0);
a3.output(0);
return 0;
}
<img src="http://img.blog.csdn.net/20160412192115356?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
学習の心得:
これは簡単なプログラムで、詳細に注意してください.クラスで宣言されたデフォルト関数は、デフォルト値を付けないように注意して書かれています.