请求高手,帮我做道C++题

2025-06-28 15:20:10
推荐回答(5个)
回答1:

/*TOY.h文件*/

#ifndef TOY_H
#define TOY_H

#include

using namespace std;
class TOY{

private:
string name; //商品名称
float price; //商品价格
int count; //商品售出数量

public:
void setPrice(float price); //设置商品价格
void setCount(int count); //设置商品售出数量
void setName(string name); //设置商品名称
void addCount(); //增加商品售出数量
float getPrice(); //获得商品价格
int getCount(); //获得商品售出数量
float totalMoney(); //计算商品售出总额

void printToyInfo(); //输出商品信息

TOY();
TOY(string name,float price);
~TOY();
};

#endif

/*TOY.cpp文件*/

#include "TOY.h"
#include

TOY::TOY()
{
name = "footBall";
price = 60.00;
count = 0;
}

TOY::TOY(string name, float price)
{
this->name = name;
this->price = price;

count = 0;
}

void TOY::setCount(int count)
{
this->count = count;
}

void TOY::setPrice(float price)
{
this->price = price;
}

void TOY::setName(string name)
{
this->name = name;
}

void TOY::addCount()
{
count++;
}

float TOY::getPrice()
{
return price;
}

int TOY::getCount()
{
return count;
}

float TOY::totalMoney()
{
return price*count;
}

void TOY::printToyInfo()
{
cout<}

TOY::~TOY()
{
}

/*demo.cpp文件*/

#include
#include "TOY.h"

#define MAX 100

using namespace std;

void main ()
{
TOY* toy[MAX];

int index;

toy[0] = new TOY();
toy[1] = new TOY("basketBall",90.20);

toy[0]->setCount(20);
toy[1]->setCount(30);

cout<<"Name\t\tPrice\tCount\tTotal"< toy[0]->printToyInfo();
toy[1]->printToyInfo();
}

相当粗糙,仅供参考,
另外主程序中如果用容器会更好。

回答2:

貌似不难,但是没时间做。。。。。。

回答3:

关注一下~

回答4:

HOHO,这样的东西用200分就想搞定?

回答5:

不错