Skip to content
Open

Laba7 #635

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
25 changes: 25 additions & 0 deletions golang/lab7/Car.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package lab7

type Car struct {
name string
price float64
model string
color string

}

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

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

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

func (c *Car) ApplyDiscount(discount float64) {
c.price -= c.price * discount / 100
}
24 changes: 24 additions & 0 deletions golang/lab7/Fruit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lab7

type Fruit struct {
Name string
Price float64
Freshness string
Color string
}

func (f *Fruit) GetName() string {
return f.Name
}

func (f Fruit) GetPrice() float64 {
return f.Price
}

func (f *Fruit) SetPrice(price float64) {
f.Price = price
}

func (f *Fruit) ApplyDiscount(discount float64) {
f.Price -= f.Price * discount / 100
}
24 changes: 24 additions & 0 deletions golang/lab7/Mobile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lab7

type Mobile struct {
Name string
Price float64
Brand string
Color string
}

func (m *Mobile) GetName() string {
return m.Name
}

func (m *Mobile) GetPrice() float64 {
return m.Price
}

func (m *Mobile) SetPrice(price float64) {
m.Price = price
}

func (m *Mobile) ApplyDiscount(discount float64) {
m.Price -= m.Price * discount / 100
}
8 changes: 8 additions & 0 deletions golang/lab7/Product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package lab7

type Product interface {
GetName() string
GetPrice() float64
SetPrice(price float64)
ApplyDiscount(discount float64)
}
24 changes: 24 additions & 0 deletions golang/lab7/laba7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lab7

import "fmt"

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

func Lab7() {
Mobile := &Mobile{"Айфон 11 pro max", 50000, "Iphone", "gold"}
Fruit := &Fruit{"Манго", 250, "свежее", "yellow"}
Car := &Car{"Reno Logan", 500000, "Reno", "black"}
products := []Product{Mobile, Fruit, Car}
fmt.Println("Стоимость без скидок:", GetTotalPrice(products))

Mobile.ApplyDiscount(25)
Fruit.ApplyDiscount(40)
Car.ApplyDiscount(10)
fmt.Println("Стоимость после учёта скидки:", GetTotalPrice(products))
}
15 changes: 8 additions & 7 deletions golang/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main

import (
"fmt"
"isuct.ru/informatics2022/lab6"
"isuct.ru/informatics2022/lab4"

"fmt"

"isuct.ru/informatics2022/lab7"
)
func main() {
fmt.Println("Лахтин Максим Сергеевич")
lab4.RunLab4()
lab6.RunLab6()
Comment on lines -9 to -11
Copy link
Collaborator

Choose a reason for hiding this comment

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

прошлые лабы не нужно удалять

}
fmt.Println("Лаборатнорная 7:")
lab7.Lab7()
}

Loading