Skip to content

Instantly share code, notes, and snippets.

@vivek-vijayan
Last active August 28, 2022 17:39
Show Gist options
  • Save vivek-vijayan/2a7565c8c7128b1112edef0a6ad580c8 to your computer and use it in GitHub Desktop.
Save vivek-vijayan/2a7565c8c7128b1112edef0a6ad580c8 to your computer and use it in GitHub Desktop.
Go program for payroll
package payroll
type Employee struct {
Empid int // public variable as the Empid starts with upper case
empname string // private variable as the empname starts with lowercase
salary int // private variable as the empname starts with lowercase
}
func (emp *Employee) AddEmployeeDetails(name string, salary int) {
emp.SetEmpName(name)
emp.SetSalary(salary)
}
// Setters
func (e *Employee) SetEmpName(name string) {
e.empname = name
}
func (e *Employee) SetSalary(salary int) {
e.salary = salary
}
func (e *Employee) SetEmpID(id int) {
e.Empid = id
}
// Getters
func (e *Employee) ShowEmpName() string {
return e.empname
}
func (e *Employee) ShowSalary() int {
return e.salary
}
func (e *Employee) ShowEmpId() int {
return e.Empid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment