Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: 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
S A B D FL I C J E G H T K L Figure 1: Search tree 1. Uninformed search algorithms (6 points) Based on the search tree in Figure 1, provide the trace to find a path from the start node S to a goal node T for the following three uninformed search algorithms. When a node has multiple successors, use the left-to-right convention. a. Depth first search (2 points) b. Breadth first search (2 points) c. Iterative deepening search (2 points)
We want to get an idea of how many tickets we have and what our issues are. Print the ticket ID number, ticket description, ticket priority, ticket status, and, if the information is available, employee first name assigned to it for our records. Include all tickets regardless of whether they have been assigned to an employee or not. Sort it alphabetically by ticket status, and then numerically by ticket ID, with the lower ticket IDs on top.
Figure 1 shows an ASM chart representing the operation of a controller. Stateassignments for each state are indicated in square brackets for [Q1, Q0].Using the ASM design technique:(a) Produce a State Transition Table from the ASM Chart in Figure 1.(b) Extract minimised Boolean expressions from your state transition tablefor Q1, Q0, DISPATCH and REJECT. Show all your working.(c) Implement your design using AND/OR/NOT logic gates and risingedgetriggered D-type Flip Flops. Your answer should include a circuitschematic.

Chapter 10 Solutions

Problem Solving with C++ (10th 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