97 lines
1.3 KiB
Plaintext
97 lines
1.3 KiB
Plaintext
'1. Not Object Oriented Program
|
|
|
|
DECLARE Multiply(N1:INT,N2:INT),INT
|
|
|
|
DEF A,B:INT
|
|
|
|
A=2:B=2
|
|
|
|
OPENCONSOLE
|
|
|
|
PRINT Multiply(A,B)
|
|
|
|
PRINT
|
|
|
|
'When compiled as a console only program, a press any key to continue is automatic.
|
|
CLOSECONSOLE
|
|
|
|
END
|
|
|
|
SUB Multiply(N1:INT,N2:INT),INT
|
|
|
|
DEF Product:INT
|
|
|
|
Product=N1*N2
|
|
|
|
RETURN Product
|
|
ENDSUB
|
|
|
|
'Can also be written with no code in the subroutine and just RETURN N1*N2.
|
|
|
|
----
|
|
|
|
'2. Not Object Oriented Program Using A Macro
|
|
|
|
$MACRO Multiply (N1,N2) (N1*N2)
|
|
|
|
DEF A,B:INT
|
|
|
|
A=5:B=5
|
|
|
|
OPENCONSOLE
|
|
|
|
PRINT Multiply (A,B)
|
|
|
|
PRINT
|
|
|
|
'When compiled as a console only program, a press any key to continue is automatic.
|
|
CLOSECONSOLE
|
|
|
|
END
|
|
|
|
----
|
|
|
|
'3. In An Object Oriented Program
|
|
|
|
CLASS Associate
|
|
'functions/methods
|
|
DECLARE Associate:'object constructor
|
|
DECLARE _Associate:'object destructor
|
|
'***Multiply declared***
|
|
DECLARE Multiply(UnitsSold:UINT),UINT
|
|
'members
|
|
DEF m_Price:UINT
|
|
DEF m_UnitsSold:UINT
|
|
DEF m_SalesTotal:UINT
|
|
ENDCLASS
|
|
|
|
DEF Emp:Associate
|
|
|
|
m_UnitsSold=10
|
|
|
|
Ass.Multiply(m_UnitsSold)
|
|
|
|
OPENCONSOLE
|
|
|
|
PRINT"Sales total: ",:PRINT"$"+LTRIM$(STR$(Emp.m_SalesTotal))
|
|
|
|
PRINT
|
|
|
|
CLOSECONSOLE
|
|
|
|
END
|
|
|
|
'm_price is set in constructor
|
|
SUB Associate::Multiply(UnitsSold:UINT),UINT
|
|
m_SalesTotal=m_Price*UnitsSold
|
|
RETURN m_SalesTotal
|
|
ENDSUB
|
|
|
|
SUB Associate::Associate()
|
|
m_Price=10
|
|
ENDSUB
|
|
|
|
SUB Associate::_Associate()
|
|
'Nothing to cleanup
|
|
ENDSUB
|