Critics are Welcome
regards Frank
Code: Select all
' class example by frank bruebach, freebasic, 16-04-2024
'
' Define the Employee class
Type Employee
names As String
dept As String
salary As Integer
End Type
' Define the constructor for the Employee class
Sub Employee_Constructor(ByRef emp As Employee, names As String, dept As String, salary As Integer)
emp.names = names
emp.dept = dept
emp.salary = salary
End Sub
' Define the destructor for the Employee class
Sub Employee_Destructor(ByRef emp As Employee)
' Optionally
End Sub
' Initialize an instance of the Employee class using the constructor
Dim john As Employee
Employee_Constructor(john, "John", "Computer Lab", 1000)
' Define methods to access and manipulate the attributes of the Employee class
Function getDepartment(emp As Employee) As String
getDepartment = emp.dept
End Function
Function getSalary(emp As Employee) As Integer
getSalary = emp.salary
End Function
Sub setSalary(ByRef emp As Employee, newSalary As Integer)
emp.salary = newSalary
End Sub
' Print the attributes of the Employee instance
Print "Department: " & getDepartment(john) ' Output: Computer Lab
Print "Salary: " & getSalary(john) ' Output: 1000
' Update the salary of the Employee instance
setSalary(john, 1200)
Print "Updated Salary: " & getSalary(john) ' Output: 1200
' Call the destructor for the Employee instance
Employee_Destructor(john)
Sleep 5000