i was trying to do a inheritance class whereby it's similar below, but why, whenever a class end, the value returns to it's original value?? Is there anyway that can fix??
-----------------------------------
Your Flight Itinerary:-
KUL-HND:-
Date:-858993460 Nov 2013,
Time:-858993460
HND-KUL:_
Date:-858993460 Nov 2013,
Time:-858993460
-----------------------------------
Your Ticket Price:-
-----------------------------------
-858993460 Adult(s) :1200
Subcharge :250
Tax :-858993460
Total=Price For Passenger + Subcharge + Tax:-858994170
The reason for this is your inheiritance structure.
PrintTicket inherits from Ticket.
Ticket never initializes it's values.
Your program defines both pa and jj.
pa's constructor prompts for input from the user.
You then try to print using jj which was never initialized since p is not in it's inheiritance tree.
Change PrintTicket to inherit from p and get rid of pa.
What u mean is by this right?? But my problem is...I will get second time input for class p when the class printticket is compiling...
And I can't delete my class p and merge it into class printticket bcause my question don't allow me to do so...must going to hv both class p and printticket
Thats why I create another class and inherited from the base class...but my base class value is not initialize...any other way to fix it?
Please, explain in your own words what you think the class inheritance to mean. What you have shown so far does imply that you have misunderstood the concept.
Read my earlier response. Get rid of pa (line 107).
At least now you have the inheirtance right Ticket<-p<-PrintTicket
pa and jj are two different instances which both include class p.
Therefore p's constructor gets called for both pa and jj.
As noted earlier, passenger is still uninitialized at line 28.
Therefore your calculation of tax is bogus.
Lines 72, 74 and 84 will also output nonsense as a result.
must going to hv
Don't know what that means.
my base class value is not initialize...any other way to fix it?
Any reason you can't create a constructor for Ticket to initialize it?