-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -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) | ||
} | ||
|
This file contains 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 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 |
---|---|---|
@@ -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()) | ||
} |