请定义一个简单的数对类,该类包含两个双精度数。

请定义一个简单的数对类,该类包含两个双精度数。 我们可以通过SetA,SetB,GetA,GetB实现两个数据的设置和获取。例如,它能支持如下的使用(把数对用于保存二维坐标): int main() { DataPair point; point.setA(1.2); point.setB(4); cout<<"x="<

class DataPair 
{
    double a, b;
public:
    void setA(double d) { a = d; }
    double getA() { return a; }
    void setB(double d) { b = d; }
    double getB() { return b; }
};

 

class DataPair{
    double x;
    double y;
public:
    void SetA(double a){x=a;}
    void SetB(double b){y=b;}
    double GetA() {return x;}
    double GetB() {return y;}
}

int main()
{
     DataPair point;
     point.setA(1.2);
     point.setB(4);
     cout<<"x="<<point.GetA()<<"\ny="<<point.GetB();
     return 0;
}

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632