Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
49 changes: 37 additions & 12 deletions golang/lab4/Calculate.go

Choose a reason for hiding this comment

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

Давайте сделаем на 2 файла 8 лабу 1 и 2 части

Copy link
Author

Choose a reason for hiding this comment

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

Разделила на два файла

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package Lab4
package lab4

import (
"math"
"fmt"
"math"
"strconv"

"isuct.ru/informatics2022/lab8"
)

func Calculate(a,b,x float64) float64 {
Expand All @@ -18,19 +21,41 @@ func TaskA(a, b, x1, x2, dx float64) []float64 {
return y
}

func TaskB(a float64, b float64, x[5] float64) []float64 {
var y []float64
func TaskB(a float64, b float64, x[] float64) []float64 {
var arr []float64
for _, value := range x {
y = append(y, Calculate(a,b,value))
arr = append(arr, Calculate(a,b, value))
}
return y
return arr
}

func PrintValue(Values []float64) {
for _, value := range Values {
fmt.Println(value)
}
}

func ReadFileTask4() []float64 {
fmt.Println("Введите X1, X2, dX для задачи A и список значений для задачи B")
arr := lab8.RunLab8()
var numbers []float64
for _, values := range arr {
value, _ := strconv.ParseFloat(values, 64)
numbers = append(numbers, value)
}
return numbers
}


func RunLab4 () {
a := 1.1
b := 0.09

fmt.Println(TaskA(a,b,1.2,2.2,0.2))
var s = [5]float64{1.21,1.76,2.53,3.48,4.52}
fmt.Println(TaskB(a, b, s))
const a = 1.1
const b = 0.09
arr := ReadFileTask4()
slice := arr[3:]

ValuesA := TaskA(a, b, arr[0], arr[1], arr[2])
ValuesB := TaskB(a, b, slice)

PrintValue(ValuesA)
PrintValue(ValuesB)
}
30 changes: 30 additions & 0 deletions golang/lab7/Clothes.go
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
}
28 changes: 28 additions & 0 deletions golang/lab7/HouseholdGoods.go
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
}
29 changes: 29 additions & 0 deletions golang/lab7/PetFood.go
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
}
46 changes: 46 additions & 0 deletions golang/lab7/lab7.go
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)
}
84 changes: 84 additions & 0 deletions golang/lab8/lab8.go
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
}
}
}


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
}
4 changes: 2 additions & 2 deletions golang/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

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

func main() {
Lab4.RunLab4()
lab6.RunLab6()
lab7.RunLab7()

fmt.Println("Istomina_Elena_Sergeevna")
}
Expand Down
Loading