Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement in C sharp, Create a class Account that should include one private ins

ID: 3592526 • Letter: I

Question

Implement in C sharp, Create a class Account that should include one private instance variable Balance of type decimal to represent the account balance. The class should provide a constructor that receives an initial balance via its parameter and uses it to initialize the instance variable Balance. The class should have a public property BalanceP with a set accessor and a get accessor. When setting the account balance, the set accessor should validate the balance to ensure that it’s greater than or equal to 0.0. If not, give an error message and set the balance to 0.0. The get accessor of the property BalanceP returns the current balance. The class should provide two public methods. Method Creditshould add an amount to the current balance. Method Debit should withdraw money from the account and ensure that the debit amount does not exceed the account’s balance. If it does, the balance should be left unchanged, and the method should display the message "Debit amount exceeded account balance."

Create a derived class CheckingAccount that inherits from the base class Account created in part1. and include a decimal instance variable Fee that represents the fee charged per transaction. CheckingAccount’s constructor should receive the initial balance and fee amount via its parameters. Class CheckingAccount should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully.However, CheckingAccount’s Debit method should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Hint: applying the technique "virtual and overide" to Credit and Debit method.] After defining the class, create a class CheckingAccountTest that creates an instance of the class CheckingAccount and tests the methods of the class CheckingAccount. That is, the instance will show the initial balance, deposit some money, show the updated balance, withdraw some money, and show the updated balance.

Explanation / Answer

#include<fstream>

#include<iostream>

#include<iomanip>

using namespace std;

class payroll{

ifstream fin;

char employeeid[12];

char employeename[20];

char maritalstatus;

int hoursworked,overtime;

double hourlyrate,overtimepay,regularpay,grosspay,taxrate,taxamount,netpay;

void calculategrosspay();

void calculatetax();

void calculatenetpay();

void printheadings();

void printdata();

public:payroll();

~payroll();

void printreport(); };

payroll::payroll(){

fin.open("payroll.dat"); }//CONSTRUCTOR

payroll::~payroll(){

fin.close(); }//DECONSTRUCTOR

void payroll::calculategrosspay(){

if(hoursworked>40){

overtime=hoursworked-40;

regularpay=hoursworked*hourlyrate;

overtimepay=overtime*(hourlyrate*1.5);

grosspay=regularpay+overtimepay; }//IF

else grosspay=hoursworked*hourlyrate; }//CALCULATEGROSSPAY

void payroll::calculatetax(){

if(grosspay>=500)taxrate=.30;

else if(grosspay>200)taxrate=.20;

else taxrate=.10;

if(maritalstatus=='S'||maritalstatus=='s')

taxrate=taxrate+.05;

taxamount=grosspay*taxrate;}//CALCULATETAX

void payroll::calculatenetpay(){

netpay=grosspay-taxamount;}//CALCULATENETPAY

void payroll::printheadings(){

cout<<setw(45)<<"-PAYROLL REPORT-"<<endl;

cout<<"-----------------------------------"<<endl;

cout<<"NAME ID HW OT RT-PAY OT-PAY GROSS TAX NET"<<endl;

cout<<"------------------------------------------------"<<endl;

}//PRINTHEADINGS

void payroll::printdata(){

cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);

cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)<<hoursworked

<<setw(3)<<overtime<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)

<<grosspay<<setw(8)<<taxamount<<setw(8)<<netpay<<endl; }//PRINTDATA

void payroll::printreport(){

int i=0;

printheadings();

while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){

calculategrosspay();

calculatetax();

calculatenetpay();

printdata();

i++; }//WHILE

}//PRINTREPORT

int main(){

payroll employee;

employee.printreport();

return 0;

}//MAIN

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote