Is it possible to...?

Below are my coding. It runs very well. However, as you can notice, there are several functions that are exactly the same but due to different class thus I could not take it out of the if/then/else block. Is it possible to take it out with any special functions or etc.?
P/S: Two different classes are declared due to I've to do accordingly to questions regarding inheritance in C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  if (dutyFree == true)
        {
            //as accordingly to question, information input by user are display through friend function
            freeDutyPrice vehicle(vehicleType, countryOfOrigin, manufacturerPrice, engineCapacity);
            vehicle.setExciseDuty();
            vehicle.calculate();
            displayData(vehicle);
            //as accordingly to question, input/output should be done in main program
            cout << left << setw(25) << "Excise Duty" << right << ": RM" << setw(8) << right << vehicle.returnExciseDuty << endl;
            cout << left << setw(25) << "Sales Tax" << right << ": RM" << setw(8) << right << vehicle.returnSalesTax << endl;
            cout << left << setw(25) << "Final Price" << right << ": RM" << setw(8) << right << vehicle.returnFinalPrice << endl;
            
        }
        else
        {
            nonFreeDutyPrice vehicle(vehicleType, countryOfOrigin, manufacturerPrice, engineCapacity);
            vehicle.setExciseDuty();
            vehicle.setImportDuty();
            vehicle.calculate();
            displayData(vehicle);
            cout << left << setw(25) << "Excise Duty" << right << ": RM" << setw(8) << right << vehicle.returnExciseDuty << endl;
            cout << left << setw(25) << "Import Duty" << right << ": RM" << setw(8) << right << vehicle.returnImportDuty << endl;
            cout << left << setw(25) << "Sales Tax" << right << ": RM" << setw(8) << right << vehicle.returnSalesTax << endl;
            cout << left << setw(25) << "Final Price" << right << ": RM" << setw(8) << right << vehicle.returnFinalPrice << endl;
        }
Topic archived. No new replies allowed.