Question

Code the following Program in C++ Define a class named Payment that contains a member variable...

Code the following Program in C++

Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods.   

Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment.

Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s).

Define a class named CreditCardPayment that is derived from Payment. This class should contain member variables for the name on the card, expiration date, and credit card number.   Include appropriate constructor(s). Finally, redefine the paymentDetails function to include all credit card information in the printout.

Create a main method that creates at least two CashPayment and two CreditCardPayment objects with different values and calls paymentDetails for each.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code -


#include <iostream>

using namespace std;
//class paymeth
class Payment{
//variable delcare
public:
float amountOfPayment;
//paymentDetails function
void paymentDetails(){
cout<<"Amount of payment "<<getAmountPayment()<<endl;
}
//getter for amount
float getAmountPayment(){
return amountOfPayment;
}
//setter for amount
void setAmountPayment(float amount){
amountOfPayment = amount;
}
  
};
//class CashPayment inherits Payment class
class CashPayment : public Payment{
//constructor CashPayment
public:
CashPayment(float amount){
amountOfPayment = amount;
}
//override paymentDetails function
void paymentDetails(){
cout<<"Amount paid as cash is "<<amountOfPayment<<endl;
}
};
//class CreditCardPayment inherits Payment class
class CreditCardPayment : public Payment{
//variable declare
string name , expiryDate,creditCardNumber;
//constructor credit card class
public:
CreditCardPayment(string nameCard,string expiry,string cardNo,float amount){
name = nameCard;
expiryDate = expiry;
creditCardNumber = cardNo;
amountOfPayment = amount;
}
// paymentDetails function
void paymentDetails(){
cout<<"Name on card "<<name<<" Expiry date "<<expiryDate<<" Card number "<<creditCardNumber<<" Amount due "<<amountOfPayment<<endl;
}
};

int main()
{
//Payment class object
Payment p1;
//setter method
p1.setAmountPayment(2500);
//print payment
p1.paymentDetails();
//CashPayment object first
CashPayment c1(3000);
//paymentDetails print
c1.paymentDetails();
//CashPayment object second
CashPayment c2(5000);
c2.paymentDetails();
//CreditCardPayment object first
CreditCardPayment cc1("John","22-12-2021","123456789",5343);
cc1.paymentDetails();
//CreditCardPayment object first
CreditCardPayment cc2("Bryan","10-2-2022","987654321",1234);
cc2.paymentDetails();
return 0;
}

Screenshots -

pls do give a like , thank you

Add a comment
Know the answer?
Add Answer to:
Code the following Program in C++ Define a class named Payment that contains a member variable...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • 7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables...

    7. PersonData and CustomerData classes Design a class  named PersonData with the following member variables : lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables . Next, design a class  named CustomerData, which is derived from the PersonData class . The CustomerData class should have the following member variables : customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool....

  • 7. PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...

    7. PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailinglist The customer Number variable will be used to hold a unique integer for each customer. The mailing List variable should be a bool....

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • C++ In the code cell below, define a class named Student with an integer id and...

    C++ In the code cell below, define a class named Student with an integer id and a string name. This class should have a constructor that takes two arguments: one for the id and the other for the name. Then Create another class named CollegeStudent that publicly inherits from Student. This class should have a protected member named major. It should also have a constructor that takes three arguments: id, name, and major. This constructor should delegate initializing the id...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT