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
Write a program to display the given details with the normal constructor and the copy constructor.Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.The class Course has the following public data members.  Data Type Variable Name string course_name string    sessionname1 string     sessionname2 string     sessionname3 Define a constructor with parameters passed in the same order as declared in the class and create a copy constructor that replicates the course. Include the following method inside the Course class Method Member Function void display() This method is used to display all the details of the course In the main() method, obtain input from the user in the console and display the details of a normal constructor and a copy constructor using the display() method.Input and Output Format:Refer to the…
Q1) Write the Code the following scenario. Write an abstract function named receivePay in interface with return type double and no parameters. Write another incomplete function, name Show with return type void and an argument of type int in that interface. Build a class with name Bill that implements the above interface. Bill class with name BillId , itemsquantity and itemsprice with proper datatypes with private access . Define two constructors,one default and other is parameterized to initialize the class members . Now receivePay has to beimplemented in such a way that its displays product of itemsquantity and itemsprice and Display function will display the BillId.Can we do same task with abstract class instead of interface? NOTE:SUBJECT:CSHARP (VISUAL PROGRAMMING)
This lab will exercise your understanding of some of the concepts covered in Chapter 13:overloading operators   1. Create a class, name of your choice, to represent a college class in which students might register. a. Create three private member variables:Class Name (to hold values such as CSC210)Number of StudentsClass Hours b. Overload the >> operator to input, from cin, into the class object, the Class Name and Class Hours c. Overload the << operator to output all the private member variables d. Overload the + (plus) operator to add a value to the Number of Students private member variable.This will represent students registering for the class. e. Overload the - (minus) operator to subtract a value from the Number of Studentsprivate member variable. This will represent students dropping the class. f. The default constructor should initialize the private member variables appropriately. 2. Write a client program to: a. Upon program execution, create one class object that…

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