initial commit
This commit is contained in:
commit
22020f62d9
6 changed files with 381 additions and 0 deletions
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
*.test
|
||||||
|
|
||||||
|
*.out
|
||||||
|
|
||||||
|
go.work
|
||||||
|
|
||||||
|
vendor/
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
cmd/redovalnica
|
||||||
157
README.md
Normal file
157
README.md
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
# Redovalnica - Student Grade Management System
|
||||||
|
|
||||||
|
Package redovalnica implements a simple grade book in Go.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
A minimal grading system: add students and grades, list grades, and compute final results. Configurable thresholds control required grade counts and the grading range.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go get git.fri.uni-lj.si/zs7976/ps-naloga5
|
||||||
|
```
|
||||||
|
|
||||||
|
## Package Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
naloga5/
|
||||||
|
├── redovalnica/ # Core package with grading functionality
|
||||||
|
│ └── redovalnica.go
|
||||||
|
├── cmd/ # Command-line application
|
||||||
|
│ └── redovalnica.go
|
||||||
|
├── go.mod
|
||||||
|
├── go.sum
|
||||||
|
└── README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exported Functions
|
||||||
|
|
||||||
|
The `redovalnica` package exports the following functions:
|
||||||
|
|
||||||
|
### DodajStudenta
|
||||||
|
```go
|
||||||
|
func DodajStudenta(studenti map[string]Student, vpisnaStevilka string, ime string, priimek string)
|
||||||
|
```
|
||||||
|
Adds a new student to the grade book. If a student with the given ID already exists, the function does nothing.
|
||||||
|
|
||||||
|
### DodajOceno
|
||||||
|
```go
|
||||||
|
func DodajOceno(studenti map[string]Student, vpisnaStevilka string, ocena int)
|
||||||
|
```
|
||||||
|
Adds a grade to a student's record. If the student doesn't exist, the function does nothing.
|
||||||
|
|
||||||
|
### IzpisVsehOcen
|
||||||
|
```go
|
||||||
|
func IzpisVsehOcen(studenti map[string]Student)
|
||||||
|
```
|
||||||
|
Prints all students and their grades to standard output.
|
||||||
|
|
||||||
|
### IzpisiKoncniUspeh
|
||||||
|
```go
|
||||||
|
func IzpisiKoncniUspeh(studenti map[string]Student, minStOcen int, minOcena int, maxOcena int)
|
||||||
|
```
|
||||||
|
Prints the final success status for all students based on their average grades and configured parameters.
|
||||||
|
|
||||||
|
## Usage as a Library
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.fri.uni-lj.si/zs7976/ps-naloga5/redovalnica"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Create student map
|
||||||
|
studenti := make(map[string]redovalnica.Student)
|
||||||
|
|
||||||
|
// Add students
|
||||||
|
redovalnica.DodajStudenta(studenti, "63210001", "Ana", "Novak")
|
||||||
|
redovalnica.DodajStudenta(studenti, "63210002", "Boris", "Kralj")
|
||||||
|
|
||||||
|
// Add grades
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 10)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 9)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 8)
|
||||||
|
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 6)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 7)
|
||||||
|
|
||||||
|
// Display all grades
|
||||||
|
redovalnica.IzpisVsehOcen(studenti)
|
||||||
|
|
||||||
|
// Display final success (minStOcen=3, minOcena=1, maxOcena=10)
|
||||||
|
redovalnica.IzpisiKoncniUspeh(studenti, 3, 1, 10)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command-Line Application
|
||||||
|
|
||||||
|
The package includes a command-line application with configurable parameters.
|
||||||
|
|
||||||
|
### Building
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cmd
|
||||||
|
go build -o redovalnica
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run with default parameters
|
||||||
|
./redovalnica
|
||||||
|
|
||||||
|
# Run with custom parameters
|
||||||
|
./redovalnica --stOcen 4 --minOcena 5 --maxOcena 10
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command-Line Flags
|
||||||
|
|
||||||
|
- `--stOcen`: Minimum number of grades required for positive evaluation (default: 3)
|
||||||
|
- `--minOcena`: Minimum possible grade (default: 1)
|
||||||
|
- `--maxOcena`: Maximum possible grade (default: 10)
|
||||||
|
|
||||||
|
### Example Output
|
||||||
|
|
||||||
|
```
|
||||||
|
=== Sistem Redovalnica ===
|
||||||
|
Parametri: minStOcen=3, minOcena=1, maxOcena=10
|
||||||
|
|
||||||
|
REDOVALNICA:
|
||||||
|
63210001 - Ana Novak: [10 9 8]
|
||||||
|
63210002 - Boris Kralj: [6 7 5 8]
|
||||||
|
63210003 - Janez Novak: [4 5]
|
||||||
|
|
||||||
|
Ana Novak: povprečna ocena 9.0 (3 ocen) -> Odličen študent!
|
||||||
|
Boris Kralj: povprečna ocena 6.5 (4 ocen) -> Povprečen študent
|
||||||
|
Janez Novak: povprečna ocena 4.5 (2 ocen) -> Premalo ocen
|
||||||
|
```
|
||||||
|
|
||||||
|
## Internal functions
|
||||||
|
|
||||||
|
Unexported helpers:
|
||||||
|
|
||||||
|
- `povprecje`: average grade for a student
|
||||||
|
- `izpisStudenta`: format student info
|
||||||
|
- `vrniUspeh`: determine success category
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
For detailed API documentation, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go doc git.fri.uni-lj.si/zs7976/ps-naloga5/redovalnica
|
||||||
|
```
|
||||||
|
|
||||||
|
Or view documentation for specific functions:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go doc git.fri.uni-lj.si/zs7976/ps-naloga5/redovalnica.DodajOceno
|
||||||
|
go doc git.fri.uni-lj.si/zs7976/ps-naloga5/redovalnica.IzpisVsehOcen
|
||||||
|
```
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Žan Skvarča
|
||||||
77
cmd/redovalnica.go
Normal file
77
cmd/redovalnica.go
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
"git.fri.uni-lj.si/zs7976/ps-naloga5/redovalnica"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cmd := &cli.Command{
|
||||||
|
Name: "redovalnica",
|
||||||
|
Usage: "Student grade management system",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.IntFlag{
|
||||||
|
Name: "stOcen",
|
||||||
|
Usage: "Minimum number of grades required for positive evaluation",
|
||||||
|
Value: 3,
|
||||||
|
},
|
||||||
|
&cli.IntFlag{
|
||||||
|
Name: "minOcena",
|
||||||
|
Usage: "Minimum possible grade",
|
||||||
|
Value: 1,
|
||||||
|
},
|
||||||
|
&cli.IntFlag{
|
||||||
|
Name: "maxOcena",
|
||||||
|
Usage: "Maximum possible grade",
|
||||||
|
Value: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
minStOcen := int(cmd.Int("stOcen"))
|
||||||
|
minOcena := int(cmd.Int("minOcena"))
|
||||||
|
maxOcena := int(cmd.Int("maxOcena"))
|
||||||
|
|
||||||
|
fmt.Printf("=== Sistem Redovalnica ===\n")
|
||||||
|
fmt.Printf("Parametri: minStOcen=%d, minOcena=%d, maxOcena=%d\n\n",
|
||||||
|
minStOcen, minOcena, maxOcena)
|
||||||
|
// Ustvari mapo študentov
|
||||||
|
studenti := make(map[string]redovalnica.Student)
|
||||||
|
|
||||||
|
// Dodaj študente
|
||||||
|
redovalnica.DodajStudenta(studenti, "63210001", "Ana", "Novak")
|
||||||
|
redovalnica.DodajStudenta(studenti, "63210002", "Boris", "Kralj")
|
||||||
|
redovalnica.DodajStudenta(studenti, "63210003", "Janez", "Novak")
|
||||||
|
|
||||||
|
// Dodaj ocene
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 10)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 9)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210001", 8)
|
||||||
|
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 6)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 7)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 5)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210002", 8)
|
||||||
|
|
||||||
|
redovalnica.DodajOceno(studenti, "63210003", 4)
|
||||||
|
redovalnica.DodajOceno(studenti, "63210003", 5)
|
||||||
|
|
||||||
|
// Izpiši vse ocene
|
||||||
|
redovalnica.IzpisVsehOcen(studenti)
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
// Izpiši končni uspeh
|
||||||
|
redovalnica.IzpisiKoncniUspeh(studenti, minStOcen, minOcena, maxOcena)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
7
go.mod
Normal file
7
go.mod
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
module git.fri.uni-lj.si/zs7976/ps-naloga5
|
||||||
|
|
||||||
|
go 1.23
|
||||||
|
|
||||||
|
require github.com/urfave/cli/v3 v3.0.0-alpha9
|
||||||
|
|
||||||
|
require github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
12
go.sum
Normal file
12
go.sum
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo=
|
||||||
|
github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
104
redovalnica/redovalnica.go
Normal file
104
redovalnica/redovalnica.go
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
// Package redovalnica implements a simple grade book.
|
||||||
|
//
|
||||||
|
// It supports adding students and grades, listing grades, and computing final
|
||||||
|
// status based on averages.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// studenti := make(map[string]redovalnica.Student)
|
||||||
|
// redovalnica.DodajStudenta(studenti, "63210001", "Ana", "Novak")
|
||||||
|
// redovalnica.DodajOceno(studenti, "63210001", 10)
|
||||||
|
// redovalnica.IzpisVsehOcen(studenti)
|
||||||
|
// redovalnica.IzpisiKoncniUspeh(studenti, 3, 1, 10)
|
||||||
|
//
|
||||||
|
// Exported functions:
|
||||||
|
// - DodajStudenta
|
||||||
|
// - DodajOceno
|
||||||
|
// - IzpisVsehOcen
|
||||||
|
// - IzpisiKoncniUspeh
|
||||||
|
package redovalnica
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// Student represents a student with personal data and grades.
|
||||||
|
type Student struct {
|
||||||
|
Ime string
|
||||||
|
Priimek string
|
||||||
|
Ocene []int
|
||||||
|
}
|
||||||
|
|
||||||
|
// DodajStudenta adds a student if the ID is not already present.
|
||||||
|
func DodajStudenta(studenti map[string]Student, vpisnaStevilka string, ime string, priimek string) {
|
||||||
|
_, obstaja := studenti[vpisnaStevilka]
|
||||||
|
if obstaja {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
studenti[vpisnaStevilka] = Student{Ime: ime, Priimek: priimek, Ocene: []int{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DodajOceno appends a grade to a student's record. If the student is missing
|
||||||
|
// the call is a no-op.
|
||||||
|
func DodajOceno(studenti map[string]Student, vpisnaStevilka string, ocena int) {
|
||||||
|
student, obstaja := studenti[vpisnaStevilka]
|
||||||
|
if !obstaja {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
student.Ocene = append(student.Ocene, ocena)
|
||||||
|
studenti[vpisnaStevilka] = student
|
||||||
|
}
|
||||||
|
|
||||||
|
// povprecje returns the average grade for a student, or 0 if no grades.
|
||||||
|
func povprecje(studenti map[string]Student, vpisnaStevilka string) float64 {
|
||||||
|
student, obstaja := studenti[vpisnaStevilka]
|
||||||
|
if !obstaja || len(student.Ocene) == 0 {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
skupaj := 0
|
||||||
|
for _, ocena := range student.Ocene {
|
||||||
|
skupaj += ocena
|
||||||
|
}
|
||||||
|
return float64(skupaj) / float64(len(student.Ocene))
|
||||||
|
}
|
||||||
|
|
||||||
|
// izpisStudenta returns formatted student info or an empty string if missing.
|
||||||
|
func izpisStudenta(studenti map[string]Student, vpisnaStevilka string) string {
|
||||||
|
student, obstaja := studenti[vpisnaStevilka]
|
||||||
|
if !obstaja {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return vpisnaStevilka + " - " + student.Ime + " " + student.Priimek + ": " + fmt.Sprint(student.Ocene)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IzpisVsehOcen prints all students and their grades.
|
||||||
|
func IzpisVsehOcen(studenti map[string]Student) {
|
||||||
|
fmt.Println("REDOVALNICA:")
|
||||||
|
for vpisnaStevilka := range studenti {
|
||||||
|
fmt.Println(izpisStudenta(studenti, vpisnaStevilka))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vrniUspeh returns a status string based on average and grade count.
|
||||||
|
func vrniUspeh(povprecje float64, stOcen int, minStOcen int, minOcena int, maxOcena int) string {
|
||||||
|
if stOcen < minStOcen {
|
||||||
|
return "Premalo ocen"
|
||||||
|
}
|
||||||
|
if povprecje >= float64(maxOcena)-1 {
|
||||||
|
return "Odličen študent!"
|
||||||
|
} else if povprecje >= float64(minOcena)+float64(maxOcena-minOcena)/2 {
|
||||||
|
return "Povprečen študent"
|
||||||
|
} else {
|
||||||
|
return "Neuspešen študent"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IzpisiKoncniUspeh prints final status for all students using provided
|
||||||
|
// thresholds.
|
||||||
|
func IzpisiKoncniUspeh(studenti map[string]Student, minStOcen int, minOcena int, maxOcena int) {
|
||||||
|
for vpisnaStevilka, student := range studenti {
|
||||||
|
povp := povprecje(studenti, vpisnaStevilka)
|
||||||
|
stOcen := len(student.Ocene)
|
||||||
|
uspeh := vrniUspeh(povp, stOcen, minStOcen, minOcena, maxOcena)
|
||||||
|
fmt.Printf("%s %s: povprečna ocena %.1f (%d ocen) -> %s\n",
|
||||||
|
student.Ime, student.Priimek, povp, stOcen, uspeh)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue