Skip to content

Lab · Go Programming (backend and cloud)

Lab: a class result sheet

Labbeginner· about 2 hours· 5 steps

The brief

A school's class teacher pastes the unit-test register as text lines. You turn each line into a Student struct, add Total and Percent methods, list the top three without disturbing the register, count grades with a map, and print initials that work for Hindi names too.

Why it matters

Parsing text records into structs, summarising them with slices and maps, and handling Indian-language names correctly is daily work in school ERPs, HR systems and every backend that reads CSV exports. The slice-sharing and rune mistakes you meet here are favourite interview questions.

Skills you practise

  • strings.Split, TrimSpace and Fields
  • strconv.Atoi
  • structs and value-receiver methods
  • slices.Clone and sorting
  • maps and sorted keys
  • runes vs bytes

You need

  • Go 1.22 or newer installed from go.dev/dl
  • A module made with go mod init example.com/results

What you will have at the end

main.go that turns the class register into a result sheet: totals, percentages, grades, the top three and initials, correct for Hindi names too.

How it is marked (rubric, 100 points)
Correct resultsTotals, percentages to one decimal, grades, the top three and the grade counts all match.40
Slices and maps used safelyThe register is not reordered by sorting; the map is made before use; keys are sorted for printing.25
Text handled properlyFields are trimmed, Atoi errors are returned, initials use runes.20
Readable codeSmall methods on Student, clear names, gofmt and go vet clean.15

0/5 steps done

Step 1 of 5

Parse each register line into a Student

All six lines parse: the output starts with Parsed 6 students and shows each name and its marks.

strings.Split(line, ",") gives the fields, but each one after the first starts with a space, and strconv.Atoi(" 78") fails. Trim every field with strings.TrimSpace before you use it. The first field is the roll number, the second the name, the rest are marks: append each parsed mark to s.Marks. Return the Atoi error if one fails, so main can skip a bad line.

Run this on your machine, then paste the output below
$ go run .

Also check yourself

Your notes: main.go

Write down each command you ran. It goes into your project summary.