Skip to content
Open

Lab 7 #627

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
1 change: 1 addition & 0 deletions Informatics_2024
Submodule Informatics_2024 added at f0237c
35 changes: 35 additions & 0 deletions golang/labs/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package lab4

import (
"fmt"
"math"
)

func RunLab4() {
a := 2.5
b := 4.6
fmt.Println(taska(1.1, 3.6, 0.5, a, b))
arr := []float64{1.2, 1.28, 1.36, 1.46, 2.35}
fmt.Println(taskb(arr, a, b))
}

func taska(xn, xk, deltax, a, b float64) []float64 {
var yValues []float64
for x := xn; x <= xk; x += deltax {
yValues = append(yValues, CalculateY(x, a, b))
}
return yValues
}

func taskb(values []float64, a, b float64) []float64 {
var yValues []float64
for _, x := range values {
yValues = append(yValues, CalculateY(x, a, b))
}
return yValues
}

func CalculateY(x float64, a float64, b float64) float64 {
y := math.Pow(a+b*x, 2.5) / (1 + math.Log10(a+b*x))
return y
}
41 changes: 41 additions & 0 deletions golang/labs/lab6/lab6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package lab6

import (
"fmt"
)

type Mouse struct {
Name string
Age int
Weight float64
}

func NewMouse(name string, age int, weight float64) Mouse {
return Mouse{Name: name, Age: age, Weight: weight}
}

func (r *Mouse) GetAge() int {
return r.Age
}

func (r *Mouse) SetAge(age int) {
if age > 0 {
r.Age = age
}
}

func (r Mouse) Info() string {
return fmt.Sprintf("Имя: %s, Возраст: %d, Вес: %.2f кг", r.Name, r.Age, r.Weight)
}

func RunLab6() {
mouse := NewMouse("Гена", 2, 1.5)

fmt.Println(mouse.Info())

mouse.SetAge(3)

fmt.Printf("Обновленный возраст: %d\n", mouse.GetAge())

fmt.Println(mouse.Info())
}
40 changes: 40 additions & 0 deletions golang/labs/lab7/clothes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package labs

import "fmt"

type Clothes struct {
name string
price float64
brand string
material string
season string
}

func (c *Clothes) GetName() string {
return c.name
}

func (c *Clothes) GetPrice() float64 {
return c.price
}

func (c *Clothes) SetDiscount(discount float64) {
c.price -= c.price * discount / 100
}

func (c *Clothes) SetPrice(newPrice float64) {
c.price = newPrice
}

func (c *Clothes) GetBrand() string {
return c.brand
}
func (c *Clothes) GetSeason() string {
return c.season
}
func (c *Clothes) GetMat() string {
return c.material
}
func (c *Clothes) GetInf() string {
return fmt.Sprintf("название: %s, цена: %.2f, бренд: %s, материал: %s,сезон: %s", c.name, c.price, c.brand, c.material, c.season)
}
27 changes: 27 additions & 0 deletions golang/labs/lab7/cosmetics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package labs

import "fmt"

type Cosmetics struct {
name string
price float64
brand string
}

func (c *Cosmetics) GetName() string {
return c.name
}
func (c *Cosmetics) GetPrice() float64 {
return c.price
}

func (c *Cosmetics) SetDiscount(discount float64) {
c.price -= c.price * discount / 100
}

func (c *Cosmetics) SetPrice(newPrice float64) {
c.price = newPrice
}
func (c *Cosmetics) GetInf() string {
return fmt.Sprintf("название: %s, бренд: %s, цена: %.2f", c.name, c.brand, c.price)
}
28 changes: 28 additions & 0 deletions golang/labs/lab7/food.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package labs

import "fmt"

type Food struct {
price float64
name string
brand string
calories int
}

func (f *Food) GetName() string {
return f.name
}
func (f *Food) GetPrice() float64 {
return f.price
}

func (f *Food) SetDiscount(discount float64) {
f.price -= f.price * discount / 100
}

func (f *Food) SetPrice(newPrice float64) {
f.price = newPrice
}
func (f *Food) GetInf() string {
return fmt.Sprintf("название: %s, цена: %.2f, каллории: %d , бренд: %s", f.name, f.price, f.calories, f.brand)
}
33 changes: 33 additions & 0 deletions golang/labs/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package labs

import "fmt"

func CalculateProductsSum(products []Product) float64 {
var sum float64 = 0
for _, product := range products {
sum += product.GetPrice()
}
return sum
}

func RunLab7() {
carrot := &Food{50.15, "морковь", "магнит", 17}
mascara := &Cosmetics{"тушь для ресниц", 1700, "loreal paris"}
shirt := &Clothes{"рубашка", 3000.99, "Levi`s", "синтетика", "весна"}
products := []Product{carrot, mascara, shirt}
fmt.Println("товары")
fmt.Println("общая стоимость:", CalculateProductsSum(products), "рублей")
for _, product := range products {
fmt.Println(product.GetInf())
}

for _, product := range products {
product.SetDiscount(20)
}
fmt.Println("общая стоимость товаров после применения скидки 20%:", CalculateProductsSum(products), "рублей")

fmt.Println("информация про товар рубашка")
fmt.Println("материал:", shirt.GetMat())
fmt.Println("сезон:", shirt.GetSeason())
fmt.Println("бренд:", shirt.GetBrand())
}
9 changes: 9 additions & 0 deletions golang/labs/lab7/product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package labs

type Product interface {
SetDiscount(discount float64)
SetPrice(newPrice float64)
GetPrice() float64
GetName() string
GetInf() string
}
10 changes: 9 additions & 1 deletion golang/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package main

import "fmt"
import (
"fmt"
lab4 "isuct.ru/informatics2022/labs/lab4"
lab6 "isuct.ru/informatics2022/labs/lab6"
lab7 "isuct.ru/informatics2022/labs/lab7"
)

func main() {
fmt.Println("Медведева Виктория Александровна")
lab4.RunLab4()
lab6.RunLab6()
lab7.RunLab7()
}
Loading