0% found this document useful (0 votes)
4 views13 pages

Laba 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Laba 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Міністерство освіти і науки України

Національний університет «Львівська Політехніка»

Кафедра АСУ

Звіт до лабораторної роботи № 1

з дисципліни «Інноваційні інформаційні технології»


на тему:
«Структура класу та механізми доступу до його
компонентів»

Виконала:
Прийняла:

Львів – 2021
Мета: Вивчення базових елемент·в ООП (поняття класу, протоколу,
конструктора і т.д.) та їх застосування для розв"язку прикладних задач.
Варіант 8
Обчислити кут між двома n-мірними векторами, використавши два
означення скалярного добутку (див. лінійну алгебру ). Ввести в розгляд клас
Vector.

Код програми:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab1
{

public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
}
Vector A, B;
int n;
double[] mas1, mas2;
private void Form1_Load(object sender, EventArgs e)
{
n = 2;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;

textBox13.Visible = false;
textBox14.Visible = false;
textBox15.Visible = false;
textBox16.Visible = false;
textBox17.Visible = false;
textBox18.Visible = false;
textBox19.Visible = false;
textBox20.Visible = false;
}

private void button1_Click(object sender, EventArgs e)


{
A = new Vector(n);
B = new Vector(n);
mas1 = new double[n];
mas2 = new double[n];

if (n == 2)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
}
else if (n == 3)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
}
else if (n == 4)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);

}
else if (n == 5)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);

}
else if (n == 6)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);
mas1[5] = Convert.ToDouble(textBox6.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);
mas2[5] = Convert.ToDouble(textBox16.Text);

}
else if (n == 7)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);
mas1[5] = Convert.ToDouble(textBox5.Text);
mas1[6] = Convert.ToDouble(textBox6.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);
mas2[5] = Convert.ToDouble(textBox16.Text);
mas2[6] = Convert.ToDouble(textBox17.Text);

}
else if (n == 8)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);
mas1[5] = Convert.ToDouble(textBox6.Text);
mas1[6] = Convert.ToDouble(textBox7.Text);
mas1[7] = Convert.ToDouble(textBox8.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);
mas2[5] = Convert.ToDouble(textBox16.Text);
mas2[6] = Convert.ToDouble(textBox17.Text);
mas2[7] = Convert.ToDouble(textBox18.Text);

}
else if (n == 9)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);
mas1[5] = Convert.ToDouble(textBox6.Text);
mas1[6] = Convert.ToDouble(textBox7.Text);
mas1[7] = Convert.ToDouble(textBox8.Text);
mas1[8] = Convert.ToDouble(textBox9.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);
mas2[5] = Convert.ToDouble(textBox16.Text);
mas2[6] = Convert.ToDouble(textBox17.Text);
mas2[7] = Convert.ToDouble(textBox18.Text);
mas2[8] = Convert.ToDouble(textBox19.Text);
}
else if (n == 10)
{
mas1[0] = Convert.ToDouble(textBox1.Text);
mas1[1] = Convert.ToDouble(textBox2.Text);
mas1[2] = Convert.ToDouble(textBox3.Text);
mas1[3] = Convert.ToDouble(textBox4.Text);
mas1[4] = Convert.ToDouble(textBox5.Text);
mas1[5] = Convert.ToDouble(textBox6.Text);
mas1[6] = Convert.ToDouble(textBox7.Text);
mas1[7] = Convert.ToDouble(textBox8.Text);
mas1[8] = Convert.ToDouble(textBox9.Text);
mas1[9] = Convert.ToDouble(textBox10.Text);

mas2[0] = Convert.ToDouble(textBox11.Text);
mas2[1] = Convert.ToDouble(textBox12.Text);
mas2[2] = Convert.ToDouble(textBox13.Text);
mas2[3] = Convert.ToDouble(textBox14.Text);
mas2[4] = Convert.ToDouble(textBox15.Text);
mas2[5] = Convert.ToDouble(textBox16.Text);
mas2[6] = Convert.ToDouble(textBox17.Text);
mas2[7] = Convert.ToDouble(textBox18.Text);
mas2[8] = Convert.ToDouble(textBox19.Text);
mas2[9] = Convert.ToDouble(textBox20.Text);

Console.WriteLine("A");
A.SetPar(mas1);
double a= A.GetModul();
Console.WriteLine("B");
B.SetPar(mas2);

double cos = B.GetSkal(A)/ (A.GetModul() * B.GetModul());


textBox21.Text = A.GetModul()+"";
textBox22.Text = B.GetModul() + "";
textBox23.Text = B.GetSkal(A) + "";
//double reg = Math.Acos(cos);
//textBox24.Text = reg + "";
textBox24.Text = cos +"";

private void numericUpDown1_ValueChanged(object sender, EventArgs e)


{
decimal num = numericUpDown1.Value;
n = Convert.ToInt16(num);

textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
textBox10.Visible = false;

textBox13.Visible = false;
textBox14.Visible = false;
textBox15.Visible = false;
textBox16.Visible = false;
textBox17.Visible = false;
textBox18.Visible = false;
textBox19.Visible = false;
textBox20.Visible = false;

switch (num)
{
case 3:
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 4:

textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 5:

textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;

case 6:

textBox6.Visible = true;
textBox16.Visible = true;
textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 7:

textBox7.Visible = true;
textBox17.Visible = true;
textBox6.Visible = true;
textBox16.Visible = true;
textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 8:

textBox8.Visible = true;
textBox18.Visible = true;
textBox7.Visible = true;
textBox17.Visible = true;
textBox6.Visible = true;
textBox16.Visible = true;
textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 9:

textBox9.Visible = true;
textBox19.Visible = true;
textBox8.Visible = true;
textBox18.Visible = true;
textBox7.Visible = true;
textBox17.Visible = true;
textBox6.Visible = true;
textBox16.Visible = true;
textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
case 10:

textBox10.Visible = true;
textBox20.Visible = true;
textBox9.Visible = true;
textBox19.Visible = true;
textBox8.Visible = true;
textBox18.Visible = true;
textBox7.Visible = true;
textBox17.Visible = true;
textBox6.Visible = true;
textBox16.Visible = true;
textBox5.Visible = true;
textBox15.Visible = true;
textBox4.Visible = true;
textBox14.Visible = true;
textBox3.Visible = true;
textBox13.Visible = true;
break;
}
}
}

public class Vector


{
private double[] par;
private int n;
private double modul;

public Vector(decimal n)
{
this.n = Convert.ToInt16(n);
par = new double[this.n];
}
public void SetPar(double[] mas)
{
par = mas;
for(int i=0;i<n;i++)
Console.WriteLine(par[i]);
SetModul();
}
public void SetModul()
{
double var = 0;
for (int i = 0; i < n; i++)
{
var += par[i] * par[i];

modul = Math.Sqrt(var);
}
public double GetModul()
{
return modul;
}
public double[] GetPar()
{
return par;
}
public double GetSkal(Vector a)
{
double[] mas = a.GetPar();
double var = 0;
for (int i = 0; i < n; i++)
{
var += par[i] * mas[i];
}
return var;
}
}
}
Результат роботи програми:

Висновок: під час виконання даної лабораторної роботи було вивчено


базових елементів ООП (поняття класу, протоколу, конструктора і т.д.) та
їх застосування для розв"язку прикладних задач.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy