-
Notifications
You must be signed in to change notification settings - Fork 112
Istomina lab 8 #622
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
Open
HelenIstomina
wants to merge
28
commits into
ISUCT:Istomina_Elena
Choose a base branch
from
HelenIstomina:Istomina_lab_8
base: Istomina_Elena
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Istomina lab 8 #622
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
88a3d0e
Add files via upload
HelenIstomina d04c357
Update Clothes.go
HelenIstomina d974fb3
Update lab7
HelenIstomina 82251a9
Update lab7
HelenIstomina 3de0a0f
Update main.go
HelenIstomina 19cd740
Update lab7.go
HelenIstomina 201ddbf
Update lab7
HelenIstomina fc87ec0
Update lab7
HelenIstomina d193052
Update lab7
HelenIstomina dc4a099
Update lab7.go
HelenIstomina 0119a47
Add files via upload
HelenIstomina dfbcb45
Update lab8.go
HelenIstomina 15b6c43
Update lab8
HelenIstomina f2d46cd
Update lab8.go
HelenIstomina debe2ff
Update main.go
HelenIstomina 37c0e49
Update main.go
HelenIstomina 9d1365e
Update main.go
HelenIstomina 7a7518f
update lab8
HelenIstomina e78ab84
Delete golang/lab8/lab8-1.go
HelenIstomina 8a370f5
Update lab8_1.go
HelenIstomina f335374
Update lab8_2.go
HelenIstomina d02a28f
Update lab8_2.go
HelenIstomina b386c73
Update lab8_1.go
HelenIstomina a02f097
Update lab7.go
HelenIstomina c52e1d3
Update lab7.go
HelenIstomina 6876302
Update lab7.go
HelenIstomina ca2c5e6
Update lab7.go
HelenIstomina 61d96f8
Update lab7.go
HelenIstomina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package lab7 | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Dress struct { | ||
| Description string | ||
| Fabric string | ||
| Brand string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (f Dress) GetDescription() { | ||
| fmt.Println("Это", f.Description, "из", f.Fabric, "от бренда", f.Brand ,"стоимостью", f.Price) | ||
| } | ||
|
|
||
| func (f Dress) GetPrice() float64 { | ||
| return f.Price | ||
| } | ||
|
|
||
| func (f *Dress) ApplyDiscount(x float64) { | ||
| (*f).Price = (f.Price) * (x) | ||
| } | ||
|
|
||
| func (f *Dress) SetNewPrice(x float64) { | ||
| (*f).Price = x | ||
| } | ||
|
|
||
| func (f *Dress) SetNewDescription(x string) { | ||
| (*f).Fabric = x | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package lab7 | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Microwave_oven struct { | ||
| Name string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (f Microwave_oven) GetDescription() { | ||
| fmt.Println("Микроволновая печь", f.Name, "стоимостью", f.Price) | ||
| } | ||
|
|
||
| func (f Microwave_oven) GetPrice() float64 { | ||
| return f.Price | ||
| } | ||
|
|
||
| func (f *Microwave_oven) ApplyDiscount(x float64) { | ||
| (*f).Price = (f.Price) * (x) | ||
| } | ||
|
|
||
| func (f *Microwave_oven) SetNewPrice(x float64) { | ||
| (*f).Price = x | ||
| } | ||
|
|
||
| func (f *Microwave_oven) SetNewDescription(x string) { | ||
| (*f).Name = x | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package lab7 | ||
|
|
||
| import "fmt" | ||
|
|
||
| type CatFood struct { | ||
| Name string | ||
| Brand string | ||
| Price float64 | ||
| } | ||
|
|
||
| func (f CatFood) GetDescription() { | ||
| fmt.Println("Корм для кошек", f.Name, "от бренда", f.Brand, "он стоит", f.Price) | ||
| } | ||
|
|
||
| func (f CatFood) GetPrice() float64 { | ||
| return f.Price | ||
| } | ||
|
|
||
| func (f *CatFood) ApplyDiscount(x float64) { | ||
| (*f).Price = (f.Price) * (x) | ||
| } | ||
|
|
||
| func (f *CatFood) SetNewPrice(x float64) { | ||
| (*f).Price = x | ||
| } | ||
|
|
||
| func (f *CatFood) SetNewDescription(x string) { | ||
| (*f).Name = x | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package lab7 | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Product interface { | ||
| GetDescription() | ||
| GetPrice() float64 | ||
| ApplyDiscount(discount float64) | ||
| SetNewPrice(newPrice float64) | ||
| SetNewDescription(newDescription string) | ||
| } | ||
|
|
||
| func CalculatePrice(list []Product) float64 { | ||
| var sum float64 = 0 | ||
| for _, price := range list { | ||
| sum += price.GetPrice() | ||
| } | ||
| return sum | ||
| } | ||
|
|
||
| func RunLab7() { | ||
| var CatFood Product = &CatFood{"Orijen Cat&Kitten Grin Free", "Orijen", 9900} | ||
| var Microwave_oven Product = &Microwave_oven{"Hotpoint MWHA 201", 10490} | ||
| var Dress Product = &Dress{"гипюровое платье", "полиэстера", "DStrend", 5983} | ||
|
|
||
| CatFood.GetDescription() | ||
| Microwave_oven.GetDescription() | ||
| Dress.GetDescription() | ||
|
|
||
| var purchase []Product = []Product{CatFood, Microwave_oven, Dress} | ||
| sum := CalculatePrice(purchase) | ||
| fmt.Println("Общая стоимость списка товаров:", sum) | ||
|
|
||
| CatFood.SetNewPrice(9400) | ||
| Microwave_oven.SetNewDescription("Samsung") | ||
| Microwave_oven.ApplyDiscount(0.1) | ||
| Dress.ApplyDiscount(0.2) | ||
| Dress.SetNewDescription("хлопка") | ||
|
|
||
| CatFood.GetDescription() | ||
| Microwave_oven.GetDescription() | ||
| Dress.GetDescription() | ||
|
|
||
| sum = CalculatePrice(purchase) | ||
| fmt.Println("Общая стоимость списка товаров с учетом всех скидок:", sum) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package lab8 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| func CreateNewFile(name string) { | ||
| file, err := os.Create(name) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer file.Close() | ||
| } | ||
|
|
||
| func EditFile(name string, count int) { | ||
| var value string | ||
| file, err := os.OpenFile(name, os.O_RDWR, 0666) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer file.Close() | ||
| for i := 1; i <= count; i++ { | ||
| fmt.Print("Добавление в файл: ") | ||
| fmt.Fscan(os.Stdin, &value) | ||
| file.WriteString(value + "\n") | ||
| } | ||
| } | ||
|
|
||
| func ReadFile(name string) []string { | ||
| var arr []string | ||
| file, err := os.Open(name) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer file.Close() | ||
| for { | ||
| data := make([]byte, 64) | ||
| for { | ||
| n, err := file.Read(data) | ||
| if err == io.EOF { | ||
| break | ||
| } | ||
| arr = append(arr, string(data[:n])) | ||
| break | ||
| } | ||
| return arr | ||
| } | ||
| } | ||
|
|
||
| func SearchInFile(name string, ValueFile string) { | ||
| arr := strings.Split(ReadFile(name)[0], "\n") | ||
| for _, value := range arr { | ||
| if value == ValueFile { | ||
| fmt.Println("Значение в файле найдено") | ||
| break | ||
| } | ||
| } | ||
| } | ||
HelenIstomina marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| func RunLab8() []string { | ||
| var NameFile string | ||
| fmt.Print("Введите название файла: ") | ||
| fmt.Fscan(os.Stdin, &NameFile) | ||
| CreateNewFile(NameFile) | ||
|
|
||
| var Count int | ||
| fmt.Print("Введите сколько значений хотите занести в файл: ") | ||
| fmt.Fscan(os.Stdin, &Count) | ||
| EditFile(NameFile, Count) | ||
|
|
||
| arr := strings.Split(ReadFile(NameFile)[0], "\n") | ||
| arr = arr[0 : len(arr)-1] | ||
|
|
||
| var Search string | ||
| fmt.Print("Какое значение вы хотите найти в файле: ") | ||
| fmt.Fscan(os.Stdin, &Search) | ||
| SearchInFile(NameFile, Search) | ||
|
|
||
| return arr | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Давайте сделаем на 2 файла 8 лабу 1 и 2 части
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.
Разделила на два файла