【发布时间】:2016-01-26 10:20:11
【问题描述】:
这是我第一次在编程方面寻求帮助。几周以来,我一直在为我的编程课程制定一个注册程序,其中涉及课程。这对我来说相当令人沮丧。我必须使用两个类:StoreItem 和Register。 StoreItem 处理商店销售的一小部分商品。收银机类主要处理物品的处理,制作总账单并要求用户用现金支付。 这是 StoreItem.cpp 文件:
//function definition
#include <string>
#include <iostream>
#include "StoreItem.h"
#include "Register.h"
using namespace std;
StoreItem::StoreItem(string , double)
{
//sets the price of the current item
MSRP;
}
void StoreItem::SetDiscount(double)
{
// sets the discount percentage
MSRP * Discount;
}
double StoreItem::GetPrice()
{ // return the price including discounts
return Discount * MSRP;
}
double StoreItem::GetMSRP()
{
//returns the msrp
return MSRP;
}
string StoreItem::GetItemName()
{
//returns item name
return ItemName;
}
StoreItem::~StoreItem()
{
//deletes storeitem when done
}
这里是 Register.cpp: 请注意,这一项中的最后 5 个函数定义尚未完成...
// definition of the register header
#include "Register.h"
#include "StoreItem.h"
using namespace std;
Register::Register()
{ // sets the initial cash in register to 400
CashInRegister = 400;
}
Register::Register(double)
{ //accepts initial specific amount
CashInRegister ;
}
void Register::NewTransAction()
{ //sets up the register for a new customer transaction (1 per checkout)
int NewTransactionCounter = 0;
NewTransactionCounter++;
}
void Register::ScanItem(StoreItem)
{ // adds item to current transaction
StoreItem.GetPrice();
// this probably isnt correct....
}
double Register::RegisterBalance()
{
// returns the current amount in the register
}
double Register::GetTransActionTotal()
{
// returns total of current transaction
}
double Register::AcceptCash(double)
{
// accepts case from customer for transaction. returns change
}
void Register::PrintReciept()
{
// Prints all the items in the transaction and price when finsished
}
Register::~Register()
{
// deletes register
}
我的主要问题是 Register::ScanItem(StoreItem)... 有没有办法将 storeItem 类中的函数正确调用到 Register scanitem 函数中?
【问题讨论】:
标签: c++ function class constructor destructor