C++成员选择符

#include<iostream>
using namespace std;

class book
{
public:
    void setprice(double a);
    double getprice();
private:
    double price;
};

void book::setprice(double a)
{
    price = a;
}

double book::getprice()
{
    return price;
}

int main()
{
    book Alice;
    Alice.setprice(29.9);
    cout<<"The price of Alice is $"<<Alice.getprice()<<endl;
    book *Harry = new book;
    Harry->setprice(49.9);
    cout<<"The price of Harry is $"<<Harry->getprice()<<endl;
    return 0;
}
posted @ 2022-08-19 22:48  luoganttcc  阅读(5)  评论(0)    收藏  举报