Having trouble with solving the questions in the screenshot using the source code below. Any suggestions are highly appreciated!  package main // Code with a simple main() to test your functions import (     "fmt"     "math" ) // Put your functions here func main() {     // Should see 7.25

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Having trouble with solving the questions in the screenshot using the source code below. Any suggestions are highly appreciated! 

package main

// Code with a simple main() to test your functions
import (
    "fmt"
    "math"
)

// Put your functions here

func main() {
    // Should see 7.25
    fmt.Println(compPoly(1, 2, -4, 2.5))

      // Should see 0.5 5
    fmt.Println(calcRoots(2, -11, 5))
      // Should see NaN NaN
    fmt.Println(calcRoots(3.14, 1, 4))

    strs1 := []string{"the", "lazy", "dog"};
    strs2 := []string{"the", "quick", "brown", "fox"};
      // Should see true
    fmt.Println(lastToFirst(strs1))
      // Should see false
    fmt.Println(lastToFirst(strs2))
}

1. a function compPoly that takes 4 parameters: a, b, c and x and returns ax² + bx + c
the parameters and return type are all of type float64
An example result: compPoly(4,-10,5, 3) should return 11 (4*3*3 – 10 * 3 + 5 = 36 – 30 + 5 = 11)
It makes sense to test the function with simple values so you can easily check if you have a correct answer, but the type really does need to be of type float64. The grader will be running test code that expects this
2. A function calcRoots that takes 3 parameters: a, b, c and uses the quadratic formula to return the two roots
the parameters and both return values are again all of type float64
the first return value should be (-b – sqrt(b²-4ac))/2a, while the 2nd return value should be (-b + sqrt(b²-4ac))/2a
if the determinant (b--4ac) is negative, return the NaN value (for “not a number") for both roots
Besides needing conditional code, this function has you use the “math" library for Go, too. The Sqrt() and NaN() functions will give you what you need.
Ex: calcRoots(2, -11, 5) should return 0.5, 5, while calcRoots (3.14, 1, 4) would return NaN, NaN
3. A function lastToFirst that takes a slice of strings and returns true if the list is in strictly decreasing order, using the default ordering for strings
This function gives you a reason to use a loop
Ex: lastToFirst ([]string{"guard", "dog", "chases"}) should return true
Transcribed Image Text:1. a function compPoly that takes 4 parameters: a, b, c and x and returns ax² + bx + c the parameters and return type are all of type float64 An example result: compPoly(4,-10,5, 3) should return 11 (4*3*3 – 10 * 3 + 5 = 36 – 30 + 5 = 11) It makes sense to test the function with simple values so you can easily check if you have a correct answer, but the type really does need to be of type float64. The grader will be running test code that expects this 2. A function calcRoots that takes 3 parameters: a, b, c and uses the quadratic formula to return the two roots the parameters and both return values are again all of type float64 the first return value should be (-b – sqrt(b²-4ac))/2a, while the 2nd return value should be (-b + sqrt(b²-4ac))/2a if the determinant (b--4ac) is negative, return the NaN value (for “not a number") for both roots Besides needing conditional code, this function has you use the “math" library for Go, too. The Sqrt() and NaN() functions will give you what you need. Ex: calcRoots(2, -11, 5) should return 0.5, 5, while calcRoots (3.14, 1, 4) would return NaN, NaN 3. A function lastToFirst that takes a slice of strings and returns true if the list is in strictly decreasing order, using the default ordering for strings This function gives you a reason to use a loop Ex: lastToFirst ([]string{"guard", "dog", "chases"}) should return true
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY