Question

*using c++* Construct a class named Savings containing three floating-point data members named balance, rate, and...

*using c++*

Construct a class named Savings containing three floating-point data members named balance, rate, and interest and a constructor that initializes each data member to 0. This class should be established with typical two files(.h and .cpp). Include a member function that inputs a balance and rate and then calculates an interest. The rate should be stored as a   percent, such   as   6.5   for   6.5%,   and   the   interest   is   computed   as   interest   = (balance)(rate/100). Add a member function to display all data member values. Use functions in main(), and display the results.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Savinqs.h:

#ifndef Savings_H_
#define Savings_H_

class Savings {
private:
   float balance;
   float rate;
   float interest;
public:
   Savings();
   void inputBalance();
   float getInterest();
};

#endif

Savings.cpp:

#include "Savings.h"

#include <iostream>

using namespace std;

Savings::Savings() {
   balance = 0;
   rate = 0;
   interest = 0;
}

void Savings::inputBalance() {
   cin >> balance >> rate;
   interest = balance * (rate / 100.0);
}

float Savings::getInterest() {
   return interest;
}

main.cpp:

#include <iostream>
#include "Savings.h"

using namespace std;

int main() {
   Savings s;
   s.inputBalance();
   cout << "Interest: " << s.getInterest() << endl;
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
*using c++* Construct a class named Savings containing three floating-point data members named balance, rate, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • Construct a class named Fractions containing two integer data members named num and denom, used to...

    Construct a class named Fractions containing two integer data members named num and denom, used to store the numerator and denominator of a fraction having the form num/denom. Your class should include a default constructor that initializes num and denom to 1 if there's no user initialization, and it must prohibit a 0 denominator value. In addition, create member functions for displaying an object's data values and overloaded operator functions for adding, subtracting, multiplying, and dividing two Fraction objects, as...

  • Construct a class named Room that declares two double-precision data members named length and width (2...

    Construct a class named Room that declares two double-precision data members named length and width (2 points). Include a constructor that initializes each data member to 1.0 when a Room object is created (1 point). Add two accessor functions for displaying the length and width values of a Room object and two mutator functions that allow changing these data member values. (2 points) Write a program that tests all functionality of this class. (3 points) Extra Credit: Create this class...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • a. construct a class named room that declares two-double precision data members named length and width....

    a. construct a class named room that declares two-double precision data members named length and width. include a constructor that initializes each datavmember to 1.0 when a room object is created. add two accessor funtions for displaying the length and width values of a room object and two mutator functions that allow changing these data member values. b. include the class written for 6a in the context of a complete program

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • C++ design a class named Technician that contains private data members to store the following: -technician's...

    C++ design a class named Technician that contains private data members to store the following: -technician's name (a string) - number of service calls - total time of all service calls - average service call time the technician class should also have the following public member functions: - a constructor function that initializes all data members by obtaining their values from the users. with the exception of the average service call time which will be calculated as: total_time/number_of_call - a...

  • c ++ Create a class Book with the data members listed below.     title, which is...

    c ++ Create a class Book with the data members listed below.     title, which is a string (initialize to empty string)     sales, which is a floating point value (as a double, initialize to 0.0) Include the following member functions:     Include a default constructor,     a constructor with parameters for each data member (in the order given above),     getters and setter methods for each data member named in camel-case. For example, if a class had a data...

  • C++ IJU U Construct a user-defined object class named Bug that models a bug moving along...

    C++ IJU U Construct a user-defined object class named Bug that models a bug moving along a horizon- tal line. The bug moves either to the right or left. Initially, the bug moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. The Bug class will have data members position (type int) for the bug's position on the horizontal line and dir (type int) for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT