error :
i m verry old
Code: Select all
'' bluatigro 29 mrt 2020
'' OOP test
type TDate
private :
as integer y , m , d
public :
declare constructor ()
declare constructor ( a as integer , b as integer , c as integer )
declare function getYear() as integer
declare function getMonth() as integer
declare function getDay() as integer
end type
constructor TDate()
'' set TDate on today .
dim as string t = date
this.y = val( mid( t , 7 , 4 ) )
this.m = val( mid( t , 4 , 2 ) )
this.d = val( mid( t , 1 , 2 ) )
end constructor
constructor TDate( y as integer , m as integer , d as integer )
this.y = y
this.m = m
this.d = d
end constructor
function TDate.getYear() as integer
return this.y
end function
function TDate.getMonth() as integer
return this.m
end function
function Tdate.getDay() as integer
return this.d
end function
type TAnimal
private :
dim as string latin
dim as Tdate birthDay = Tdate()
dim as integer weight
public :
declare constructor ( l as string , d as TDate , w as integer )
declare function getLatin() as string
declare function getAge() as integer
declare function getWeight() as integer
declare function getBirthDay() as TDate
declare function isBirthDay() as integer
end type
constructor TAnimal( l as string , d as TDate , w as integer )
this.latin = l
this.birthDay = d
this.weight = w
end constructor
function TAnimal.getLatin() as string
return this.latin
end function
function TAnimal.getAge() as integer
dim as Tdate today = TDate()
dim as integer y1,y2,m1,m2,d1,d2,age
y1 = this.getBirthDay().getYear()
m1 = this.getBirthDay().getMonth()
d1 = this.getBirthDay().getDay()
y2 = today.getYear()
m2 = today.getMonth()
d2 = today.getDay()
age = y2 - y1
if m2 < m1 then
age -= 1
else
if m2 = m1 then
if d2 < d1 then
age -= 1
end if
end if
end if
return age
end function
function Tanimal.getWeight() as integer
return this.weight
end function
function TAnimal.getBirthDay() as TDate
return this.birthDay
end function
function TAnimal.isBirthDay() as integer
dim as Tdate today = TDate()
dim as integer y1,y2,m1,m2,d1,d2,age
y1 = this.getBirthDay().getYear()
m1 = this.getBirthDay().getMonth()
d1 = this.getBirthDay().getDay()
y2 = today.getYear()
m2 = today.getMonth()
d2 = today.getDay()
if y1 <> y2 then return 0
if m1 <> m2 then return 0
if d1 <> d2 then return 0
return 1
end function
dim as TAnimal human = TAnimal( "homo sapiens" , TDate( 6 , 1 , 1960 ) , 118 )
print "latin : " + human.getLatin()
print "age : " + str( human.getAge() )
print "weight : " + str( human.getWeight() )
dim as string a
if human.isBirthDay() then
a = "yes"
else
a = "no"
end if
print "has birth day : " + a
sleep