Question

In: Computer Science

In C++ with comments in code with screenshot In this assignment, you are asked to create...

In C++ with comments in code with screenshot

In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows, (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the amount is more than balance. A function print(), which shall print ”A/C no: xxx Balance=xxx” (e.g., A/C no: 991234 Balance=$88.88), with balance rounded to two decimal places.

When you submit your code, please upload your class code(s) and your test code to prove that your code works correctly.

Solutions

Expert Solution

#include <iostream>
#include <iomanip>
using namespace std;

class Account
{
   private:
   long accountNumber;
   double balance;
  
   public:
   Account(long accountNumber,double balance)// constructor
   {
       this->accountNumber = accountNumber;
       this->balance = balance;
      
   }
   void credit(double amount)
   {
       balance = balance + amount;
   }
   void debit(double amount)
   {
       if(amount > balance)
       cout<<"\nAmount withdrawn exceeds the current balance!"<<endl;
       else
       balance = balance - amount;
      
   }
   void print()
   {
       cout<<fixed<<setprecision(2);
       cout<<"A/C no: "<<accountNumber<<" Balance=$"<<balance;
   }
  
};

int main() {

Account acc(991234,88.88);
acc.print();

acc.credit(55.30);
acc.debit(155.67);
acc.print();


   return 0;
}

output:

A/C no: 991234  Balance=$88.88
Amount withdrawn exceeds the current balance!
A/C no: 991234  Balance=$144.18

Do ask if any doubt. Please upvote.


Related Solutions

C++ ONLY -- PRACTICE ASSIGNMENT We are given a code (Driver.cpp) and asked to create a...
C++ ONLY -- PRACTICE ASSIGNMENT We are given a code (Driver.cpp) and asked to create a file (StringStack.h) and turn it in. What should the code for StringStack.h look like based on the instructions below? Download Driver.cpp Create a class named StringStack in a file named StringStack.h. Create a ListNode structure as a private member of the class. The node should be able to hold a string called value.   Create a top pointer as private attributes of the class. (this...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
Needed in C++ In this assignment, you are asked to create a class called Account, which...
Needed in C++ In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the...
C programming assignment. instructions are given below and please edit this code only. also include screenshot...
C programming assignment. instructions are given below and please edit this code only. also include screenshot of the output //In this assignment, we write code to convert decimal integers into hexadecimal numbers //We pratice using arrays in this assignment #include <stdio.h> #include <stdlib.h> #include <assert.h> //convert the decimal integer d to hexadecimal, the result is stored in hex[] void dec_hex(int d, char hex[]) {    char digits[] ={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',   ...
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class....
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class. The class will have the following data members, const int size = 100; int no_of_products; // the total number of products in the inventory. char name_array[size][15] ; // stores name of products double array [size][2]; // In the first column quantity of the product and in the second column the price per item of the product is stored. name_array stores the name of products,...
This assignment provides you with an opportunity to create a code of ethics for you and...
This assignment provides you with an opportunity to create a code of ethics for you and your family, as well as to explain the strategies and thought processes that went into developing the code. First, create an original code of ethics for your family by thinking about your family as an organization. In your code of ethics, please include the following items:  guiding principles,  purpose of the code,  core values,  training and education (How will you...
n this assignment you will create your own blog topic and post three comments that you...
n this assignment you will create your own blog topic and post three comments that you believe would be relevant to this topic and generate replies from others if the blog were to be published online. Include the following in your paper: Choose a topic that you wish to create a blog about. This may be a product, service, idea, cause, etc., that you know something about and wish to discuss. Describe the topic before preparing the blog entry. Prepare...
In this assignment, you are given partial code and asked to finish the rest according to...
In this assignment, you are given partial code and asked to finish the rest according to the specified requirement. Problem statement: one benefit of inheritance is the code reuse. Instead of writing everything from scratch, you can write a child class that reuse all the features already existed in its parent, grandparent, great grandparent, etc. In the child class, you only need to supply small amount of code that makes it unique. In the following, you are given code for...
C++ program to read line comments. This assignment will give you a little bit of practice...
C++ program to read line comments. This assignment will give you a little bit of practice with string parsing. Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment. You do not have to worry about /* multiline comments */ though there will be a small amount of extra credit for programs that correctly extract these comments as well.
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT