Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package main import ( fmt ) type Student struct { FirstName string LastName string Marks []int RollNo int Rank int Status string } func (s

package main

import ( "fmt" )

type Student struct { FirstName string LastName string Marks []int RollNo int Rank int Status string }

func (s Student) String() string { return fmt.Sprintf("%s %s %v %s", s.FirstName, s.LastName, s.Marks, s.Status) }

// if student passed in atleast two subjects then it returns true otherwise its false func (s Student) Passed() bool { count := 0 for _, marks := range s.Marks { if marks >= 33 { count++ } } return count >= 2 }

func studetDetails(students []Student) { for i := range students { students[i].RollNo = i + 1 if students[i].Passed() { students[i].Status = "Pass" } else { students[i].Status = "Fail" } } assignRanks(students) // Print all student records for i, s := range students { fmt.Println(i+1, s) } }

func assignRanks(students []Student) { for i := range students { students[i].Rank = i + 1 } }

func main() { students := []Student{ {"Ramu", "Ram", []int{45, 56, 67}, 0, 0, ""}, {"Lakshman", "Lucky", []int{55, 46, 77}, 0, 0, ""}, {"Sainath", "Sai", []int{35, 40, 30}, 0, 0, ""}, {"Manohar", "Manu", []int{50, 60, 70}, 0, 0, ""}, {"Joseph", "Joo", []int{33, 45, 87}, 0, 0, ""}, {"Madhava", "Maddy", []int{33, 37, 32}, 0, 0, ""}, {"Sandeep", "Sandy", []int{38, 51, 37}, 0, 0, ""}, {"Aravind", "Indurthi", []int{56, 44, 49}, 0, 0, ""}, {"Chaitanya", "Chaitu", []int{55, 36, 37}, 0, 0, ""}, {"Mani", "Kumar", []int{55, 34, 56}, 0, 0, ""}, {"Pranay", "sebastian", []int{32, 56, 48}, 0, 0, ""}, {"Srinivas", "Srinu", []int{37, 48, 79}, 0, 0, ""}, {"Venkatesh","Venky",[]int{44,34,78},0,0,""}, {"Ramesh","Babu",[]int{64,36,87},0,0,""}, {"Charan","Cherry",[]int{45,78,31},0,0,""}, } studetDetails(students) }

========================================================================

func (s Student) Passed() bool { count := 0 for _, marks := range s.Marks { if marks >= 33 { count++ } } return count >= 2 }

(Reviewer said this logic fuction is wrong)

Rank is not displayed in output,passed function will fail for input {35, 35, 1} and many such inputs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions