#include #include "HPVISACard.cpp" #include using namespace std; int main() { // Declare variables string type; double amount; int rewardPercentage,choice; // print menu cout<<"Menu"<<"\n1.VISA Card"<<"\n2.HPVISA Card"<>choice; // conditionally execute based on user choice switch(choice){ // case 1 case 1:{ // ask user to enter transaction type cout<<"Enter the transaction type"<>type; // ask user to enter transaction amount cout<<"Enter the transaction amount"<>amount; // ask user to enter reward points cout<<"Enter the reward points"<>rewardPercentage; // create VISACard class object using parameterized constructor VISACard v1(type,amount,rewardPercentage); // print card details by calling suitable methods cout<<"Card details:"<>type; // ask user to enter amount cout<<"Enter the transaction amount"<>amount; // create a object of class HPVISACard HPVISACard hv1(type,amount); // print card details by calling suitable methods cout<<"Card details:"< #include #include "VISACard.cpp" using namespace std; class HPVISACard :public VISACard{ public: void computeRewardPoints() { // declare RewardPoints to store points float RewardPoints; // if type == Fueal if(getType()=="Fuel"){ // calculate 3% amount and add 10 extra points RewardPoints = (amount * (3/100.0))+10; } // else calculate 3% of amount else{ RewardPoints = (amount * (3/100.0)); } // finally print Reward Points cout<<"Reward point:"< #include using namespace std; class VISACard { // protected members of class protected: string type; double amount; // private members of class private: int rewardPercentage; // public members of class public: void computeRewardPoints() { // calculate Reward points based on reward percentage float RewardPoints = amount*(getRewardPercentage()/100.0); // finally print reward points cout<<"Reward point:"<type = type; } void setAmount (double amount){ this->amount = amount; } void setRewardPercentage (int rewardPercentage){ this->rewardPercentage = rewardPercentage; } // getters int getRewardPercentage(){ return rewardPercentage; } string getType(){ return type; } double getAmount(){ return amount; } }; YOU HAVE TO FIND WHY THE OUTPUT IS NOT MATCHING AND MODIFY MY CODE ACCORDING TO THAT.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

QUESTION AND COLLEGE COMPILER OUTPUT ATTACHED IN IMAGE . PLEASE SEE

 

AND MY SOLUTION TO THE PROBLEM IS GIVEN BELOW.

------------MY SOLUTION----------

MAIN.CPP

#include <iostream>

#include "HPVISACard.cpp"
#include <sstream>

using namespace std;

int main() {
// Declare variables
string type;
double amount;
int rewardPercentage,choice;

// print menu
cout<<"Menu"<<"\n1.VISA Card"<<"\n2.HPVISA Card"<<endl;

// ask user to enter his choice
cout<<"Enter the choice"<<endl;
cin>>choice;

// conditionally execute based on user choice
switch(choice){
// case 1
case 1:{
// ask user to enter transaction type
cout<<"Enter the transaction type"<<endl;
cin>>type;

// ask user to enter transaction amount
cout<<"Enter the transaction amount"<<endl;
cin>>amount;

// ask user to enter reward points
cout<<"Enter the reward points"<<endl;
cin>>rewardPercentage;

// create VISACard class object using parameterized constructor
VISACard v1(type,amount,rewardPercentage);

// print card details by calling suitable methods
cout<<"Card details:"<<endl;
cout<<"Type:"<<v1.getType()<<endl;
cout<<"Amount:"<<v1.getAmount()<<endl;
v1.computeRewardPoints();
break;
}

// case 2
case 2:{
// ask user to enter transaction type
cout<<"Enter the transaction type"<<endl;
cin>>type;

// ask user to enter amount
cout<<"Enter the transaction amount"<<endl;
cin>>amount;

// create a object of class HPVISACard
HPVISACard hv1(type,amount);

// print card details by calling suitable methods
cout<<"Card details:"<<endl;
cout<<"Type:"<<hv1.getType()<<endl;
cout<<"Amount:"<<hv1.getAmount()<<endl;
hv1.computeRewardPoints();
break;
}

// any other choice except 1 and 2 , print invalid input
default :
cout<<"Invalid input"<<endl;
}
return 0;
}

 

HPVISCACard.cpp

#include <iostream>
#include <iomanip>
#include "VISACard.cpp"
using namespace std;

class HPVISACard :public VISACard{
public:
void computeRewardPoints() {
// declare RewardPoints to store points
float RewardPoints;

// if type == Fueal
if(getType()=="Fuel"){
// calculate 3% amount and add 10 extra points
RewardPoints = (amount * (3/100.0))+10;
}

// else calculate 3% of amount
else{
RewardPoints = (amount * (3/100.0));
}

// finally print Reward Points
cout<<"Reward point:"<<fixed<<setprecision(1)<<RewardPoints<<endl;
}

// calling super class constructor
HPVISACard(string type1, double amount1) : VISACard(type1, amount1) {
}
};

 

viscard.cpp

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

class VISACard {
// protected members of class
protected:
string type;
double amount;

// private members of class
private:
int rewardPercentage;

// public members of class
public:
void computeRewardPoints() {
// calculate Reward points based on reward percentage
float RewardPoints = amount*(getRewardPercentage()/100.0);

// finally print reward points
cout<<"Reward point:"<<fixed<<setprecision(1)<<RewardPoints<<endl;
}

public:
// constructor with 3 params
VISACard(string type1, double amount1, int rewardPercentage1) {
type = type1;
amount = amount1;
rewardPercentage = rewardPercentage1;
}

// constructor with 2 params
VISACard(string type1, double amount1) {
type = type1;
amount = amount1;
}

// setters
void setType (string type){
this->type = type;
}
void setAmount (double amount){
this->amount = amount;
}
void setRewardPercentage (int rewardPercentage){
this->rewardPercentage = rewardPercentage;
}

// getters
int getRewardPercentage(){
return rewardPercentage;
}
string getType(){
return type;
}
double getAmount(){
return amount;
}
};

YOU HAVE TO FIND WHY THE OUTPUT IS NOT MATCHING AND MODIFY MY CODE ACCORDING TO THAT.

