Problem D: 类的初体验(II)

Description

定义一个类Data,只有一个double类型的属性和如下3个方法:
1.   带1个参数的构造函数——初始化属性值为参数值。

2.   double getValue()——获得属性值。

3.    void showValue()——显示属性值。

Input

一个double类型的数值。

Output

输出输入的值2次,每次占一行。

Sample Input

3.14

Sample Output

3.14
3.14

HINT

Append Code

#include<iostream>
using namespace std;
class Data
{
private:
    double i;
public:
     Data(double d){i=d;}
    double getValue(){return i;}
    void showValue(){cout<<i<<endl;}
};
int main()
{
    double d;
    cin>>d;
    Data data(d);
    cout<<data.getValue()<<endl;
    data.showValue();
}
posted on 2017-03-13 19:20  TogetherLaugh  阅读(309)  评论(0编辑  收藏  举报