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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "Header.h"
Symbols::Symbols(string _str)
{
str = _str;
}

int Symbols::Length()
{
return str.length();
}

void Symbols::Decrement()
{
string NewStr = "";
int count = 1;
while (str[count] != '\0')
{
NewStr += str[count];
++count;
if (str[count] == '\0')
{
break;
}
++count;
}
str = NewStr;
}

string Symbols::GetData()
{
return str;
}

Numbers::Numbers(string _str)
{
str = _str;
}

int Numbers::Length()
{
return str.length();
}

void Numbers::Decrement()
{
string NewStr = "";
int count = 0;
while (str[count] != '\0')
{
NewStr += str[count];
++count;
if (str[count] == '\0')
{
break;
}
++count;
}
str = NewStr;
}

string Numbers::GetData()
{
return str;
}
66 changes: 66 additions & 0 deletions C# Labs 2 semester/6Lab_Programming_Polimorphism-master/Classes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;

namespace Lab6Polymorphism
{
abstract public class Lines
{
abstract public int Length();
abstract public void Decrement();
}
public class Symbols : Lines
{
private string str;
public Symbols(string _str)
{
str = _str;
}
public override int Length()
{
return str.Length;
}
public override void Decrement()
{
string NewStr = "";
int count = 1;
while (count < str.Length)
{
NewStr += str[count];
count += 2;
}
str = NewStr;
}
public string GetData()
{
return str;
}
}

public class Numbers : Lines
{
private string str;
public Numbers(string _str)
{
str = _str;
}
public override int Length()
{
return str.Length;
}
public override void Decrement()
{
string NewStr = "";
int count = 0;
while (count < str.Length)
{
NewStr += str[count];
count += 2;
}
str = NewStr;
}
public string GetData()
{
return str;
}
}

}
32 changes: 32 additions & 0 deletions C# Labs 2 semester/6Lab_Programming_Polimorphism-master/Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string>
#include <iostream>
using namespace std;

class Lines
{
public:
virtual int Length() = 0;
virtual void Decrement() = 0;
};

class Symbols : Lines
{
private:
string str;
public:
Symbols(string _str);
virtual int Length();
virtual void Decrement();
string GetData();
};

class Numbers : Lines
{
private:
string str;
public:
Numbers(string _str);
virtual int Length();
virtual void Decrement();
string GetData();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "Header.h"

int main()
{
string Str = "MilkShakeIt";
Symbols First(Str);
cout << Str << endl;
cout << First.Length() << endl;
First.Decrement();
cout << First.GetData() << "\n\n";

Str = "Amsterdam";
Numbers Second(Str);
cout << Str << endl;
cout << Second.Length() << endl;
Second.Decrement();
cout << Second.GetData() << "\n\n";
}

24 changes: 24 additions & 0 deletions C# Labs 2 semester/6Lab_Programming_Polimorphism-master/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Lab6Polymorphism
{
class Program
{
static void Main()
{
string Str = "Strawberry";
Symbols First = new Symbols(Str);
Console.WriteLine(Str);
Console.WriteLine(First.Length());
First.Decrement();
Console.WriteLine(First.GetData());

Str = "Banana";
Numbers Second = new Numbers(Str);
Console.WriteLine(Str);
Console.WriteLine(Second.Length());
Second.Decrement();
Console.WriteLine(Second.GetData());
}
}
}
30 changes: 30 additions & 0 deletions C# Labs 2 semester/7LabProgram-master/7LabProgramC++.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "Header.h"

int main()
{
double** array = new double* [4];
array[0] = new double[4]{ 2.4, 5.5, 3.8, -3 };
array[1] = new double[4]{ 0, 2.1, 8.4, 1.0 };
array[2] = new double[4]{ -8.6, 0, 5.5, 2 };
array[3] = new double[4]{ -1, 3, 2, 4 };

Expression exp1(array[0]);
Expression exp2(array[1]);
Expression exp3(array[2]);
Expression exp4(array[3]);
Expression* Exp = new Expression[4]{ exp1,exp2,exp3,exp4 };
double result;
for (int i = 0; i < 4; i++)
{
try
{
result = Exp[i].Calculation();
cout << result << endl;
}
catch (const char* error)
{
cout << error << endl;
}
cout << endl;
}
}
47 changes: 47 additions & 0 deletions C# Labs 2 semester/7LabProgram-master/Equation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

namespace Library
{
class Equation
{
private double a, b, c, d;

public Equation(double a, double b, double c, double d)
{
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}

public double Calculation()
{
try
{
double UpPart = 4 * Math.Log(a / b) + 1;
double DownPart = c + b - d + a;
if(DownPart == 0)
{
throw new Exception("Error: The subcortical expression less than 0");
}
else if (UpPart == 0 && b == 0)
{
throw new Exception("Error: Division by zero");
}
else if (a / b <= 0)
{
throw new Exception("Error: Used number in logarithm <= 0");
}
else
{
return UpPart / DownPart;
}
}
catch(Exception error)
{
Console.WriteLine(error.Message);
return 0;
}
}
}
}
43 changes: 43 additions & 0 deletions C# Labs 2 semester/7LabProgram-master/Expression.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "Header.h"

Expression::Expression(double* array)
{
a = array[0];
b = array[1];
c = array[2];
d = array[3];
}

double Expression::Calculation()
{
try
{
double UpPart = 4 * log(a / b) + 1;
double DownPart = c + b - d + a;
if (DownPart == 0)
{
throw ("Error: The subcortical expression less than 0");
}
else if (UpPart == 0 && b == 0)
{
throw ("Error: Division by zero");
}
else if (a / b <= 0)
{
throw ("Error: Used number in logarithm <= 0");
}
else
{
return UpPart / DownPart;
}
}
catch (const char* error)
{
cout << error << endl;
return 0;
}
}

Expression:: ~Expression()
{
}
12 changes: 12 additions & 0 deletions C# Labs 2 semester/7LabProgram-master/Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <cmath>
using namespace std;

class Expression
{
private: double a, b, c, d;
public:
Expression(double*);
double Calculation();
~Expression();
};
35 changes: 35 additions & 0 deletions C# Labs 2 semester/7LabProgram-master/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Library;
using System.Collections.Generic;

namespace _7LabProgram
{
class Program
{
static void Main(string[] args)
{
int n = 4;
var Equation = new List<Equation>(n)
{
new Equation(0.5, 6, 6, 1),
new Equation(0, -4, 9, 3),
new Equation(-8, 0, 5, 2),
new Equation(-1, 2, 3, 4)
};

for (int i = 0; i < n; i++)
{
try
{
double Result = Equation[i].Calculation();
Console.WriteLine($"{Result}");
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
Console.WriteLine();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_8LabProgram</RootNamespace>
</PropertyGroup>

</Project>
Loading