Skip to content

Commit

Permalink
launching programs2
Browse files Browse the repository at this point in the history
  • Loading branch information
Agurchic committed Jan 22, 2025
1 parent 3f970f5 commit b2f9a5c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 86 deletions.
75 changes: 38 additions & 37 deletions golang/lab/lab4/lab4.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
package main

import (
"fmt"
"math"
"fmt"
"math"
)

func CalculateY(a, b, x float64) float64 {
return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2)
return math.Pow((a*x+b), 1.0/3.0) / math.Pow(math.Log10(x), 2)
}

func TaskA(a, b, xStart, xEnd, step float64) []float64 {
var result []float64
for x := xStart; x <= xEnd; x += step {
result = append(result, CalculateY(a, b, x))
}
return result
var result []float64
for x := xStart; x <= xEnd; x += step {
result = append(result, CalculateY(a, b, x))
}
return result
}

func TaskB(a, b float64, xValues []float64) []float64 {
var result []float64
for _, x := range xValues {
result = append(result, CalculateY(a, b, x))
}
return result
var result []float64
for _, x := range xValues {
result = append(result, CalculateY(a, b, x))
}
return result
}

func main() {
a := 2.0
b := 3.0

xStart := 1.0
xEnd := 5.0
step := 1.0
resultsA := TaskA(a, b, xStart, xEnd, step)
fmt.Println("Результаты TaskA:")
for i, y := range resultsA {
fmt.Printf("x = %.2f, y = %.6f\n", xStart+float64(i)*step, y)
}

fmt.Println()

xValues := []float64{1.5, 2.5, 3.5, 4.5}
resultsB := TaskB(a, b, xValues)
fmt.Println("Результаты TaskB:")
for i, y := range resultsB {
fmt.Printf("x = %.2f, y = %.6f\n", xValues[i], y)
}
fmt.Println()
x := 3.0
resultY := CalculateY(a, b, x)
fmt.Printf("Результат CalculateY: x= %.2f, y = %.6f\n", x, resultY)
a := 2.0
b := 3.0

xStart := 1.0
xEnd := 5.0
step := 1.0
resultsA := TaskA(a, b, xStart, xEnd, step)
fmt.Println("Результаты TaskA:")
for i, y := range resultsA {
fmt.Printf("x = %.2f, y = %.6f\n", xStart+float64(i)*step, y)
}

fmt.Println()

xValues := []float64{1.5, 2.5, 3.5, 4.5}
resultsB := TaskB(a, b, xValues)
fmt.Println("Результаты TaskB:")
for i, y := range resultsB {
fmt.Printf("x = %.2f, y = %.6f\n", xValues[i], y)
}
fmt.Println()
x := 3.0
resultY := CalculateY(a, b, x)
fmt.Printf("Результат CalculateY: x= %.2f, y = %.6f\n", x, resultY)
}

30 changes: 15 additions & 15 deletions golang/lab/lab6/lab6.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ package main
import "fmt"

type Dog struct {
Name string
Breed string
Age int
Name string
Breed string
Age int
}

func NewDog(name string, breed string, age int) Dog {
return Dog{Name: name, Breed: breed, Age: age}
return Dog{Name: name, Breed: breed, Age: age}
}
func (d Dog) GetAge() int {
return d.Age
return d.Age
}
func (d *Dog) SetAge(age int) {
d.Age = age
d.Age = age
}
func (d Dog) GetInfo() string {
return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age)
return fmt.Sprintf("Name: %s, Breed: %s, Age: %d", d.Name, d.Breed, d.Age)
}

func main() {
dog1 := NewDog("Buddy", "Golden Retriever", 3)
fmt.Println(dog1.GetInfo())
dog1 := NewDog("Buddy", "Golden Retriever", 3)
fmt.Println(dog1.GetInfo())

fmt.Println("Возраст:", dog1.GetAge())
dog1.SetAge(5)
fmt.Println("Новый возраст:", dog1.GetAge())
fmt.Println(dog1.GetInfo())
fmt.Println("Возраст:", dog1.GetAge())
dog1.SetAge(5)
fmt.Println("Новый возраст:", dog1.GetAge())
fmt.Println(dog1.GetInfo())

dog2 := NewDog("Bella", "Labrador", 7)
fmt.Println(dog2.GetInfo())
dog2 := NewDog("Bella", "Labrador", 7)
fmt.Println(dog2.GetInfo())
}
67 changes: 33 additions & 34 deletions golang/lab/lab7/lab7.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,77 @@
package main

import (
"fmt"
"fmt"
)

type Product interface {
GetPrice() float64
SetPrice(price float64)
ApplyDiscount(percent float64)
GetDetails() string
GetPrice() float64
SetPrice(price float64)
ApplyDiscount(percent float64)
GetDetails() string
}

type Book struct {
title string
author string
price float64
title string
author string
price float64
}

func (b *Book) GetPrice() float64 {
return b.price
return b.price
}

func (b *Book) SetPrice(price float64) {
b.price = price
b.price = price
}

func (b *Book) ApplyDiscount(percent float64) {
b.price -= b.price * percent / 100
b.price -= b.price * percent / 100
}

func (b *Book) GetDetails() string {
return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price)
return fmt.Sprintf("Book: %s, Author: %s, Price: %.2f", b.title, b.author, b.price)
}

type Electronics struct {
name string
brand string
price float64
name string
brand string
price float64
}

func (e *Electronics) GetPrice() float64 {
return e.price
return e.price
}

func (e *Electronics) SetPrice(price float64) {
e.price = price
e.price = price
}

func (e *Electronics) ApplyDiscount(percent float64) {
e.price -= e.price * percent / 100
e.price -= e.price * percent / 100
}
func (e *Electronics) GetDetails() string {
return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price)
return fmt.Sprintf("Electronics: %s, Brand: %s, Price: %.2f", e.name, e.brand, e.price)
}

func CalculateTotalPrice(products []Product) float64 {
total := 0.0
for _, product := range products {
total += product.GetPrice()
}
return total
total := 0.0
for _, product := range products {
total += product.GetPrice()
}
return total
}

func main() {
book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00}
electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00}
book := Book{title: "The Go Programming Language", author: "Alan Donovan", price: 50.00}
electronics := Electronics{name: "Laptop", brand: "XYZ", price: 1200.00}

fmt.Println(book.GetDetails())
fmt.Println(electronics.GetDetails())

products := []Product{&book, &electronics}
totalPrice := CalculateTotalPrice(products)
fmt.Printf("Общая стоимость: %.2f\n", totalPrice)
book.ApplyDiscount(10)
fmt.Println("Цена со скидкой:", book.GetDetails())
fmt.Println(book.GetDetails())
fmt.Println(electronics.GetDetails())

products := []Product{&book, &electronics}
totalPrice := CalculateTotalPrice(products)
fmt.Printf("Общая стоимость: %.2f\n", totalPrice)
book.ApplyDiscount(10)
fmt.Println("Цена со скидкой:", book.GetDetails())
}

0 comments on commit b2f9a5c

Please sign in to comment.