我認爲我是相當能解決我的代碼,以便它會編譯,但事情仍然關閉它。代碼編譯奇怪
這是我的.h文件
#pragma once
#include <string>
using namespace std;
class Item
{
private:
string description;
double price;
int weight;
int quantity;
public:
Item(void);
~Item(void);
Item::Item(double OrderPrice, int OrderWeight, string Description);
void setOrderPrice(double amount);
void setOrderWeight(int ounces);
void setDescription(string desc);
void setQuantity(int number);
int getOrderPrice();
int getOrderWeight();
string getDescription();
int getQuantity();
void show();
};
這是我的.cpp文件:
#include <iostream>
#include <string>
#include "Item.h"
using namespace std;
Item::Item(void)
{
}
Item::Item(double OrderPrice, int OrderWeight, string Description)
{
}
Item::~Item(void)
{
}
void Item::setOrderPrice(double amount) {
price = amount;
}
void Item::setOrderWeight(int ounces) {
weight = ounces;
}
void Item::setDescription(string desc) {
description = desc;
}
void Item::setQuantity(int number) {
quantity = number;
}
int Item::getOrderPrice() {
return price;
}
int Item::getOrderWeight() {
return weight;
}
string Item::getDescription() {
return description;
}
int Item::getQuantity() {
return quantity;
}
void Item::show() {
cout << price << weight << description;
}
這是我的主要文件:
#include <iostream>
#include <string>
#include "Item.h"
using namespace std;
int main() {
double dTotalPrice = 0.0;
int iTotalWeight = 0;
Item itmMouse(24.99, 14, "Wireless Mouse");
Item itmKeyboard(22.49, 27, "USB Keyboard");
Item itmHDMI (24.99, 12, "HDMI Cable");
Item itmGlasses(7.99, 7, "Reading Glasses");
itmGlasses.setQuantity(2);
// Show the details of the order using printDetails()
cout << "Here are your shopping cart contents.\n";
itmMouse.show();
itmKeyboard.show();
itmHDMI.show();
itmGlasses.show();
// Compute the total price and total weight in this section
dTotalPrice += itmMouse.getOrderPrice();
dTotalPrice += itmKeyboard.getOrderPrice();
dTotalPrice += itmHDMI.getOrderPrice();
dTotalPrice += itmGlasses.getOrderWeight();
iTotalWeight += itmGlasses.getOrderPrice();
iTotalWeight += itmKeyboard.getOrderWeight();
iTotalWeight += itmHDMI.getOrderWeight();
iTotalWeight += itmGlasses.getOrderWeight();
// Here we show the order details
cout << "The price of your order is $ " << dTotalPrice << endl;
cout << "The shipping weight is " << iTotalWeight << " ounces\n";
cout << "That is " << iTotalWeight/16 << " pounds\n";
return 0;
}
我很感興趣,知道在哪裏我錯了。
在此先感謝!
那麼它有什麼「關」呢? – Daniel
當你沒有提供你得到的錯誤信息時,你顯然出錯了...... – ppeterka
它用奇怪的數字編譯而不是類似我應該得到的值。 – David