Skip to content
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
94 changes: 80 additions & 14 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,90 @@
using System;
using System;

namespace LabWork
namespace SinFunctionApp
{
// Даний проект є шаблоном для виконання лабораторних робіт
// з курсу "Об'єктно-орієнтоване програмування та патерни проектування"
// Необхідно змінювати і дописувати код лише в цьому проекті
// Відео-інструкції щодо роботи з github можна переглянути
// за посиланням https://www.youtube.com/@ViktorZhukovskyy/videos

class Result
{
// TODO: do it !
// Клас "Функція sin(ax + b)"
class SinFunction
{
public double a { get; set; }
public double b { get; set; }

public SinFunction(double a, double b)
{
this.a = a;
this.b = b;
}

// Обчислює значення функції в точці x
public double Evaluate(double x)
{
return Math.Sin(a * x + b);
}

// Амплітуда функції sin(ax + b) — дорівнює |a| (з математичної точки зору, множник перед sin не змінює амплітуду,
// але якщо мається на увазі a * sin(x + b), то амплітуда буде |a| — уточни за потреби)
public double GetAmplitude()
{
return Math.Abs(a);
}

// Введення коефіцієнтів функції
public void InputFunctionData()
{
Console.WriteLine("Enter coefficient a:");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter coefficient b:");
b = Convert.ToDouble(Console.ReadLine());
}

// Виведення даних про функцію
public void DisplayFunction()
{
Console.WriteLine($"Function: sin({a}x + {b})");
}
}

class Program
{
static void Main(string[] args)
{

Console.WriteLine("Hello World!");
Console.WriteLine("Enter the number of sin(ax + b) functions:");
int n = Convert.ToInt32(Console.ReadLine());

SinFunction[] functions = new SinFunction[n];

// Введення x — точки, в якій обчислюється значення функції
Console.WriteLine("Enter the point x at which to evaluate the functions:");
double x = Convert.ToDouble(Console.ReadLine());

// Введення даних для кожної функції
for (int i = 0; i < n; i++)
{
Console.WriteLine($"\nFunction #{i + 1}:");
functions[i] = new SinFunction(0, 0);
functions[i].InputFunctionData();
}

// Знаходимо функцію з найбільшим значенням у точці x
double maxValue = double.MinValue;
int maxIndex = -1;

for (int i = 0; i < n; i++)
{
double valueAtX = functions[i].Evaluate(x);
Console.WriteLine($"Value of function #{i + 1} at x = {x}: {valueAtX}");

if (valueAtX > maxValue)
{
maxValue = valueAtX;
maxIndex = i;
}
}

// Вивід результату
Console.WriteLine($"\nFunction #{maxIndex + 1} has the maximum value at x = {x}.");
functions[maxIndex].DisplayFunction();
Console.WriteLine($"Its amplitude is: {functions[maxIndex].GetAmplitude()}");
}
}
}

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/EBr0CZ_K)
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/wgWXpqsn)
# Методичні вказівки до виконання лабораторної роботи
## Тема: Масиви об’єктів
Expand Down