Question

In: Computer Science

......C++ PROGRAM.... Teacher would like us to split this program into a header file(filename.h), and a...

......C++ PROGRAM....

Teacher would like us to split this program into a header file(filename.h), and a .cpp file(filename.cpp). He gave us all the code, we just need to split it up. I do not quite understand how to do it. Please send output screenshot to show validation.

#include <iostream>

using namespace std;

//public class

class Account{

public:

//instance variables

double amount;

  

//creates account and sets amount with users account set-up value

Account(double a){

amount = a;

}

  

//adds to amount in account once deposited

void deposit(double a){

if(a < 0){

return;

}

amount += a;

}

  

//decreases amount in account once withdrawn

void withdraw(double a){

if(amount-a < 0){

return;

}

amount -= a;

}

  

//returns balance of account

double get_balance(){

return amount;

}

};

int main()

{

Account my_account(100); // Set up my account with $100

my_account.deposit(50);

my_account.withdraw(175); // Penalty of $20 will apply

my_account.withdraw(25);

  

cout << "Account balance: " << my_account.get_balance() << "\n";

my_account.withdraw(my_account.get_balance()); // withdraw all

cout << "Account balance: " << my_account.get_balance() << "\n";

return 0;

}

Solutions

Expert Solution

Account.h file:

#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
using namespace std;
class Account
{
public:
double amount;
Account(double a);
void deposit(double a);
void withdraw(double a);
double get_balance();
};

#endif // ACCOUNT_H

Account.cpp file:

#include "Account.h"

Account::Account(double a){
amount = a;
}
void Account::deposit(double a){
if(a < 0){
return;
}
amount += a;
}
void Account::withdraw(double a){
if(amount-a < 0){
return;
}
amount -= a;
}
double Account::get_balance(){
return amount;
}

Main file:

#include "Account.h"
int main()
{
Account my_account(100); // Set up my account with $100
my_account.deposit(50);
my_account.withdraw(175); // Penalty of $20 will apply
my_account.withdraw(25);

cout << "Account balance: " << my_account.get_balance() << "\n";
my_account.withdraw(my_account.get_balance()); // withdraw all
cout << "Account balance: " << my_account.get_balance() << "\n";
return 0;
}

VALIDATION:

ACCOUNT.H FILE

ACCOUNT.CPP

MAIN FILE

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP


Related Solutions

Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain code and output screenshots. Please use Bubble Sort code provided. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define FUNCTIONS_H typedef struct MyStruct { int value; char name[ 100 ]; } MyStruct; void sortArray( MyStruct*, int ); void printArray( MyStruct*, int ); #endif Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) {      float           f;      Linked_List *theList;      cout << "Simple List Demonstration\n";      cout << "(List implemented as an Array - Do...
A header file contains a class template, and in that class there is a C++ string...
A header file contains a class template, and in that class there is a C++ string object. Group of answer choices(Pick one) 1)There should be a #include for the string library AND a using namespace std; in the header file. 2)There should be a #include for the string library. 3)There should be a #include for the string library AND a using namespace std; in the main program's CPP file, written before the H file's include.
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork class. The features of an ArtWork are: Artist name (e.g. Vincent vanGogh or Stan Getz) Medium (e.g. oil painting or music composition) Name of piece (e.g. Starry Night or Late night blues) Year (e.g. 1837 or 1958)
You would like to determine if teacher A gives different grades from teacher B in the...
You would like to determine if teacher A gives different grades from teacher B in the same class at a significance level of 0.01. You take a random sample of 85 students from teacher A, 61 of whom passed the class. You also take a random sample of 70 students from teacher B, 56 of whom passed the class. a) What is the estimate of the difference in proportion of students who pass? Find the estimate of pA − pB....
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library....
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library. Your C code //SHOULD access your routines using these exact function // prototypes typedef struct RW_lock_s { } RW_lock_t; void RW_lock_init(RW_lock_t *lock); /* This routine should be called on a pointer to a struct variable of RW_lock_t to initialize it and ready it for use. */ void RW_read_lock(RW_lock_t *lock); /* This routine should be called at the beginning of a READER critical section */...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT