
Concept explainers
Explanation of Solution
Program code:
main.cpp
//include the requird header files
#include <
#include "CreditCard.h"
//use the namespace
using namespace std;
//define the function textCard()
void testCard()
{
// vector of CC pointers
vector <CreditCard*> wallet(10);
//create the credit card details
wallet[0] = new CreditCard(5391037593875309,"JoBlo",2500);
wallet[1] = new CreditCard(3485039933951954,"JoBlo",3500);
wallet[2] = new CreditCard(6011490232942994,"JoBlo",5000);
//iterate a for loop
for (int j = 1; j <= 16; j++)
{
// explicit cast
wallet[0] -> chargeIt(double(j));
// implicit cast
wallet[1] -> chargeIt(2 * j);
wallet[2] -> chargeIt(double(3 * j));
}
//iterate a for loop
for (int i = 0; i < 3; i++)
{
//print the card details
cout << *wallet[i];
//iterate a while loop to get the balance
while (wallet[i]->getBalance() > 100.0)
{
//call the method makePayment
wallet[i]->makePayment(100.0);
//print the new balance
cout << "New balance = " <<
wallet[i]->getBalance() << "\n";
}
//deleting a walllet
delete wallet[i];
}
}
//define the main() method
int main()
{
//First test case
CreditCard CC = CreditCard(1234, "Bill gates", 2500);
CC.chargeIt(1000);
CC.chargeIt(-100);
CC.chargeIt(500);
CC.makePayment(-100);
CC.makePayment(300);
cout << CC << endl << endl;
//given test case
testCard();
return EXIT_SUCCESS;
}
Explanation:
In the code,
- Include the required header files.
- Use the namespace.
- Define the “testCard()” method.
- Create vector pointers
- Create array “wallet[]” to store credit card details.
- Iterate a “for” loop.
- Explicit cast.
- Implicit cast.
- Iterate a “for” loop.
- Print the card details.
- Iterate a “while” loop to get the balance.
- Call the method “makepayment()”.
- Print the new balance.
- Delete a wallet.
- Define the “main()” function.
- Enter the credit card details.
- Call the function “chargeIt()” and “makePayment()” using “CC”.
- Call the function “testCard()”.
- Return “EXIT_SUCCESS”.
CreditCard.cpp
//Code for CreditCard.cpp
#include "CreditCard.h"
using namespace std;
//define the constructor CreditCard
CreditCard::CreditCard(long long int no, const string& nm, int lim, double bal)
{
//declare the required variables
number = no;
name = nm;
limit = lim;
balance = bal;
}
//define a function chargeIt()
bool CreditCard::chargeIt(double price)
{
if(price <= 0)
{
//print error message when price is negative
cout << "Error: Input argument must be positive.\n";
//return false
return false;
}
//if the condition is true
if (price + balance > double(limit))
{
//return false
return false;
}
//add price to balance
balance += price;
//update fraction
fraction = double(balance)*100.0/limit;
//if the condition is true
if(fraction > FRACTION_LIMIT)
{
//print warning message when fraction is more than 50%
printf("Warning: the current balance on credit card %lld is %.2f%c of your limit.\n", number, fraction, '%');
}
// the charge goes through
return true;
}
//define the function makePayment
void CreditCard::makePayment(double amount)
{
//if amount less than or equal to 0
if(amount <= 0)
{
//print error message when amount is negative
cout << "Error: Input argument must be positive...

Want to see the full answer?
Check out a sample textbook solution
Chapter 1 Solutions
Data structures and algorithms in C++
- Please answer the homework scenario below and make a JAVA OOP code. You have been hired by GMU to create and manage their course registration portal. Your first task is to develop a program that will create and track different courses in the portal. Each course has the following properties: • a course number ex. IT 106, IT 206, • A course description, ex. Intro to Programming • Total credit hour ex. 3.0, and • current enrollment ex. 30 Each course must have at least a course number and credit hours. The maximum enrollment for each course is 40 students. The current enrollment should be no greater than the maximum enrollment. A course can have a maximum of 4 credit hour. The DDC should calculate the number of seats remaining for the course. Design an object-oriented solution to create a data definition class for the course object. The course class must define all the constructors, mutators with proper validation, accessors, and special purpose methods. The DDC should calculate the…arrow_forwardFor this case study, students will analyze the ethical considerations surrounding artificial intelligence and big data in healthcare, as explored in the case study found in the textbook (pages 34-36) and in the extended version available here There will also be additional articles in this weeks learning module to show both sides of the coin. https://www.delftdesignforvalues.nl/wp-content/uploads/2018/03/Saving-the-life-of-medical-ethics-in-the-age-of-AI-and-Big-Data.pdf Students should refer to the syllabus for specific guidelines regarding length, format, and content requirements. Reflection Questions to Consider: What are the key ethical dilemmas presented in the case? How does AI challenge traditional medical ethics principles such as autonomy, beneficence, and confidentiality? In what ways can responsible innovation help address moral overload in healthcare decision-making? What are the potential risks and benefits of integrating AI-driven decision-making into patient care?…arrow_forwardCan you please solve this. Thanksarrow_forward
- can you solve this pleasearrow_forwardIn the previous homework scenario problem below: You have been hired by TechCo to create and manage their employee training portal. Your first task is to develop a program that will create and track different training sessions in the portal. Each training session has the following properties: • A session ID (e.g., "TECH101", "TECH205") • A session title (e.g., "Machine learning", "Advanced Java Programming") • A total duration in hours (e.g., 5.0, 8.0) • Current number of participants (e.g., 25) Each session must have at least a session ID and a total duration and must met the following requirements: • The maximum participant for each session is 30. • The total duration of a session must not exceed 10 hours. • The current number of participants should never exceed the maximum number of participants. Design an object-oriented solution to create a data definition class(DDC) and an implementation class for the session object. In the DDC, a session class must include: • Constructors to…arrow_forwardIn the previous homework scenario problem below: You have been hired by TechCo to create and manage their employee training portal. Your first task is to develop a program that will create and track different training sessions in the portal. Each training session has the following properties: • A session ID (e.g., "TECH101", "TECH205") • A session title (e.g., "Machine learning", "Advanced Java Programming") • A total duration in hours (e.g., 5.0, 8.0) • Current number of participants (e.g., 25) Each session must have at least a session ID and a total duration and must met the following requirements: • The maximum participant for each session is 30. • The total duration of a session must not exceed 10 hours. • The current number of participants should never exceed the maximum number of participants. Design an object-oriented solution to create a data definition class(DDC) and an implementation class for the session object. In the DDC, a session class must include: • Constructors to…arrow_forward
- Send me the lexer and parserarrow_forwardHere is my code please draw a transition diagram and nfa on paper public class Lexer { private static final char EOF = 0; private static final int BUFFER_SIZE = 10; private Parser yyparser; // parent parser object private java.io.Reader reader; // input stream public int lineno; // line number public int column; // column // Double buffering implementation private char[] buffer1; private char[] buffer2; private boolean usingBuffer1; private int currentPos; private int bufferLength; private boolean endReached; // Keywords private static final String[] keywords = { "int", "print", "if", "else", "while", "void" }; public Lexer(java.io.Reader reader, Parser yyparser) throws Exception { this.reader = reader; this.yyparser = yyparser; this.lineno = 1; this.column = 0; // Initialize double buffering buffer1 = new char[BUFFER_SIZE]; buffer2 = new char[BUFFER_SIZE]; usingBuffer1 = true; currentPos = 0; bufferLength = 0; endReached = false; // Initial buffer fill fillBuffer(); } private…arrow_forwardIf integer x is divisible by 3, can you prove that ceil(x/2) + floor(x/6) = floor(x/2) + ceil(x/6)arrow_forward
- Draw the NFA for thisarrow_forwardWhat are three examples each of closed-ended, open-ended, and range-of-response questions? thank youarrow_forwardCreate 2 charts using this data. One without using wind speed and one including max speed in mph. Write a Report and a short report explaining your visualizations and design decisions. Include the following: Lead Story: Identify the key story or insight based on your visualizations. Shaffer’s 4C Framework: Describe how you applied Shaffer’s 4C principles in the design of your charts. External Data Integration: Explain the second data and how you integrated it with the Halloween dataset. Compare the two datasets. Attach screenshots of the two charts (Bar graph or Line graph) The Shaffer 4 C’s of Data Visualization Clear - easily seen; sharply defined• who's the audience? what's the message? clarity more important than aestheticsClean - thorough; complete; unadulterated, labels, axis, gridlines, formatting, right chart type, colorchoice, etc.Concise - brief but comprehensive. not minimalist but not verboseCaptivating - to attract and hold by beauty or excellence does it capture…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





