-
Notifications
You must be signed in to change notification settings - Fork 112
lab7 #625
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
base: Moshkova_Elizaveta
Are you sure you want to change the base?
lab7 #625
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package lab7 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| type Drink struct { | ||
| Name string | ||
| Volume string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (d Drink) GetInfo() { | ||
| fmt.Println("В магазине продаётся", d.Name, "объёмом", d.Volume, ", ценой", d.Price, "руб.") | ||
| } | ||
|
|
||
| func (d Drink) GetPrice() float64 { | ||
| return d.Price | ||
| } | ||
|
|
||
| func (d *Drink) SetDiscount(x float64) { | ||
| (*d).Price = (d.Price / 100) * (100 - x) | ||
| } | ||
|
|
||
| func (d *Drink) EditPrice(x float64) { | ||
| (*d).Price = x | ||
| } | ||
|
|
||
| func (d *Drink) EditDescription(x string) { | ||
| (*d).Volume = x | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package lab7 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| type Lipstick struct { | ||
| Brand string | ||
| Color string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (l Lipstick) GetInfo() { | ||
| fmt.Println("В магазине продаётся", l.Color, l.Brand, "ценой", l.Price, "руб.") | ||
| } | ||
|
|
||
| func (l Lipstick) GetPrice() float64 { | ||
| return l.Price | ||
| } | ||
|
|
||
| func (l *Lipstick) SetDiscount(x float64) { | ||
| (*l).Price = (l.Price / 100) * (100 - x) | ||
| } | ||
|
|
||
| func (l *Lipstick) EditPrice(x float64) { | ||
| (*l).Price = x | ||
| } | ||
|
|
||
| func (l *Lipstick) EditDescription(x string) { | ||
| (*l).Color = x | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это не description |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package lab7 | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Toy struct { | ||
| Hero string | ||
| Size string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (t Toy) GetInfo() { | ||
| fmt.Println("В магазине продаётся", t.Hero, "размером", t.Size, ", ценой", t.Price, "руб.") | ||
| } | ||
|
|
||
| func (t Toy) GetPrice() float64 { | ||
| return t.Price | ||
| } | ||
|
|
||
| func (t *Toy) SetDiscount(x float64) { | ||
| (*t).Price = (t.Price / 100) * (100 - x) | ||
| } | ||
|
|
||
| func (t *Toy) EditPrice(x float64) { | ||
| (*t).Price = x | ||
| } | ||
|
|
||
| func (t *Toy) EditDescription(x string) { | ||
| (*t).Size = x | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это не description |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package lab7 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| type Product interface { | ||
| GetInfo() | ||
| GetPrice() float64 | ||
| SetDiscount(float64) | ||
| EditPrice(float64) | ||
| EditDescription(string) | ||
| } | ||
|
|
||
| func CalculatePrice(purchase []Product) float64 { | ||
| var total float64 = 0 | ||
| for _, price := range purchase { | ||
| total += price.GetPrice() | ||
| } | ||
| return total | ||
| } | ||
|
Comment on lines
+7
to
+21
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. отдельный файл с продуктом |
||
|
|
||
| func RunLab7() { | ||
| var drink Product = &Drink{"кола", "1.95 л", 160} | ||
| var toy Product = &Toy{"котик", "25 см", 1650} | ||
| var lipstick Product = &Lipstick{"NARS", "бардовая", 4700} | ||
|
Comment on lines
+24
to
+26
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это не должны быть продукты изначально |
||
| var purchase []Product = []Product{drink, toy, lipstick} | ||
|
|
||
| drink.GetInfo() | ||
| toy.GetInfo() | ||
| lipstick.GetInfo() | ||
|
|
||
| total := CalculatePrice(purchase) | ||
| fmt.Println("Общая стоимость товара:", total) | ||
|
|
||
| drink.EditPrice(190) | ||
| toy.EditDescription("1 м") | ||
| toy.SetDiscount(10) | ||
| lipstick.SetDiscount(5) | ||
| lipstick.EditDescription("алая") | ||
|
|
||
| drink.GetInfo() | ||
| toy.GetInfo() | ||
| lipstick.GetInfo() | ||
|
|
||
| total = CalculatePrice(purchase) | ||
| fmt.Println("Общая стоимость товара:", total) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,13 @@ import ( | |
| "isuct.ru/informatics2022/lab4" | ||
|
|
||
| "isuct.ru/informatics2022/lab6" | ||
| "isuct.ru/informatics2022/lab7" | ||
| ) | ||
|
|
||
| func main() { | ||
| fmt.Println("Мошкова Елизавета Алексеевна ") | ||
| lab6.RunLab6() | ||
| lab4.RunLab4() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лишнее |
||
| lab7.RunLab7() | ||
| lab4.RunLab4() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это не правильное название функции или должно быть поле описание