Question

C++ Create a class named SavingsAccount that contains the following: Three (3) private class variables: a...

C++

Create a class named SavingsAccount that contains the following:

  1. Three (3) private class variables: a String called ‘name’, a double called “balance” and another double called “interestRate” and 4 function prototypes.
  2. A constructor that receives 3 parameters: a string, and 2 doubles; the constructor will use these parameters to initialize the name, the balance, and the interestRate respectively.
  3. setBalance: it receives a double parameter called theBalance and assigns it to the balance.
  4. getBalance: it returns the balance.
  5. calculateInterestAmount: it calculates and returns the interest amount for the current balance (interestAmount = balance x interestRate)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Code:

Output:

Here I first take balance is 0 and then assigned 1200 to balance through setBalance..

And print the balance and Interest Amount to Screen

Raw Code:

#include <iostream>
#include <stdio.h>
using namespace std;
class SavingsAccount //CreaThreeting a class
{
private: //Three private class variables
        string name;
        double balance;
        double interestRate;
    public:
        SavingsAccount(string a,double b,double c){ //A constructor with 3 parameters
            name = a;
            balance = b; //assigning values
            interestRate = c;
        }
    public:
        void setBalance(double theBalance) {//Setter to set balance to a private variable
            balance = theBalance;//setting to balance
        }
   int getBalance() {//Getter to return private variable balance
       return balance;
   }
   public:
       double calculateInterestAmount(){//Prototype to return interest amount
           double InterestAmount = balance*interestRate;//Calculating interest amount
           return InterestAmount;//returning Interest Amount
       }
};

int main(){
   SavingsAccount obj("John",0,2);//Instance of the class to obj default balance is 0
   obj.setBalance(1200); //Setting Balance to 1200
   cout <<"The Balance is " << obj.getBalance() << endl ;//Printing Setted balance
   cout << "The interest Amount "<< obj.calculateInterestAmount() << endl ;//printing Interest Amount
   return 0;
}

Thank You ,

please do vote(Like)...

Add a comment
Know the answer?
Add Answer to:
C++ Create a class named SavingsAccount that contains the following: Three (3) private class variables: a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

  • Java please Assume the existence of a BankAccount class. Define a subclass, SavingsAccount that contains the...

    Java please Assume the existence of a BankAccount class. Define a subclass, SavingsAccount that contains the following: a double instance variable, interestRate a constructor that accepts a parameter of type double which is used to initialize the instance variable

  • For this lab you must write a complete class in C++. This will be a class...

    For this lab you must write a complete class in C++. This will be a class named BankAccount. This class must have the following private variables: 1. accountHolderName : string 2. balance : double 3. interestRate: double This class must have the following public constructor: 1. BancAccount(name : string, balance : double, rate : double) This class must have the following public member functions: 1. getAccountHolderName() : string a. returns the account holders name 2. getBalance() : double a. returns...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • In C++: Define a class named Account that stores a balance (monetary amount). The class should...

    In C++: Define a class named Account that stores a balance (monetary amount). The class should have a private double variable balance. Add one accessor getBalance function that returns the balance and one deposit function that increases the balance by a given double amount. Then subclass Account with a SavingsAccount class. This class should have a private double variable interest. Add an addInterest function that increases the balance (from the superclass Account) according to the interest. Demonstrate the use in...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • Application should be in C# programming language Create a class called SavingsAccount.  ...

    Application should be in C# programming language Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the...

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT