Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Functional Programming Assignments
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AB8057
Functional Programming Assignments
Commits
bec33738
Commit
bec33738
authored
1 year ago
by
AB8057
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
290aa767
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignments/assignment6/assignment6.ex
+65
-0
65 additions, 0 deletions
Assignments/assignment6/assignment6.ex
with
65 additions
and
0 deletions
Assignments/assignment6/assignment6.ex
0 → 100644
+
65
−
0
View file @
bec33738
#Define a module and struct Employee, and add struct fields:
#first name
#last name
#id number
#salary
#job, which is one of the {:none, :coder, :designer, :manager, :ceo }
#id number has a default value that is previous id + 1
#salary has a default value 0
#job has a default value of :none
#Implement functions Employee.promote and Employee.demote which updates the job accordingly.
#job :none salary is set to 0
#each job above :none gets 2000 more salary than previous
#Test your Employee module and its promote and demote functions.
defmodule
Employee
do
defstruct
[
:first_name
,
:last_name
,
id_number:
0
,
salary:
0
,
job:
:none
]
def
new_employee
(
firstname
,
lastname
)
do
%
Employee
{
first_name:
firstname
,
last_name:
lastname
}
end
#promoting
def
promote
(%
Employee
{}
=
employee
)
do
new_job
=
promotion
(
employee
.
job
)
new_salary
=
update_salary
(
new_job
)
%
Employee
{
employee
|
job:
new_job
,
salary:
new_salary
}
end
#demoting
def
demote
(%
Employee
{}
=
employee
)
do
new_job
=
demotion
(
employee
.
job
)
new_salary
=
update_salary
(
new_job
)
%
Employee
{
employee
|
job:
new_job
,
salary:
new_salary
}
end
defp
update_salary
(
:none
),
do
:
0
defp
update_salary
(
job
),
do
:
2000
+
update_salary
(
demotion
(
job
))
#promotion order
defp
promotion
(
:none
),
do
:
:coder
defp
promotion
(
:coder
),
do
:
:designer
defp
promotion
(
:designer
),
do
:
:manager
defp
promotion
(
:manager
),
do
:
:ceo
#demotion order
defp
demotion
(
:ceo
),
do
:
:manager
defp
demotion
(
:manager
),
do
:
:designer
defp
demotion
(
:designer
),
do
:
:coder
defp
demotion
(
:coder
),
do
:
:none
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment