Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

very simple box class

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • very simple box class

    Code:
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    'SED_PBCC
    '------------------------------------------------------------------------------
    'A simple Box class that calculates it's volume showing multiple instances of the class
    'This was translated from some online C++  instruction  somewhere??
    '******************************************************************************
    '                               James C. Fuller
    '                           [email protected]
    '                               August 4,2008
    '******************************************************************************
    
    #COMPILE EXE
    #DIM ALL
    
    %TRUE = -1
    %FALSE = 0
    
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    CLASS cBox
    	INSTANCE side1,side2,side3,volume AS SINGLE
    	INSTANCE sides_not_set AS LONG
    
    	CLASS METHOD CREATE
    		sides_not_set = %TRUE
    	END METHOD
    
    	INTERFACE iBox : INHERIT IUNKNOWN
    
    		PROPERTY GET volume() AS SINGLE
    			PROPERTY = volume
    		END PROPERTY
    
    		METHOD SetSides(BYVAL A AS SINGLE,BYVAL B AS SINGLE, BYVAL C AS SINGLE)
    			side1 = A
    			side2 = B
    			side3 = C
    			sides_not_set = %FALSE
    		END METHOD
    
    		METHOD FindVolume()
    			IF ISFALSE(sides_not_set) THEN
    				volume = side1 * side2 * side3
    			END IF
    		END METHOD
    	END INTERFACE
    
    END CLASS
    
    
    
    
    FUNCTION PBMAIN () AS LONG
    	LOCAL oBox() AS iBox
    	LOCAL loBox AS iBox
    	LOCAL NumOfBoxes,i  AS LONG, TotVol AS SINGLE
    	LOCAL side1,side2,side3 AS SINGLE
    	NumOfBoxes = DATACOUNT/3
    'Array of Objects
    	REDIM oBox(1 TO NumOfBoxes)
    	PRINT "Number of Boxes = ";NumOfBoxes
    	FOR i = 1 TO NumOfBoxes
    		oBox(i) = CLASS "cBox"
    		side1 = VAL(READ$(i*3))-2
    		side2 = VAL(READ$(i*3))-1
    		side3 = VAL(READ$(i*3))
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    		oBox(i).SetSides(side1,side2,side3)
    		oBox(i).FindVolume
    		PRINT "Box #";FORMAT$(i);" (A=";FORMAT$(Side1);",B=";FORMAT$(Side2);",C=";FORMAT$(Side3);") Volume = ";oBox(i).volume
    
    		TotVol += oBox(i).volume
    '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    	NEXT i
    
        ? "Total Volume of ";FORMAT$(NumOfBoxes);" Boxes = " + FORMAT$(TotVol,"######.000")
    
    	WAITKEY$
    
    
    	DATA 12,5,6
    	DATA 7,7,7
    	DATA 8,4,6
    	DATA 2,3,4
    	DATA 19.88,4.8,7.92
    
    END FUNCTION
    Attached Files
Working...
X