September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
96
Task/Function-definition/IWBASIC/function-definition.iwbasic
Normal file
96
Task/Function-definition/IWBASIC/function-definition.iwbasic
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
'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
|
||||
Loading…
Add table
Add a link
Reference in a new issue