COMPILER OUPTPUT MISMATCH
Test Script - Main
S.No
Test
Expected
Obtained
Differences
Test Script - Main
Menu
Menu
Menu
Input: 1
1.VISA Card
1.VISA Card
1.VISA Card
Shopping
2.HPVISA Card
2.HPVISA Card
2.HPVISA Card
5000
Enter the choice
Enter the choice
Enter the choice
Enter the transaction type
Enter the transaction type
Enter the transaction type
Enter the transaction amount
Enter the transaction amount
Enter the transaction amount
Enter the reward points
Enter the reward points
Enter the reward points
Card details:
Type: Shepping
Amount: 5000
Reward point: 100.0
Card details:
Reward point:100.0
Type: Shopping
Amount: 5000
Reward point: 100.0
Test Script - Main
Menu
Menu
Menu
Input: 2
1.VISA Card
1.VISA Card
1.VISA Card
Fuel
2.HPVISA Card
2.HPVISA Card
2.HPVISA Card
650
Enter the choice
Enter the choice
Enter the choice
Enter the transaction type
Enter the transaction type
Enter the transaction type
Enter the transaction amount
Enter the transaction amount
Enter the transaction amount
Card details:
Fype: Fuet
Amount: 650
Reward point: 29.5
Card details:
Reward point:29.5
Туре: Fuel
Amount: 650
Reward point: 29.5
3
Test Script - Main
Menu
Menu
Input: 3
1.VISA Card
1.VISA Card
2.HPVISA Card
2.HPVISA Card
Enter the choice
Enter the choice
Invalid input
Invalid input
2.
Transcribed Image Text:COMPILER OUPTPUT MISMATCH Test Script - Main S.No Test Expected Obtained Differences Test Script - Main Menu Menu Menu Input: 1 1.VISA Card 1.VISA Card 1.VISA Card Shopping 2.HPVISA Card 2.HPVISA Card 2.HPVISA Card 5000 Enter the choice Enter the choice Enter the choice Enter the transaction type Enter the transaction type Enter the transaction type Enter the transaction amount Enter the transaction amount Enter the transaction amount Enter the reward points Enter the reward points Enter the reward points Card details: Type: Shepping Amount: 5000 Reward point: 100.0 Card details: Reward point:100.0 Type: Shopping Amount: 5000 Reward point: 100.0 Test Script - Main Menu Menu Menu Input: 2 1.VISA Card 1.VISA Card 1.VISA Card Fuel 2.HPVISA Card 2.HPVISA Card 2.HPVISA Card 650 Enter the choice Enter the choice Enter the choice Enter the transaction type Enter the transaction type Enter the transaction type Enter the transaction amount Enter the transaction amount Enter the transaction amount Card details: Fype: Fuet Amount: 650 Reward point: 29.5 Card details: Reward point:29.5 Туре: Fuel Amount: 650 Reward point: 29.5 3 Test Script - Main Menu Menu Input: 3 1.VISA Card 1.VISA Card 2.HPVISA Card 2.HPVISA Card Enter the choice Enter the choice Invalid input Invalid input 2.
ABC Bank announced a new scheme of reward points for a transaction using an ATM card. Each
transaction using the normal card will be provided by giving a reward percentage of the transaction
amount as a reward point. If a transaction is made using a premium card and it is for fuel expenses,
additional 10 points will be rewarded.
Write a program to calculate the total reward points.
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class
names, member variable names, and function names should be the same as specified in the problem
statement.
A class VISACard has the following attributes.
Access Specifiers
Data type
string
double
int
Variable
protected
protected
private
type
lamount
rewardPercentage
Include the following method in VISACard class.
Method
Description
In this method, calculate and display the reward points
based on rewardPercentage in amount
public void ComputeRewardPoints()
Formula:
Reward points = amount * (rewardPercentage / 1o0)
A derived class HPVISACard derived from VISACard class and overrides the following method.
Method
Description
In this method, calculate the reward point.
3% of the amount will be reward points.
If the transaction type is fuel, add 10 points to calculate reward points.
public void ComputeRewardPoints()
Formula:
Transaction type (Fuel): Reward points = (amount * (3/100))+ 10
Type other than fuel: Reward points = amount * (3/ 100)
In the Main method, obtain input from the user.
Create VISACard or HPVISACard objects and invoke display methods to display the details.
Card type will be either 'VISA card' or 'HPVISA card'. Otherwise, display 'Invalid input'
Calculate the reward points corresponding to the card type and transaction type and print the reward
points(upto two precision).
Input and Output Format:
Refer sample input and output for formatting specifications.
All text in bold corresponds to the input and the rest corresponds to output.
Sample Input and Output 1:
Menu
1.VISA Card
2.HPVISA Card
Enter the choice
1
Enter the transaction type
Shopping
Enter the transaction amount
5000
Enter the reward points
Card details:
Type: Shopping
Amount: 5000
Reward point: 100.0
Sample Input and Output 2:
Menu
1.VISA Card
2.HPVISA Card
Enter the choice
2
Enter the transaction type
Fuel
Enter the transaction amount
650
Card details:
Туре: Fuel
Amount: 650
Reward point: 29.5
Sample Input and Output 3:
Menu
1.VISA Card
2.HPVISA Card
Enter the choice
3
Invalid input
Transcribed Image Text:ABC Bank announced a new scheme of reward points for a transaction using an ATM card. Each transaction using the normal card will be provided by giving a reward percentage of the transaction amount as a reward point. If a transaction is made using a premium card and it is for fuel expenses, additional 10 points will be rewarded. Write a program to calculate the total reward points. Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement. A class VISACard has the following attributes. Access Specifiers Data type string double int Variable protected protected private type lamount rewardPercentage Include the following method in VISACard class. Method Description In this method, calculate and display the reward points based on rewardPercentage in amount public void ComputeRewardPoints() Formula: Reward points = amount * (rewardPercentage / 1o0) A derived class HPVISACard derived from VISACard class and overrides the following method. Method Description In this method, calculate the reward point. 3% of the amount will be reward points. If the transaction type is fuel, add 10 points to calculate reward points. public void ComputeRewardPoints() Formula: Transaction type (Fuel): Reward points = (amount * (3/100))+ 10 Type other than fuel: Reward points = amount * (3/ 100) In the Main method, obtain input from the user. Create VISACard or HPVISACard objects and invoke display methods to display the details. Card type will be either 'VISA card' or 'HPVISA card'. Otherwise, display 'Invalid input' Calculate the reward points corresponding to the card type and transaction type and print the reward points(upto two precision). Input and Output Format: Refer sample input and output for formatting specifications. All text in bold corresponds to the input and the rest corresponds to output. Sample Input and Output 1: Menu 1.VISA Card 2.HPVISA Card Enter the choice 1 Enter the transaction type Shopping Enter the transaction amount 5000 Enter the reward points Card details: Type: Shopping Amount: 5000 Reward point: 100.0 Sample Input and Output 2: Menu 1.VISA Card 2.HPVISA Card Enter the choice 2 Enter the transaction type Fuel Enter the transaction amount 650 Card details: Туре: Fuel Amount: 650 Reward point: 29.5 Sample Input and Output 3: Menu 1.VISA Card 2.HPVISA Card Enter the choice 3 Invalid input
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 10 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage