Files
BasicsOfComputerSoftwareEng…/OOP/03/Optional01.cpp
2023-03-08 20:54:29 +08:00

66 lines
1.4 KiB
C++

#include <iostream>
class Seller {
private:
static int totalCount;
static double totalPrice;
int sellerNumber;
int sellCount;
double singlePrice;
public:
Seller();
Seller(int sellerNum, int sellCount, double price);
int getSellerNumber();
int getSellCount();
double getSinglePrice();
static double calcAvg();
static double getTotal();
};
Seller::Seller() {
this->sellerNumber = 0;
this->sellCount = 0;
this->singlePrice = 0;
}
Seller::Seller(int sellerNum, int newSellCount, double price) {
this->sellerNumber = sellerNum;
this->sellCount = newSellCount;
this->singlePrice = price;
Seller::totalCount += newSellCount;
Seller::totalPrice += price * newSellCount;
}
int Seller::getSellerNumber() {
return this->sellerNumber;
}
int Seller::getSellCount() {
return this->sellCount;
}
double Seller::getSinglePrice() {
return this->singlePrice;
}
double Seller::getTotal() {
return Seller::totalPrice;
}
double Seller::calcAvg() {
return Seller::totalPrice / Seller::totalCount;
}
int Seller::totalCount = 0;
double Seller::totalPrice = 0;
int main() {
Seller* s1 = new Seller(101, 5, 23.5);
Seller* s2 = new Seller(102, 12, 24.5);
Seller* s3 = new Seller(103, 100, 21.5);
std::cout << "Total: " << Seller::getTotal() << std::endl;
std::cout << "Avg: " << Seller::calcAvg() << std::endl;
return 0;
}