#2
rjsp2016-08-19 16:18
|
程序代码:
#ifndef __ACCOUNT_H__
#define __ACCOUNT_H__
class SavingAccount{
private:
int id;
int lastDate;
double balance;
double rate;
double accumlation;
static double total;
void record(int date,double amount);
double accumlate(int date)const{
return accumlation+balance*(date-lastDate);
}
public:
SavingAccount(int id,int date,double rate);
int getId()const{return id;}
double getRate()const{return rate;}
double getBalance()const{return balance;}
static double getTotal(){return total;}
void deposit(int date,double amount);
void withdraw(int date,double amount);
void settle(int date);
void show()const;
};
#endif
程序代码:
#include"account.h"
#include<iostream>
#include<cmath>
using namespace std;
double SavingAccount::total=0;
SavingAccount::SavingAccount(int id,int date,double rate)
: id(id),balance(0),lastDate(date),rate(rate),accumlation(0){
cout<<date<<" #"<<id<<" id created!"<<endl;
}
SavingAccount::record(int date,double amount){
accumlation=accumlate(date);
lastDate=date;
amount=floor(amount*100+0.5)/100;
balance+=amount;
total+=amount;
cout<<date<<"\t#"<<id<<amount<<"\t"<<balance<<endl;
}
SavingAccount::deposit(int date,double amount){
record(date,amount);
}
SavingAccount::withdraw(int date,double amount){
if(amount<=balance)
record(date,-amount);
else
cout<<"Error:not enough money!"<<endl;
}
SavingAccount::settle(int date){
double interest=accunlate(date)*rate/365;
if(interest!=0)
record(date,interest);
accumlation=0;
}
void SavingAccount::show(){
cout<<"#"<<id<<"\tBalance:"<<balance;
}
程序代码:
#include"account.h"
#include<iostream>
using namespace std;
ing main(){
SavingAccount sao(20160727,1,0.015);
SavingAccount sal(20160728,1,0.015);
sa0.deposit(5,5000);
sal.deposit(25,10000);
sao.deposit(45,5500);
sal.withdraw(60,4000);
sao.settle(90);
sal.settle(90);
sao.show(); cout<<endl;
sal.show(); cout<<endl;
cout<<"Total:"<<SavingAccount.getTotal()<<endl;
return 0;
}
错误:
--------------------Configuration: 511 - Win32 Debug--------------------
Compiling...
account.cpp
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(11) : error C2556: 'int __thiscall SavingAccount::record(int,double)' : overloaded function differs only by return type from 'void __thiscall SavingAccount::record(int,double)
'
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(11) : see declaration of 'record'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(11) : error C2371: 'record' : redefinition; different basic types
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(11) : see declaration of 'record'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(19) : error C2556: 'int __thiscall SavingAccount::deposit(int,double)' : overloaded function differs only by return type from 'void __thiscall SavingAccount::deposit(int,doubl
e)'
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(21) : see declaration of 'deposit'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(19) : error C2371: 'deposit' : redefinition; different basic types
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(21) : see declaration of 'deposit'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(20) : error C2264: 'record' : error in function definition or declaration; function not called
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(22) : error C2556: 'int __thiscall SavingAccount::withdraw(int,double)' : overloaded function differs only by return type from 'void __thiscall SavingAccount::withdraw(int,dou
ble)'
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(22) : see declaration of 'withdraw'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(22) : error C2371: 'withdraw' : redefinition; different basic types
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(22) : see declaration of 'withdraw'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(24) : error C2264: 'record' : error in function definition or declaration; function not called
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(28) : error C2556: 'int __thiscall SavingAccount::settle(int)' : overloaded function differs only by return type from 'void __thiscall SavingAccount::settle(int)'
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(23) : see declaration of 'settle'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(28) : error C2371: 'settle' : redefinition; different basic types
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(23) : see declaration of 'settle'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(29) : error C2065: 'accunlate' : undeclared identifier
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(31) : error C2264: 'record' : error in function definition or declaration; function not called
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\account.cpp(34) : error C2511: 'show' : overloaded member function 'void (void)' not found in 'SavingAccount'
c:\program files (x86)\microsoft visual studio\myprojects\511\account.h(3) : see declaration of 'SavingAccount'
main.cpp
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\main.cpp(5) : error C2146: syntax error : missing ';' before identifier 'main'
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\main.cpp(5) : error C2501: 'ing' : missing storage-class or type specifiers
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\511\main.cpp(5) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
511.exe - 1 error(s), 0 warning(s)