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

Added lab7 #436

Open
wants to merge 7 commits into
base: Rukina_Polina
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions golang/lab7/Cosmetic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lab7
import "fmt"

type Cosmetic struct {
Name string
Brend string
Price float32
}

func (c Cosmetic) GetInformation() {
fmt.Println("У нас есть в наличии", c.Name, "из бренда", c.Brend, "и стоит", c.Price)
}

func (c Cosmetic) GetPrice() float32 {
return c.Price
}

func (c *Cosmetic) ApplyDiscount(x float32) {
(*c).Price = (c.Price / 100) * (100 - x)
}

func (c *Cosmetic) ChangePrice(x float32) {
(*c).Price = x
}

func (c *Cosmetic) ChangeDescription(x string) {
(*c).Brend = x
}
1 change: 1 addition & 0 deletions golang/lab7/Informatics_2024
Submodule Informatics_2024 added at ea3aab
27 changes: 27 additions & 0 deletions golang/lab7/Sweets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lab7
import "fmt"
type Sweets struct {
Name string
Taste string
Price float32
}

func (s Sweets) GetInformation() {
fmt.Println("У нас есть в наличии", s.Name, "вкуса", s.Taste, "стоимостью", s.Price)
}

func (s Sweets) GetPrice() float32 {
return s.Price
}

func (s *Sweets) ApplyDiscount(x float32) {
(*s).Price = (s.Price / 100) * (100 - x)
}

func (s *Sweets) ChangePrice(x float32) {
(*s).Price = x
}

func (s *Sweets) ChangeDescription(x string) {
(*s).Taste = x
}
43 changes: 43 additions & 0 deletions golang/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lab7

import "fmt"

type Products interface {
GetInformation()
GetPrice() float32
ApplyDiscount(float32)
ChangePrice(float32)
ChangeDescription(string)
}


func CalculateBuy(list []Products) float32 {
var sum float32 = 0
for _, price := range list {
sum += price.GetPrice()
}
return sum
}

func RunLab7Tasks() {
var cosmetic Products = &Cosmetic{"помада", "Gucci", 5000}
var techcic Products = &Technic{"ноутбук", "Apple", 169660}
var sweets Products = &Sweets{"Сникерс", "Солёная карамель", 85}
cosmetic.GetInformation()
techcic.GetInformation()
sweets.GetInformation()
var buy []Products = []Products{cosmetic , techcic, sweets}
sum := CalculateBuy(buy)
fmt.Println("Товары стоят",sum)
techcic.ChangePrice(150000)
cosmetic.ChangeDescription("LV")
cosmetic.ApplyDiscount(5)
sweets.ApplyDiscount(60)
sweets.ChangeDescription("Белый шоколад")
techcic.GetInformation()
cosmetic.GetInformation()
sweets.GetInformation()

sum = CalculateBuy(buy)
fmt.Println("Товары стоят",sum)
}
27 changes: 27 additions & 0 deletions golang/lab7/technic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package lab7
import "fmt"
type Technic struct {
Name string
Brend string
Price float32
}

func (t Technic) GetInformation() {
fmt.Println("У нас есть в наличии", t.Name, "от компании", t.Brend, "и стоит", t.Price)
}

func (t Technic) GetPrice() float32 {
return t.Price
}

func (t *Technic) ApplyDiscount(x float32) {
(*t).Price = (t.Price / 100) * (100 - x)
}

func (t *Technic) ChangePrice(x float32) {
(*t).Price = x
}

func (t *Technic) ChangeDescription(x string) {
(*t).Brend = x
}
5 changes: 3 additions & 2 deletions golang/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

package main

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


func main() {
fmt.Println("Рукина Полина Владимировна")
lab4.RunLab4Tasks()
lab6.Runlab6()
}
lab7.RunLab7Tasks()
}
Loading