存款利息问题
【问题描述】
利息存款问题
存款类型和利率分别如下:
活期 0.35% 一年 3.25% 两年3.75% 三年4.25% 五年4.75%
编写程序账户类,包括编号,姓名 ,本金,存储类型,以及利率等信息,能够计算账户存款到期的利息值并显示。
#include <string> #include<iostream> using namespace std; class Account { public: Account(); Account(string ID, string Name, int MoneyCapital, int DepositType, double Life) { this->mID = ID; this->mName = Name; this->mMoneyCapital = MoneyCapital; this->mDepositType = DepositType; this->mLife = Life; } double getInterst() { return mMoneyCapital * InterestRate[mDepositType] * mDepositType+mMoneyCapital*mLife*InterestRate[0]; } private: string mID,mName; int mMoneyCapital;// 本金 int mDepositType; //存款类型 float mLife; //简化处理输入以年为单位 static float InterestRate[5];//利率 float mInerest;//利息 }; float Account::InterestRate[5]= { 0.0035,0.0325,0.0375,0.0425,0.0475 }; Account::Account() { }; int main() { Account a1("1001","zhang3",10000,1,0.8); Account a2("1002","li4",2000,2,1); cout<<a1.getInterst(); cout<<a2.getInterst(); }
静态数据成员应用-货物销售
#include <string> #include<iostream> using namespace std; class Goods { public: Goods(string id,string name,float inprice,float outprice,int num); Goods(); void sell(int sales); float getInPrice() { return this->mInPrice; } float getOutPrice() { return this->mOutPrice; } void buy(int num) { this->mNum+=num; } string GetId() { return mId; } void SetId(string val) { mId = val; } string GetName() { return mName; } void SetName(string val) { mName = val; } static float Getsum() { return sum; } static float getProfit() {return profit;} private: string mId; string mName; float mInPrice; float mOutPrice; int mNum; static float profit; static float sum; ; }; float Goods::profit = 0; float Goods::sum = 0; Goods::Goods(string id, string name, float inprice, float outprice, int num) { this->mId = id; this->mName = name; this->mInPrice = inprice; this->mOutPrice = outprice; this->mNum = num; } Goods::Goods() { } void Goods::sell(int sales) { this->sum += this->getOutPrice() * sales; this->profit += (this->getOutPrice() - this->getInPrice()) * sales; } int main() { Goods gd[100]; gd[0]=Goods("1001","白菜",0.8,1.5,500); gd[1]=Goods("1002","萝卜",1.5,2.1,500); gd[0].sell(10); gd[1].sell(20); gd[0].sell(5); cout<<gd[0].Getsum()<<endl; cout<<gd[1].Getsum()<<endl; cout<<gd[0].getProfit()<<endl; return 0; }