C++ examples for Class:Class Creation
Create class to do the Sales Commission Calculate
#include <iostream> //ww w. j av a 2s.com class Account { private: const double COMMISSION = 0.09f; const double BASEPAY = 200.0f; double weeklySales = 0.0f; double weeklyEarnings = 0.0f; public: Account(); ~Account(); // SETTERS void setWeeklySales(double); void setWeeklyEarnings(); // GETTERS double getWeeklySales(); double getWeeklyEarnings(); void run(); }; Account::Account() {} Account::~Account() {} // SETTERS void Account::setWeeklySales(double sales) { weeklySales = sales; } void Account::setWeeklyEarnings() { weeklyEarnings = BASEPAY + (getWeeklySales() * COMMISSION); } // GETTERS double Account::getWeeklySales() { return weeklySales; } double Account::getWeeklyEarnings() { return weeklyEarnings; } void Account::run() { double dtmp = 0.0f; std::cout << "Enter sales in dollars (-1 to end): "; std::cin >> dtmp; setWeeklySales(dtmp); if (getWeeklySales() != -1) { setWeeklyEarnings(); std::cout << "Salary is: $" << getWeeklyEarnings() << std::endl; } } int main(int argc, const char *argv[]) { Account scc; while (scc.getWeeklySales() != -1) { scc.run(); } return 0; }