Question

In: Computer Science

Using C++. Please number the answers for clarity 1. Create an Account object named as myAccount...

Using C++. Please number the answers for clarity

1. Create an Account object named as myAccount and initialize it with appropriate data.

2. Change myAccount’s interest rate to 1%

3. display the balance on myAccount.

4. Declare a pointer variable ptr and initialize it with the address of myAccount. Display the interest earned on myAccount by using pointer ptr.

5. Dynamically allocate an array of five Account objects.

6. Suppose  getAcctNum() returns the account number of a given Account variable.  Write a function that returns a boolean value to find if a given account number appears in an array of Account objects.

Solutions

Expert Solution

Hi,

Please find code below.Output attached.

#include <iostream>
using namespace std;
class Account
{
private:
  
   int accountNum; //Account Number
   double balance; //depicts Current Balance of the account
   double interestRate; // depicts interest rate of the account.


public:
   // access specifier is public for below methods.
   Account() //Default Constructor (no parameters)
   {
   accountNum = 0;
balance = 0;
interestRate = 0;
   }
   Account(int accnum, double bal, double interest)// parametrised constructor
   {
   accountNum = accnum;
   balance = bal;
   interestRate = interest;
   }

   //setters
   void setAccountNum(int x)
   {
   accountNum = x;
   }
   void setBalance(double x)
   {
   balance = x;
   }
   void setInterestRate(double x)
   {
   interestRate = x;
   }

   //Getters
   int getAccountNum()
   {
   return accountNum;
   }
   double getBalance()
   {
   return balance;
   }
   double getInterestRate() // considering this as annual interest rate.
   {
   return interestRate;
   }

  
   bool withdraw(double withdrawAmount)
   {
   if (balance >= withdrawAmount)
   {
   balance -= withdrawAmount;
       return true;
   }
   else
   {   
   return false;
   }
   }
   void deposit(double depositAmount)
   {
  
   balance += depositAmount;
   }
  
   double getMonthlyInterestEarned()
{   
double monthlyInterestRate = interestRate / 12;  
   double interestEarned = monthlyInterestRate * balance;
   return interestEarned;
}

};

int main()
{
// Step 1: Create an Account object named as myAccount and initialize it with appropriate data.
Account myAccount(111,100,8);
  
//Step 2:Change myAccount’s interest rate to 1%
myAccount.setInterestRate(2);
myAccount.deposit(100);
myAccount.withdraw(50);
  
  
//step 3. display the balance on myAccount.
cout << "Balance on myAccount is:" << myAccount.getBalance() << endl;
  
//4. Declare a pointer variable ptr and initialize it with the address of myAccount.
//Display the interest earned on myAccount by using pointer ptr.
  
Account *acctPtr = &myAccount;
double intEarned = acctPtr->getMonthlyInterestEarned();
cout << "Monthly interest earned is:" << intEarned << endl;
  
//5. Dynamically allocate an array of five Account objects.
Account **myVar;
myVar = new Account*[5];
  
myVar[0] = new Account(222,200,9);
myVar[1] = new Account(333,300,7);
myVar[2] = new Account(444,400,6);
myVar[3] = new Account(555,500,5);
myVar[4] = new Account(666,600,4);
  

//step 6:Suppose  getAcctNum() returns the account number of a given Account variable.  Write a function that //returns a boolean value to find if a given account number appears in an array of Account objects.
int accountNumber;
bool found = false;
cout << "Enter the account number to be searched in array of objects" << endl;
cin >> accountNumber;
for(int i=0;i<5;i++)
{
if(myVar[i]->getAccountNum() == accountNumber)
{
found = true;
}
if(found)
break;
}
if(found)
cout << " Given account number :" << accountNumber << " found and is available in array of objects" << endl;
else
cout << "Sorry account number not found" << endl;
  
  
}

Output :

Thanks,

kindly upvote.


Related Solutions

Create a random number generator object named myRandom and an integer variable named intRoulette. Set intRoulette...
Create a random number generator object named myRandom and an integer variable named intRoulette. Set intRoulette to be a random number from 0 to 36 (including the numbers 0 and 36). (visual studios 2015) using tryparse
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a...
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a memory so you store that number of integers write integers in order starting from 1 until you fill all that memory print the address and values of the first and the last integer stored in the memory
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory so you store that number of integers. Write integers in order starting from 1 until you fill all that memory. Print the addresses and values of the first and the last integer stored in the memory.
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory...
Create C program that takes 1 parameter: a number. Using that number, dynamically allocate a memory so you store that number of integers. Write integers in order starting from 1 until you fill all that memory. Print the addresses and values of the first and the last integer stored in the memory. Help ASAP!!!
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named...
Using C# Create a class named Inches To Feet. Its Main()method holds an integer variable named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT