C++ 需要帮助在类中创建对象,并为成员函数赋值吗
分配详细信息(我的代码放在下面):C++ 需要帮助在类中创建对象,并为成员函数赋值吗,c++,C++,分配详细信息(我的代码放在下面): 给出一个C++类声明,名为SavingsAccount,包含以下信息: 操作(成员功能): 开立账户(初始存款)。这被称为以美元和美分表示初始值 付定金。为美元和美分增值的函数 撤回。从美元和美分中减去值的函数 显示当前余额。将打印美元和美分的函数 数据(成员数据): 美元 美分 给出所有成员函数的实现代码 编写将创建名为bank1的对象的代码。代码将首先在帐户中存入200.50美元。代码将先存入40.50美元,然后再提取100.98美元。它将打印出美元和美分
给出一个C++类声明,名为SavingsAccount,包含以下信息:
操作(成员功能):// PART 2: Allow the USER to input Initial, Deposit, and Withdrawl values.
// NOTE: You must perform normalization on cents. This means that if cents is
// 100 or more, it must increment dollars by the appropriate amount. Example:
// if cents is 234, then dollars must be increased by 2 and cents reduced to 34.
#include <iostream>
using namespace std;
// SavingsAccount class declaration:
class SavingsAccount
{
private:
int dollars;
int cents;
public:
void setOpen(int, int);
void setDeposit(int, int);
void setWithdrawl(int, int);
void showBalance();
};
//*******************************************************
// setOpen function, allows user to open a new Account **
//*******************************************************
void SavingsAccount::setOpen(int d, int c)
{
dollars = d;
cents = c;
cout << "Input Dollars for Opening Balance:" endl;
cin >> "$" >> dollars;
cout << "Input Cents for Opening Balance:" endl;
cin >> "." >> cents;
// Normalize dollars and cents
while(cents >=100)
{
cents-=100;
dollars++
};
};
//************************************************************
//setDeposit function, adds a Deposit to the user's Account **
//************************************************************
void SavingsAccount::setDeposit(int d, int c)
{
dollars = d;
cents = c;
cout << "Input Dollars to Deposit:" endl;
cin >> "$" >> dollars
cout << "Input Cents to Deposit:" endl;
cin >> "." >> cents
dollars += d;
cents += c;
// normalize dollars and cents
while(cents >= 100)
{
cents -= 100;
dollars++;
};
};
//*******************************************************************
// setWithdrawl function, withdrawls money from the user's Account **
//*******************************************************************
void SavingsAccount::setWithdrawl(int d, int c)
// normalize dollars and cents
{
dollars = d;
cents = c;
cout << "Input Dollars to Withdrawl:" endl;
cin >> "$" >> dollars;
cout << "Input Cents to Withdrawl:" endl;
cin >> "." >> cents;
while(c >=100)
{
c -= 100;
d++;
};
if(c > cents)
{
dollars--;
cents += 100;
};
dollars -= d;
cents -= c;
};
//******************************************************************
// showBalance function, shows the user's current account balance **
//******************************************************************
void SavingsAccount::showBalance()
{
cout << "Your current balance is: $" << dollars << "." << cents << endl;
};
//******************
// Function Main **
//******************
int main()
{
char answer; // To hold Y or N input.
cout << "This program will help you open and manage a new Savings Account!" endl;
SavingsAccount::setOpen(int d, int c);
cout << "Do you wish to make a Deposit?" endl;
cout << "Press 'Y' for Yes, and 'N' for No." endl;
cin << answer;
do
{
SavingsAccount::setDeposit(int d, int c);
} while (answer = 'Y' || answer = 'y';
cout << "Do you wish to make a Withdrawl?" endl;
cout << "Press 'Y' for Yes, and 'N' for No." endl;
cin << answer;
do
{
SavingsAccount::setWithdrawl(int d, int c);
} while (answer = 'Y' || answer = 'y';
SavingsAccount::showBalance();
return 0;
};
//第2部分:允许用户输入初始值、存款值和取款值。
//注意:您必须对美分执行标准化。这意味着如果美分是
//100或更多,它必须以适当的金额增加美元。例子:
//如果美分是234,那么美元必须增加2美分,减少到34美分。
#包括
使用名称空间std;
//SavingsAccount类声明:
阶级储蓄帐户
{
私人:
整数美元;
整数美分;
公众:
void setOpen(int,int);
作废定金(整数,整数);
无效设置撤销(int,int);
void showBalance();
};
//*******************************************************
//setOpen函数,允许用户开立新帐户**
//*******************************************************
void SavingsAccount::setOpen(int d,int c)
{
美元=d;
美分=c;
cout>“$”>>美元;
cout>“>”美分;
//使美元和美分正常化
而(美分>=100)
{
美分-=100;
美元++
};
};
//************************************************************
//设置存款功能,向用户帐户添加存款**
//************************************************************
void SavingsAccount::setDeposit(整数d、整数c)
{
美元=d;
美分=c;
cout>“$”>>美元
cout>“>”美分
美元+=d;
美分+=c;
//使美元和美分正常化
而(美分>=100)
{
美分-=100;
美元++;
};
};
//*******************************************************************
//设置取款功能,从用户帐户取款**
//*******************************************************************
void SavingsAccount::setdrawingl(int d,int c)
//使美元和美分正常化
{
美元=d;
美分=c;
cout>“$”>>美元;
cout>“>”美分;
而(c>=100)
{
c-=100;
d++;
};
如果(c>美分)
{
美元--;
美分+=100;
};
美元-=d;
美分-=c;
};
//******************************************************************
//showBalance函数,显示用户的当前帐户余额**
//******************************************************************
void SavingsAccount::showBalance()
{
库特
但我不知道如何重新执行第1部分的函数,将预先分配的数字放入美元和美分变量中
听起来像是在创建SavingsAccount
实例时应该自动发生的事情。看看如何创建类构造函数和默认值参数。欢迎使用DumpMyHomeworkStackOverflow!请阅读常见问题解答,在这里以一个最小、完整的示例发布您的代码和工作,并说明您在哪里拥有pro特别是问题。最重要的是,始终标记作业,以便将其与其他问题区分开来,并进行相应处理(例如提示而非解决方案、假设新来者等)。打印格式化输出需要