Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code that uses polymorphism to make printing out similar objects using their appro- priate attributes. The program will prompt the user to input as

Write code that uses polymorphism to make printing out similar objects using their appro- priate attributes. The program will prompt the user to input as many cards as desired, including driver license, passports, library cards, university ID cards, bank cards, and credit cards. It will then print all the cards in ascending order of expiration date, such that the cards that expire the soonest are printed first, and those without expiration date are printed last.

To do this, consider all cards belong to three main categories: basic cards, ID cards, and bank cards. Basic cards only contain the name of the institution, the name of the person, and sometimes an expiration date. ID cards such as your driver license or passport number can also contain an ID number and date of birth (DOB). Bank cards contain an account number and a card security code number.

Create a base class Card as well as derived classes IDCard and BankCard with data fields as explained above. Write any necessary member functions and non-member functions such that your program prompts the user to input as many cards as desired and then prints them all in order of expiration date. Follow the format shown in the output sample exactly and abide by good coding practices. Figure 1 shows a sample output.

image text in transcribed

The main problem I am having is ordering the class information by expiration date. I am storing all the class information in a vector of type pointer to card. Here is a snippet of my main function

vector vect;

int card_type;

Card* pCard;

Card test;

do

{

cout

cin >> card_type;

cout

if (card_type == 1)

{

pCard = new Card;

}

else if (card_type == 2)

{

pCard = new IDCard;

}

else if (card_type == 3)

{

pCard = new BankCard;

}

else if (card_type == 0) break;

else

{

cout

continue;

}

pCard->read();

vect.push_back(pCard);

}

while (card_type != 0);

If you could please show me how to order the VECTOR according to the expiration date that would be great! Thank you.

* Wallet Printer! * Print Cards by selecting the type (e when done) 1. Basic Card 2. ID Card 3. Bank Card Card Type : 3 | LIBRARY CARD name : Andrew Tzuo exp : 03/28/2017 Institution name : BANK OF AMERICA Card holder name : Jane Baker Expiration date muddyyy (@ if none) : 88282823 Account number : 3456478310001 Card Security Code : 353 | CHASE name : Jane Baker exp : 03/25/2822 Card Type : 1 | Account# : 907929020294 CSC: 749 Institution name : UCLA Card holder name : Andrew Tzuo Expiration date muddyyy (@ if none) : 8 Card Type : 2 | BANK OF AMERICA name : Jane Baker exp : 08/28/2823 Institution name : UCLA BRUIN CARD Card holder name : Ashley Phillips Expiration date muddyyy (@ if none) : 0 ID number : 352573968 DOB maddyyy (@ if not listed) : 0 | Account# : 3456478310001 CSC : 353 Card Type : 1 | UCLA name : Andrew Tzuo exp : N/A. Institution name : LIBRARY CARD Card holder name : Andrew Tzuo Expiration date muddyyy (@ if none) : 03282017 Card Type : 3 | UCLA BRUIN CARD name : Ashley Phillips exp : N/A. Institution name : CHASE Card holder name : Jane Baker Expiration date muddyyy (@ if none) : 83252822 Account number : 907929020294 Card Security Code : 749 ID# : 352573968 DOB : N/A

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_2

Step: 3

blur-text-image_3

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions