posts - 137,comments - 0,views - 40818

Toy.h:

复制代码
#pragma once
#include <iostream>
#include <windows.h>
#define DISCOUNT 5 //折扣,打5折

using namespace std;
class Toy {
public:
    Toy();  //构造函数
    Toy(string name,int price,string origin);
    string getName()const;//获取玩具的名字
    int getPrice()const;//获取玩具的价格
    string getOrigin()const;//获取玩具的产地
    void description()const;//写出具体描述
private:
    string name;//名字
    int price;//价格
    string origin;//产地
};
Toy::Toy() {
    name = "没有玩具";
    price = 0;
    origin = "";
}
Toy::Toy(string name, int price, string origin)
{
    this->name = name;
    this->price = price;
    this->origin = origin;
}
string Toy::getName() const
{
    return name;
}

int Toy::getPrice() const
{
    return (int)(price * DISCOUNT * 0.1);
}

string Toy::getOrigin() const
{
    return origin;
}

void Toy::description() const
{
    cout << name<< "" << price << "[mode in " << origin << "]" << endl
        << "打折大酬宾:"<< DISCOUNT <<"" << endl <<
        getName()<<"" << getPrice() << "[mode in " << getOrigin() << "]" << endl;
}
复制代码

Toy.cpp:

复制代码
#include <iostream>
#include <windows.h>
#include "源.h"

using namespace std;

int main() {
    Toy toy1("变形金刚", 5600, "China");
    toy1.description();

    system("pause");
    return 0;
}
复制代码

posted on   wshidaboss  阅读(67)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示