Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
Using C++: Write a program that creates a Bus class that includes a bus ID number, number of seats, driver name, and current speed. Create a default constructor without any parameters that initializes the value of ID number, number of seats, and driver name. Create another constructor with three parameters of bus id number, number of seats, and driver name. Car speed should always be initialized as 0. The program will also include the member functions to perform the various operations: modify, set, and display bus information (Bus id, number of seats, driver name, and current speed). For example:- Set the bus id number- Set the number of seats- Set of driver number----------------------------------------------------- Return the bus id number by using get method- Return the number of seats- Return of driver number- Return the current speed-----------------------Member function to display the bus information- busInformation() Also write two member functions, Accelerate() and Brake().…
Language: C++ Create a class named City. Assume that a city has a name, a number of inhabitants, a mayor and an area (in km²). Then create three instances of this class: Bremen, Paris and London. Provide suitable setter and getter methods for each of these properties. The class declaration has to be placed into City.h, the class definition has to be placed into City.cpp and the test program where the instances are created has to be in testcity.cpp. You can set the needed data from the main () function by initialization or read it from the key- board.
Write a c++ program and explain with comments Create a class called Employee that includes attributes: empid, name, points, group, and avg with data types: “int”, “String”, “double”, “String”, and “double” respectively. Include a constructor with parameters: empid and name. Include another constructor to assign default values to the attributes. Include a function called addPoints that is used to add a given amount to the value of the attribute points. Include a function called upgradePoints that is used to increase the value of theattribute points by a given percentage. Include a function called removePoints that is used to reduce a given amount fromthe value of the attribute points. If the resultant value is negative then the value of the attribute should be set into zero. Include a function called computeGroup that assigns a value to the attribute groupbased on the value of the attribute points as given in the following table. Points Group points < 100 Silver 100…

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

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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