Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab5 #278

Open
wants to merge 1 commit into
base: Kulbakin_Akim_Aleksandrovich
Choose a base branch
from
Open

lab5 #278

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions golang/internal/lab5/lab5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package airplanestruct

import "fmt"

type airplane struct {
speed int
model string
manufcountry string
}

func (a airplane) GetSpeed() int {
return a.speed
}

func NewAirplane(speedVar int, modelVar, manufcountryVar string) (airplane, error) {
var a airplane = airplane{
model: modelVar,
manufcountry: manufcountryVar,
}
var err = a.SetSpeed(speedVar)
return a, err
}

func (a *airplane) SetSpeed(speed int) error {
if speed > 200 && speed < 10000 {
a.speed = speed
return nil
}
return fmt.Errorf("failed SetSpeed() for airplane model \"%s\" - invalid speed", a.GetModel())
}

func (a airplane) GetModel() string {
return a.model
}

func (a *airplane) SetModel(model string) {
a.model = model
}

func (a airplane) GetManufcountry() string {
return a.manufcountry
}

func (a *airplane) SetManufcountry(manufcountry string) {
a.manufcountry = manufcountry
}
31 changes: 27 additions & 4 deletions golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ package main

import (
"fmt"
"log"

"isuct.ru/informatics2022/internal/lab4"
airplanestruct "isuct.ru/informatics2022/internal/lab5"
//"isuct.ru/informatics2022/internal/lab4"
)

func checkForError(err error) {
if err != nil {
log.Fatal(err)
}
}

func main() {
fmt.Println("Кульбакин Аким Александрович")
/*fmt.Println("Кульбакин Аким Александрович")
fmt.Println("Задача А")
xn := 1.2
xk := 2.2
Expand All @@ -21,6 +30,20 @@ func main() {
xarray := []float64{1.21, 1.76, 2.53, 3.48, 4.52}
x, y = lab4.TaskB(xarray, a, b)
for i := range y {
fmt.Println("при x =", x[i], "y =", y[i])
}
fmt.Println("при x =", x[i], "y =", y[i])*/

//lab 5
airplane, err := airplanestruct.NewAirplane(3000, "IL-62", "Russia")
checkForError(err)
aeroplane, err := airplanestruct.NewAirplane(853, "Some Airbus", "France")
checkForError(err)
lastairplane, err := airplanestruct.NewAirplane(968, "Boeing-747", "USA")
checkForError(err)

airplane.SetModel("Il'ushin IL-62")
aeroplane.SetModel("Airbus A320")

fmt.Println("Airplane model is", lastairplane.GetModel())
fmt.Println("Airplane speed is", lastairplane.GetSpeed())
fmt.Println("Airplane manufacturing country is", lastairplane.GetManufcountry())
}