Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been provided with the files already and I posted them as well, just need to add constructors. and make the correct output. /*********************

I have been provided with the files already and I posted them as well, just need to add constructors. and make the correct output.

image text in transcribedimage text in transcribed

/*********************

* File: check05b.cpp

*********************/

// You should not change anything in this file

#include

using namespace std;

#include "money.h"

/****************************************************************

* Function: main

* Purpose: Test the money class

****************************************************************/

int main()

{

int dollars;

int cents;

cout

cin >> dollars;

cout

cin >> cents;

Money m1;

Money m2(dollars);

Money m3(dollars, cents);

cout

m1.display();

cout

cout

m2.display();

cout

cout

m3.display();

cout

return 0;

}

/***********************

* File: money.cpp

***********************/

#include

#include

using namespace std;

#include "money.h"

/*****************************************************************

* Function: prompt

* Purpose: Asks the user for values for dollars and cents

* and stores them.

****************************************************************/

void Money :: prompt()

{

int dollars;

int cents;

cout

cin >> dollars;

cout

cin >> cents;

setDollars(dollars);

setCents(cents);

}

/*****************************************************************

* Function: display

* Purpose: Displays the value of the money object.

****************************************************************/

void Money :: display() const

{

cout

cout

}

int Money::getDollars() const

{

return dollars;

}

int Money::getCents() const

{

return cents;

}

void Money::setDollars(int d)

{

if(d

dollars=-d;

else

dollars=d;

}

void Money::setCents(int c)

{

if(c

cents=-c;

else

cents=c;

}

/******************

* File: money.h

******************/

#ifndef MONEY_H

#define MONEY_H

#include

using namespace std;

class Money

{

private:

int dollars;

int cents;

public:

void prompt();

void display() const;

int getDollars()const;

int getCents()const;

void setDollars(int d);

void setCents(int c);

};

#endif

Overview This checkpoint is intended to help you practice the syntax of constructors. It will build upon the class you created in Checkpoint 05a Instructions Add a default and a non-default constuctor the Money class from Checkpoint 05a. 1. While you will use the money class from Checkpoint 05a, you will use a new "main" function. Copy over the file check05b.cpp and a corresponding makefile to start with: mkdir check05b cd check05b cp /home/cs165new/check05b/* 2. Now, copy over your money.h and money.cpp files from last time. Assuming you have your code from last time in a directory called "check05a" and that you are now in the "check05b" directory: cp./check05a/money.* . 3. Please note that this code does not compile at this point. You need to add code to make it compile 4. Add the following constructors: -Default - Set the values to 0. Non-default that accepts 1 integer - Sets the dollar amount to that integer, sets the cents to O Non-default that accepts 2 integers -Sets the dollar amount to the first, and the cents to the second. 5. Don't forget to use your setters so that you will get any error checking they do for free. 6. You should not change anything in main (or your functions from last time). All you need to do is add the contructors. 7. Don't forget to add your information to the makefile before tar-ing, and submitting

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

Students also viewed these Databases questions