The Student Room Group

Pascal - Object Oriented Programming

An object-oriented program is required to handle details of a lending library's books and CDs.
This could be implemented by declaring two separate classes Book and CD. This would result in a lot of repetitive code. Making use of inheritant , write class definiations for one super class StockItem and two subclasses Book and CD.


This is my attempt. Please inspect my code to verify that i have done the right thing.

Type
StockItem = Class
Private
Title : string;
OnLoan : Boolean;
DateAquired : Date;
Public
Procedure init;
Function SetLoan;
Procedure DisplayDetails;
End;
Type
Book = Class(StockItem)
Private
Title : string;
Author : string;
ISBN : Integer;
OnLoan : Boolean;
DateAquired : Date;
End;
Type
CD=Class(StockItem)
Private
Title : string;
Artist : string;
PlayingTime : real;

End;
End.
Reply 1
I wasn't aware that Pascal was OOP - Delphi is (I think), but Pascal is a procedural language, no?

And sorry, but your code is unreadable :frown:

Latest