QuestionQuestion

Part I

Date Class:
Design and Implement a class called Date that has data members to store month (as a number), day, year, and name of the month. The class should have a three-­‐parameter constructor that allows the data to be set at the time of new Data object instances are created. Default constructor that does not take any parameters should set the default values of 1 (month), 1 (day), 2001 (year). The class should have following three member functions to display date following formats
showDate1() should display the date in 1/1/2001 format showDate2() should display the date in January 1, 2001 format showDate3() should display the date in 1 January 2001 format
Also the class should have method to set the date (setDate()). This method should take month, day, and year as parameters and set the object instance data member values.

1/1/2001
February 12, 2010

29 August 1986

#include <iostream>
using namespace std;
#include "Date.h"
int main()
{
Date d1;
Date d2(2, 12, 2010);

d1.showDate1(); d2.showDate2();

d1.setDate(8, 29, 1986); d1.showDate3(); system("pause");
return 0;
}

Part 2
Write a class that simulates managing a simple bank account. The account is created with an initial balance. It is possible to deposit and withdraw funds, to add interest, and to find out the current balance. This should be implemented in class named Account that includes:
• A default constructor that sets the initial balance to zero.
• A constructor that accepts the initial balance as a parameter.
• A function getBalance that returns the current balance.
• A method deposit for depositing a specified amount.
• A method withdraw for withdrawing a specified amount.
• A method addInterest for adding interest to the account.
The addInterest method takes the interest rate as a parameter and changes the balance in the account to balance*(1+interestRate).

The UML diagram for the Account class is shown here:
Account
-balance: double
+Account();
+Account(double);
+double getBalance();
+void deposit(double );
+void withdraw(double);
+void addInterest(double);

Your class must work with the code given below and display the output . 240
450

#include<iostream>    
using namespace std;
#include "Account.h"    
int main()    
{    
Account a1;    
Account a2(500);    
a1.depost(200);    
a2.withdraw(50);                
a1.addInterest(0.2);    
cout<<a1.getBalance();    
cout<<"\n";    
cout<<a2.getBalance();    
system("pause");    
return 0;    
}

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "Date.h"

Date::Date() {
    setDate(1, 1, 2001);
}

Date::Date(int day, int month, int year) {
    setDate(day, month, year);
}


Date::~Date() {
}

void Date::setDate(int day, int month, int year) {
// set all integer value
    this->day = day;
    this->month = month;
    this->year = year;
   
    // choose name of month form the list
    switch(month){
       case 1:
            monthName = "January";
            break;
       case 2:
            monthName = "February";
            break;
       case 3:
            monthName = "March";
            break;
       case 4:
            monthName = "April";
            break;
       case 5:
            monthName = "May";
            break;
       case 6:
            monthName = "June";
            break;
       case 7:
            monthName = "July";
            break;
       case 8:
            monthName = "August";
            break;
       case 9:
            monthName = "September";
            break;
       case 10:
            monthName = "October";
            break;
       case 11:
            monthName = "November";
            break;
       default:
            monthName = "December";
    }
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats