問題...UML圖解釋Qt中
我試圖解釋使用Qt這個UML圖: 我關注的是如何界定的QList類以及如何實現的聚合和組合關係。我明白,繼承是由......派生類:公共基本指令。
#ifndef PRODUCT_H
#define PRODUCT_H
#include <Transaction.h>
#include <QString>
#include <QList>
#include <QDate>
#include <QDebug>
//define product class
class Product {
public:
Product(QString name, int num, double seprice, double suprice, QString sc);
virtual void sell(int n);
void restock(int n);
QString getSupplierCode();
void setProductCode(QString c);
QString getProductCode();
QList<Transaction*>getTransactions();
QString toString();
void removeAll();
bool isExpired();
private:
QString m_Name;
int m_NumOfItems;
QString m_ProductCode;
double m_SellingPrice;
double m_SupplierPrice;
QString m_SupplierCode;
QList<Transaction*>m_Transactions;
};
//end of product class
#endif //PRODUCT_H
#ifndef FOODPRODUCT_H
#define FOODPRODUCT_H
//begining of FoodProduct class
class FoodProduct : public Product {
public:
FoodProduct(QString name, int num, double seprice, double suprice, QString sc, QDate sbd);
void sell(int n);
QString toString();
bool isExpired();
private:
QDate m_SellByDate;
};
//end of FoodProduct Class
#endif // FOODPRODUCT_H
#ifndef PRODUCTLIST_H
#define PRODUCTLIST_H
//begining of ProductList Class
class ProductList : public QList<Product*> {
public:
QString add(QString name, int num, double seprice, double suprice, QString sc, QDate sbd);
void sell(QString pc, int n);
void restock(QString pc, int n);
QString toString();
void removeStock();
QString getTransactions(QString pc) const;
private:
int m_NextCode;
};
//end of ProductList Class
#endif //PRODUCTLIST_H
#include <Product.h>
#ifndef TRANSACTION_H
#define TRANSACTION_H
//begining of Transaction Class
class Transaction
{
public:
Transaction(QString type, QDate date, int num, double price);
QString toString();
private:
QString m_Type;
QDate m_Date;
int m_NoOfItems;
double m_PricePerItem;
};
//end of Transaction class
#endif // TRANSACTION_H
implementations
#include <Product.h>
Product::Product(QString name, int num, double seprice, double suprice, QString sc)
{
m_Name = name;
m_NumOfItems = num;
m_SellingPrice = seprice;
m_SupplierPrice = suprice;
m_SupplierCode = sc;
}
void Product::sell(int n)
{
if(m_NumOfItems == 0)
{
qDebug() << "Out of stock";
}
else
{
m_NumOfItems -= n;
m_Transaction.append(Transaction("Sale", QDate::currentDate(),n, m_SellingPrice));
}
}
void Product::restock(int n)
{
m_NumOfItems += n;
m_Transaction.append(Transaction("Purchase", QDate::currentDate(),n, m_SupplierPrice));
}
QString Product::getSupplierCode()
{
return m_SupplierCode;
}
void Product::setProductCode(QString c)
{
m_ProductCode = c;
}
QString Product::getProductCode()
{
return m_ProductCode;
}
QString Product::toString()
{
return QString("Product Name: %1\nProduct Code: %2\nSupplier Price: %3\nSelling Price: %4\nSupplier Code: %5")
.arg(m_Name).arg(m_ProductCode).arg(m_SupplierPrice).arg(m_SellingPrice).arg(m_SupplierCode);
}
void Product::removeAll()
{
m_NumOfItems = 0;
}
-------------------------
#include <Transaction.h>
Transaction::Transaction(QString type, QDate date, int num, double price)
{
m_Type = type;
m_Date = date;
m_NoOfItems = num;
m_PricePerItem = price;
}
QString Transaction::toString()
{
QString date1;
date1 = m_Date.toString();
return QString("Transaction Type: %1\nDate: %2\nNumber of Items: %3\nPrice: R%4\n")
.arg(m_Type).arg(date1).arg(m_NoOfItems).arg(m_PricePerItem*m_NoOfItems);
}
--------------------------
FoodProduct::FoodProduct(QString name,int num, double seprice, double suprice, QString sc, Qdate sbd)
{
FoodProduct = Product();
m_SellByDate = sbd;
}
void FoodProduct::sell(int n)
{
if (isExpired())
qDebug << "Product has expired!";
else Product::sell(n);
}
bool FoodProduct::isExpired()
{
return(m_SellByDate < QDate::currentDate());
}
QString FoodProduct::toString()
{
Product::toString();
}
--------------------
#include ProductList.h
QString ProductList::add(QString name, int num, double seprice, double suprice, QString sc, QDate sbd)
:int m_NextCode(1001);
{
ProductList = Product();
m_SellByDate = sbd;
m_NextCode++;
}
ProductList::~ProductList()
{
}
void ProductList:sell(Qstring pc, int n)
{
foreach(Product* pc, ProductList)
{
ProductList::m_NumberOfItems -= n;
}
}
void ProductList:restock(Qstring pc, int n)
{
foreach(Product* pc, ProductList)
{
ProductList::m_NumberOfItems += n;
}
}
void ProductList::removeStock()
{
foreach(Product* pc, ProductList)
{
if (ProductList::isExpired())
ProductList::m_NumberOfItems = 0;
}
}
QString ProductList::toString()
{
return QString("Product Name: %1\nProduct Code: %2\nNumber of Items: %3")
.arg(ProductList::m_Name).arg(ProductList::m_ProductCode).arg(ProductList::m_NumberofItems);
}
QString ProductList::getTransactions(QString pc)
{
}
請問UML在哪裏?我不會閱讀上面的長文本。 –
謝謝,我可以通過電子郵件發送它,我不知道如何在這裏附上圖像?它告訴我需要10個聲望才能發佈圖片。 – Morgs
將其放置在公共服務器上(例如imageshack.us)併發布鏈接。一旦你獲得了聲望(很快),你可以直接發佈圖片。 –