Advertisement
Gabiinethee

InheritanceGo_HackerRank_Day12_2

Jun 6th, 2022
1,691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.29 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. type Person struct {
  8.     firstName      string
  9.     lastName       string
  10.     identification int32
  11. }
  12.  
  13. type profesor struct {
  14.     *Person
  15.     testScores [2]int32
  16. }
  17.  
  18. func (pp profesor) calculate() string {
  19.     sum := 0
  20.     result := 0
  21.     for i := 0; i < len(pp.testScores); i++ {
  22.         sum = sum + int(pp.testScores[i])
  23.     }
  24.     result = sum / len(pp.testScores)
  25.  
  26.     if result <= 100 && result >= 90 {
  27.         return "O"
  28.     } else if result < 90 && result >= 80 {
  29.         return "E"
  30.     } else if result < 80 && result >= 70 {
  31.         return "A"
  32.     } else if result < 70 && result >= 55 {
  33.         return "P"
  34.     } else if result < 55 && result >= 40 {
  35.         return "D"
  36.     } else {
  37.         return "T"
  38.     }
  39. }
  40.  
  41. func (p Person) printPerson() {
  42.     fmt.Printf("Name: %s, %s \nID: %v", p.lastName, p.firstName, p.identification)
  43. }
  44.  
  45. func main() {
  46.  
  47.     var firstName string
  48.     var lastName string
  49.     var id int32
  50.     fmt.Scan(&firstName, &lastName, &id)
  51.  
  52.     var amountOfTestScores uint8
  53.     fmt.Scan(&amountOfTestScores)
  54.     var testScores [2]int32
  55.     for i := 0; i < int(amountOfTestScores); i++ {
  56.         var v int32
  57.         fmt.Scan(&v)
  58.         testScores[i] = v
  59.     }
  60.  
  61.     p := Person{
  62.         firstName,
  63.         lastName,
  64.         id,
  65.     }
  66.  
  67.     pp := profesor{
  68.         &p,
  69.         testScores,
  70.     }
  71.  
  72.     p.printPerson()
  73.     grade := pp.calculate()
  74.  
  75.     fmt.Printf("\nGrade: %s", grade)
  76.  
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement