【发布时间】:2012-11-19 13:51:09
【问题描述】:
我试图让这个程序开始运行,但目前我只是得到错误。我不知道如何让它工作。如果我将类 SavingsAccount 更改为 public 应该没问题,但我必须保持原样。
问题出在主函数中。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class SavingsAccount
{
int accountType;
string ownerName;
long ssn;
double accountClosurePenaltyPercent, accountBalance;
void Information();
inline double AccountClosureLoss()
{
return (accountBalance * accountClosurePenaltyPercent);
}
void OutputInformation();
};
void SavingsAccount::Information()
{
cout << "Enter Account Type (1 for Checking or 2 for Savings): ";
cin >> accountType;
cout << "Enter owner name: ";
getline(cin, ownerName);
cout << "Enter the Social Security Number: ";
cin >> ssn;
cout << "Enter the percent penalty for closing account(decimal form): ";
cin >> accountClosurePenaltyPercent;
cout << "Enter the account balance: ";
cin >> accountBalance;
}
void SavingsAccount::OutputInformation()
{
cout << "Account Type: " << endl;
cout << "Name: " << ownerName << endl;
cout << "SSN: " << ssn << endl;
cout << "Account Closure Penaly %: " << accountClosurePenaltyPercent << endl;
cout << "Account Balance: " << accountBalance;
}
int main(void)
{
SavingsAccount.Information();
SavingsAccount.AccountClosureLoss();
SavingsAccount.OutputInformation();
return 0;
}
到目前为止我尝试了什么。
int main(void)
{
SavingsAccount John;
John.Information();
John.AccountClosureLoss();
John.OutputInformation();
return 0;
}
有什么建议吗?
【问题讨论】:
-
Friend functions in C++ 的可能重复项
-
我意识到白天的反对票比晚上多得多。
-
考虑一下时区,以及 SO 的大部分用户可能居住的地方 ;-)
标签: c++ class methods private-members