Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 1P

Solution to Practice Program 10.1

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.

Expert Solution & Answer
Check Mark
Program Plan Intro

Redefine CDAccount

Program Plan:

  • Include the necessary libraries.
  • Use namespace.
  • Define a class.
    • Declare the member functions as public.
    • Declare the variables as private.
  • Define the main method.
    • Declare the variables that are required for the program.
    • Call the function.
    • Display the messages.
  • Add member functions
    • Default constructor.
    • Constructor to set specified values.
    • To return interest rate.
    • To return initial balance.
    • To return balance at maturity.
    • To return the term.
    • input function (istream&);
    • output function (ostream&);
Program Description Answer

Program Description:

The following C++ program redefines CDAccount from Display 10.1 to be a class rather than struct.

Explanation of Solution

Program:

//Include libraries

#include <iostream>

//Use namespace

using namespace std;

//Define class

class CDAccount

{

//Public specifiers

public:

    //Declare member functions

    CDAccount();

    CDAccount(double bal, double intRate, int T);

    double InterestRate();

    double InitialBalance();

    double BalanceAtMaturity();

    int Term();

    void input(istream&);

    void output(ostream&);

//Private specifiers

private:

    //Declare variables

    double balance;

    double interestRate; // in PER CENT

    int term; // months to maturity;

};

//Main function

int main()

{

    //Declare variables

    double balance; double intRate;

    int term;

    //Constructor

    CDAccount account = CDAccount(100.0, 10.0, 6);

    //Display message

    cout << "CD Account interest rate: "

        << account.InterestRate() << endl;

    //Display message

    cout << "CD Account initial balance: "

        << account.InitialBalance() << endl;

    //Display message

    cout << "CD Account balance at maturity is: "

        << account.BalanceAtMaturity() << endl;

    //Display message

    cout << "CD Account term is: " << account.Term()

        << " months" << endl;

    account.output(cout);

    //Display message

    cout << "Enter CD initial balance, interest rate, "

        << " and term: " << endl;

    account.input(cin);

    //Display message

    cout << "CD Account interest rate: "

        << account.InterestRate() << endl;

    //Display message

    cout << "CD Account initial balance: "

        << account.InitialBalance() << endl;

    //Display message

    cout << "CD Account balance at maturity is: "

        << account.BalanceAtMaturity() << endl;

    //Display message

    cout << "CD Account term is: " << account.Term()

        << " months" << endl;

    account.output(cout);

    //Newline character

    cout << endl;

    //Pause console window

    system("pause");

}

//Default constructor

CDAccount::CDAccount() { /* do nothing */ }

//Constructor to set specified values

CDAccount::CDAccount(double bal, double intRate, int T)

{

    balance = bal;

    interestRate = intRate;

    term = T;

}

//Function to return interest rate

double CDAccount::InterestRate()

{

    //Return value

    return interestRate;

}

//Function to return initial balance

double CDAccount::InitialBalance()

{

    //Return value

    return balance;

}

//Function to return the balance at maturity

double CDAccount::BalanceAtMaturity()

{

    //Return value

    return balance * (1 + (interestRate / 100)*(term / 12.0));

}

//Function to return the term

int CDAccount::Term()

{

    //Return value

    return term;

}

//Input Function

void CDAccount::input(istream& inStream)

{

    //Store value

    inStream >> balance;

    inStream >> interestRate;

    inStream >> term;

}

//Output function

void CDAccount::output(ostream& outStream)

{

    //Display values

    outStream.setf(ios::fixed);

    outStream.setf(ios::showpoint);

    outStream.precision(2);

    //Display message

    outStream << "when your CD matures in " << term

        << " months" << endl

        << "it will have a balance of "

        << BalanceAtMaturity() << endl;

}

Sample Output

Output:

CD Account interest rate: 10

CD Account initial balance: 100

CD Account balance at maturity is: 105

CD Account term is: 6 months

when your CD matures in 6 months

it will have a balance of 105.00

Enter CD initial balance, interest rate, and term:

100

10

12

CD Account interest rate: 10.00

CD Account initial balance: 100.00

CD Account balance at maturity is: 110.00

CD Account term is: 12 months

when your CD matures in 12 months

it will have a balance of 110.00

Press any key to continue . . .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I would like to get help to resolve the following case
Last Chance Securities The IT director opened the department staff meeting today by saying, "I've got some good news and some bad news. The good news is that management approved the payroll system project this morning. The new system will reduce clerical time and errors, improve morale in the payroll department, and avoid possible fines and penalties for noncompliance. The bad news is that the system must be installed by January 1st in order to meet new federal reporting rules, all expenses from now on must be approved in advance, the system should have a modular design if possible, and the vice president of finance would like to announce the new system in a year-end report if it is ready by mid-December." Tasks 1. Why is it important to define the project scope? How would you define the scope of the payroll project in this case? 2. Review each constraint and identify its characteristics: present versus future, internal versus exter- nal, and mandatory versus desirable. 3. What…
2. Signed Integers Unsigned binary numbers work for natural numbers, but many calculations use negative numbers as well. To deal with this, a number of different methods have been used to represent signed numbers, but we will focus on two's complement, as it is the standard solution for representing signed integers. 2.1 Two's complement • Most significant bit has a negative value, all others are positive. So, the value of an n-digit -2 two's complement number can be written as: Σ2 2¹ di 2n-1 dn • Otherwise exactly the same as unsigned integers. i=0 - • A neat trick for flipping the sign of a two's complement number: flip all the bits (0 becomes 1, or 1 becomes 0) and then add 1 to the least significant bit. • Addition is exactly the same as with an unsigned number. 2.2 Exercises For questions 1-3, answer each one for the case of a two's complement number and an unsigned number, indicating if it cannot be answered with a specific representation. 1. (15 pts) What is the largest integer…

Chapter 10 Solutions

Problem Solving with C++ (9th Edition)

Ch. 10.2 - Below we have redefined the class DayOfYear from...Ch. 10.2 - Given the following class definition, write an...Ch. 10.2 - Prob. 13STECh. 10.2 - The private member function DayOfYear::checkDate...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - Suppose you change Self-Test Exercise 15 so that...Ch. 10.2 - Explain what public: and private: do in a class...Ch. 10.2 - a. How many public: sections are required in a...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - How would you change the definition of the class...Ch. 10.2 - Prob. 24STECh. 10.3 - When you define an ADT as a C++ class, should you...Ch. 10.3 - When you define an ADT as a C++ class, what items...Ch. 10.3 - Suppose your friend defines an ADT as a C++ class...Ch. 10.3 - Redo the three- and two-parameter constructors in...Ch. 10.4 - How does inheritance support code reuse and make...Ch. 10.4 - Can a derived class directly access by name a...Ch. 10.4 - Suppose the class SportsCar is a derived class of...Ch. 10 - Solution to Practice Program 10.1 Redefine...Ch. 10 - Redo your definition of the class CDAccount from...Ch. 10 - Define a class for a type called CounterType. An...Ch. 10 - Write a grading program for a class with the...Ch. 10 - Redo Programming Project 1 (or do it for the first...Ch. 10 - Define a class called Month that is an abstract...Ch. 10 - Redefine the implementation of the class Month...Ch. 10 - My mother always took a little red counter to the...Ch. 10 - Write a rational number class. This problem will...Ch. 10 - Define a class called Odometer that will be used...Ch. 10 - Redo Programming Project 7 from Chapter 5 (or do...Ch. 10 - The U.S. Postal Service printed a bar code on...Ch. 10 - Consider a class Movie that contains information...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY