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

CODE IN C++ PLEASE Create a structure (object) named Person that has the following characteristics: •...
CODE IN C++ PLEASE Create a structure (object) named Person that has the following characteristics: • full name • age • family members full names represent by an array of size 10. Write a program that creates an array of Person of size 5. Populate the array of objects with the information given by user input according to the following specifications: • With input from the user i) Populate only 3 positions of the array of Person object. ii) Populate...
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
Please write program in c++ with using pointer. create a function that can find the number...
Please write program in c++ with using pointer. create a function that can find the number of even numbers that are between the maximum and minimum elements of an given array.The program have to use pointer. example 8 -1 2 2 1 9 2 4 0 output: 2
Question: In a package named "oop" create a Scala class named "Team" and a Scala object...
Question: In a package named "oop" create a Scala class named "Team" and a Scala object named "Referee". Team will have: • State values of type Int representing the strength of the team's offense and defense with a constructor to set these values. The parameters for the constructor should be offense then defense • A third state variable named "score" of type Int that is not in the constructor, is declared as a var, and is initialized to 0 Referee...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT