Question

In: Computer Science

c++ Redefine CDAccount from Display 10.1 so that it is a class rather than a structure....

c++

Redefine CDAccount from Display 10.1 so that it is a class rather than a structure. Use the same member variables as in Display 10.1 but make them private. Include member functions for each of the following: one to return the initial balance, one to return the balance at maturity, one to return the interest rate, and one to return the term. Include a constructor that sets all of the member variables to any specified values, as well as a default constructor. Embed your class definition in a test program.

10.1 display

#include <iostream>
3 using namespace std;
4 //Structure for a bank certificate of deposit:
5 struct CDAccount
6 {
7 double balance;
8 double interestRate;
9 int term; //months until maturity
10 };
11
12
13 void getData(CDAccount& theAccount);
14 //Postcondition: theAccount.balance and theAccount.interestRate
15 //have been given values that the user entered at the keyboard.
16
17
18 int main( )
19 {
20 CDAccount account;
21 getData(account);
22
23 double rateFraction, interest;
24 rateFraction = account.interestRate / 100.0;
25 interest = account.balance * rateFraction * (account.term / 12.0);
26 account.balance = account.balance + interest;
27
28 cout.setf(ios::fixed);
29 cout.setf(ios::showpoint);
30 cout.precision(2);
31 cout << "When your CD matures in "
32 << account.term << " months,\n"
33 << "it will have a balance of $"
34 << account.balance << endl;
35 return 0;
36 }
37
38 //Uses iostream:
39 void getData(CDAccount& theAccount)
40 {
41 cout << "Enter account balance: $";
42 cin >> theAccount.balance;
43 cout << "Enter account interest rate: ";
44 cin >> theAccount.interestRate;
45 cout << "Enter the number of months until maturity\n"
46 << "(must be 12 or fewer months): ";
47 cin >> theAccount.term;
48 }

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include <iostream>

using namespace std;

class CDAccount

{

    private:

        double balance;

        double interestRate;

        int term; //months until maturity

    public:

        CDAccount(){

            balance = 0;

            interestRate = 0.0;

            term = 0;

        }

        CDAccount(double bal, double interest, int _term){

            balance = bal;

            interestRate = interest;

            term = _term;

        }

        double getInitialBalance(){

            return balance;

        }

        double getBalance(){

            double rateFraction, interest;

            rateFraction = interestRate / 100.0;

            interest = balance * rateFraction * (term / 12.0);

            return balance + interest;

        }

        double getInterestRate(){

            return interestRate;

        }

        int getTerm(){

            return term;

        }

};

void getData(double &balance, double &interestRate, int &terms);

int main()

{

    double balance, interestRate;

    int terms;

    getData(balance, interestRate, terms);

    CDAccount account(balance, interestRate, terms);

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    cout.precision(2);

    cout << "When your CD matures in "

         << account.getTerm() << " months,\n"

         << "it will have a balance of $"

         << account.getBalance() << endl;

    return 0;

}

//Uses iostream:

void getData(double &balance, double &interestRate, int &terms)

{

    cout << "Enter account balance: $";

    cin >> balance;

    cout << "Enter account interest rate: ";

    cin >> interestRate;

    cout << "Enter the number of months until maturity\n"

         << "(must be 12 or fewer months): ";

    cin >> terms;

}


Related Solutions

class rather than ethnicity is responsible for stratification in the Caribbean.
class rather than ethnicity is responsible for stratification in the Caribbean.
Q2: Describe the structure of the courts in Canada and illustrate the litigation process rather than...
Q2: Describe the structure of the courts in Canada and illustrate the litigation process rather than to copy from internet
Suppose that money demand depends on consumption rather than on income, so that the equation for...
Suppose that money demand depends on consumption rather than on income, so that the equation for the money market becomes: M/P = L [r, C(Y-T)]. Analyze the impact of a tax cut in a small open economy on the exchange rate and income under both floating and fixed exchange rates
C. Design a RandomCipher class as a subclass of the substitutionCipher from exercise P-3.40, so that...
C. Design a RandomCipher class as a subclass of the substitutionCipher from exercise P-3.40, so that each instance of the class relies on a random permutation of letters for its mapping.
What is the advantage of defining the member functions outside a class rather than defining inside...
What is the advantage of defining the member functions outside a class rather than defining inside a class? How the following are achieved in C++? a) static polymorphism. b) dynamic polymorphism What will happen if you forget to implement the pure virtual function in the derived class? How a function templates differs from function overloading?
Suppose our IS/LM model from class is adjusted so that y = c (y – T,...
Suppose our IS/LM model from class is adjusted so that y = c (y – T, confidence) + I (I + premium, confidence) + G m/p= L (i, y) i = Federal Funds rate Suppose the government takes action to improve the solvency of the financial system. Assume that there is an unusually high premium added to the federal funds interest rate when firms borrow at the moment. If the government action is successful, and banks become more willing to...
Here is my C++ program so far. Is there anyway I can make it display an...
Here is my C++ program so far. Is there anyway I can make it display an error if the user enters a float? Thanks #include <iostream> using namespace std; // Creating a constant for the number of integers in the array const int size = 10; int main() { // Assigning literals to the varibles int a[size]; int sum=0; float avg; // For loop that will reiterate until all 10 integers are entered by the user for(int i=0; i<size; i++)...
Imagine that the Earth’s rotational axis was tilted 90 degrees rather than 23.5 degrees (so the...
Imagine that the Earth’s rotational axis was tilted 90 degrees rather than 23.5 degrees (so the polar axis would point towards the Sun twice a year). Describe the apparent motion of the Sun and stars over a 24-h period on the winter solstice from (a) the North Pole, (b) the equator, and (c) the South Pole. Note that the Sun’s angular diameter is 0.5 degrees.
Redesign topsort so it selects the LAST NODE in each iteration, rather than the first. def...
Redesign topsort so it selects the LAST NODE in each iteration, rather than the first. def topsort(G): count = dict((u, 0) for u in G) # The in-degree for each node for u in G: for v in G[u]: count[v] += 1 # Count every in-edge Q = [u for u in G if count[u] == 0] # Valid initial nodes S = [] # The result while Q: # While we have start nodes... u = Q.pop() # Pick...
1) Short tandem repeats belong to the ______ class of DNA polymorphisms. 2) Rather than representing...
1) Short tandem repeats belong to the ______ class of DNA polymorphisms. 2) Rather than representing a biowarfare attack designed to infect US populations, explain the more likely intention of the anthrax letters of 2001. 3) Explain the benefit of engineering pathogen-resistant plants
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT