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

Lab67 #610

Open
wants to merge 11 commits into
base: Medvedeva_Viktoriia
Choose a base branch
from
1 change: 1 addition & 0 deletions Informatics_2024
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удалить папку

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) GetMaterial() string {
return c.material
}
func (c *Clothes) GetInfo() 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) GetInfo() 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) GetInfo() 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() {
potato := &Food{50.15, "картошка", "вкусвилл", 17}
lipstick := &Cosmetics{"помада", 1700, "Chanel"}
sweatshirt := &Clothes{"толстовка", 3000.99, "Levi`s", "хлопок", "осень"}
products := []Product{potato, lipstick, sweatshirt}
fmt.Println("Товары")
fmt.Println("Общая стоимость:", CalculateProductsSum(products), "рублей")
for _, product := range products {
fmt.Println(product.GetInfo())
}

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

fmt.Println("Информация про товар толстовка")
fmt.Println("материал:", sweatshirt.GetMaterial())
fmt.Println("сезон:", sweatshirt.GetSeason())
fmt.Println("бренд:", sweatshirt.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
GetInfo() 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