C++ 编译连接不上!不知道错在哪里,找不到!

来源:百度知道 编辑:UC知道 时间:2024/06/21 00:26:30
1.创建一个SavingsAccount类:
(1) 用static(静态)数据成员包含每个存款人的annualInterestRate(年利率)。类的每个成员包含一个private数据成员savingsBalance,表示当前存款额。
(2) 提供一个 calculateMonthlyInterest 成员函数,计算月利息,用savingsBalance乘以annualInterestRate除以12取得,并将当月月息加入savingsBalance。
(3) 提供一个静态成员函数modifyInterestRate, 将静态annualInterestRate设置为新值。实例化两个不同的SavingsAccount对象saver1和saver2,余额分别为$2 000.00和$3 000.00 将annualInterestRate设置为3%,计算每个存款人的月息并打印出新的结果。

#include<iostream.h>
class SavingsAccount
{ static double annualInterestRate;
double savingsBalance;
public:
SavingsAccount(double a,double b)
{annualInterestRate=a; savingsBalance=b;}

void calculateMonthlyInterest()
{double calculateMonthlyInterest;
calculateMonthlyInterest=annualInterestRate*savingsBalance/12;
savingsBalance+=calculateMonthlyInterest;}

static void modifyInterestRate(double n)
{annualInterestRate=n;}

void display()
{cout<&

#include<iostream.h>
class SavingsAccount
{ static double annualInterestRate;
double savingsBalance;
public:
SavingsAccount(double a,double b)
{annualInterestRate=a; savingsBalance=b;}

void calculateMonthlyInterest()
{double calculateMonthlyInterest;
calculateMonthlyInterest=annualInterestRate*savingsBalance/12;
savingsBalance+=calculateMonthlyInterest;}

static void modifyInterestRate(double n)
{annualInterestRate=n;}

void display()
{cout<<annualInterestRate<<" "<<savingsBalance<<endl;}
};
double SavingsAccount::annualInterestRate;//********静态成员需要在类外声明***********
void main()
{SavingsAccount saver1(0.05,20000.00),saver2(0.05,30000.00);
saver1.display();
saver2.display();
SavingsAccount::modifyInterestRate(0.03);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
saver1.display();
saver