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
Problem Statement You are working as a Devops Administrator. Y ou’ve been t asked to deploy a multi - tier application on Kubernetes Cluster. The application is a NodeJS application available on Docker Hub with the following name: d evopsedu/emp loyee This Node JS application works with a mongo database. MongoDB image is available on D ockerHub with the following name: m ongo You are required to deploy this application on Kubernetes: • NodeJS is available on port 8888 in the container and will be reaching out to por t 27017 for mongo database connection • MongoDB will be accepting connections on port 27017 You must deploy this application using the CL I . Once your application is up and running, ensure you can add an employee from the NodeJS application and verify by going to Get Employee page and retrieving your input. Hint: Name the Mongo DB Service and deployment, specifically as “mongo”.
I need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergent
I need help in my server client in C language

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
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