diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b56cba36d07e5106ecb63a5269b0f8a51e9f602c --- /dev/null +++ b/.gitignore @@ -0,0 +1,357 @@ +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.sln" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.sln" new file mode 100644 index 0000000000000000000000000000000000000000..520a7c53798878c12fc7fced43f37f76b6cae688 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.sln" @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30907.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Лабораторная работа №2", "Лабораторная работа №2\Лабораторная работа №2.vcxproj", "{B2B1102C-9898-4A3B-A121-691A80F4854A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Debug|x64.ActiveCfg = Debug|x64 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Debug|x64.Build.0 = Debug|x64 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Debug|x86.ActiveCfg = Debug|Win32 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Debug|x86.Build.0 = Debug|Win32 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Release|x64.ActiveCfg = Release|x64 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Release|x64.Build.0 = Release|x64 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Release|x86.ActiveCfg = Release|Win32 + {B2B1102C-9898-4A3B-A121-691A80F4854A}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E5EC4B0E-63C3-4B43-A496-DF85A80F49C7} + EndGlobalSection +EndGlobal diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.cpp" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..6828744648b352ceb6bdea04dd41f5a85f334549 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.cpp" @@ -0,0 +1,254 @@ +#include "Vector.h" +#include "CSRMatrix.h" + +//!!! Если параметров много, то они форматируются в столбик +CSRMatrix::CSRMatrix() + : elements(nullptr) + , columns(nullptr) + , rowPointers(nullptr) + , elementsSize(0) + , columnsSize(0) + , rowPointersSize(0) +{} + +// +CSRMatrix::CSRMatrix( + double *element, + int *column, + int *rowPointer, + size_t elementsSize, + size_t columnsSize, + size_t rowPointersSize) + : elementsSize(elementsSize) + , columnsSize(columnsSize) + , rowPointersSize(rowPointersSize) +{ + elements = new double[elementsSize]; + columns = new int[columnsSize]; + rowPointers = new int[rowPointersSize]; + for (int i = 0; i < elementsSize; ++i) + { + this->elements[i] = element[i]; + } + for (int i = 0; i < columnsSize; ++i) + { + this->columns[i] = column[i]; + } + for (int i = 0; i < rowPointersSize; ++i) + { + this->rowPointers[i] = rowPointer[i]; + } + std::cout << "\n" << " " << this << "\n"; +} + +// +CSRMatrix::CSRMatrix(const CSRMatrix& other) : elementsSize(other.elementsSize), columnsSize(other.columnsSize), rowPointersSize(other.rowPointersSize) +{ + elements = new double[elementsSize]; + columns = new int[columnsSize]; + rowPointers = new int[rowPointersSize]; + for (int i = 0; i < elementsSize; ++i) + { + this->elements[i] = other.elements[i]; + } + for (int i = 0; i < columnsSize; ++i) + { + this->columns[i] = other.columns[i]; + } + for (int i = 0; i < rowPointersSize; ++i) + { + this->rowPointers[i] = other.rowPointers[i]; + } + std::cout << "\n" << " ! " << this << "\n"; +} + +// +CSRMatrix::~CSRMatrix() +{ + delete[] elements; + delete[] columns; + delete[] rowPointers; + std::cout << "\n" << " ! " << this << "\n"; +} + +// , +size_t CSRMatrix::GetRows() const +{ + return rowPointersSize; +} + +// , +size_t CSRMatrix::GetColumns() const +{ + return columnsSize; +} + +// , +size_t CSRMatrix::NonZeroElements() const +{ + return elementsSize; +} + +// = +CSRMatrix& CSRMatrix::operator = (const CSRMatrix& other) +{ + if (this != &other) + { + //!!! Выделять память заново нужно только, если размеры не совпадают + + + if (this->elements != nullptr) //!!! Лишняя проврека + { + delete[] this->elements; + } + this->elementsSize = other.elementsSize; + this->elements = new double[other.elementsSize]; + for (int i = 0; i < elementsSize; ++i) + { + this->elements[i] = other.elements[i]; + } + + if (this->columns != nullptr) + { + delete[] this->columns; + } + this->columnsSize = other.columnsSize; + this->columns = new int[other.columnsSize]; + for (int i = 0; i < columnsSize; ++i) + { + this->columns[i] = other.columns[i]; + } + + if (this->rowPointers != nullptr) + { + delete[] this->rowPointers; + } + this->rowPointersSize = other.rowPointersSize; + this->rowPointers = new int[other.rowPointersSize]; + for (int i = 0; i < rowPointersSize; ++i) + { + this->rowPointers[i] = other.rowPointers[i]; + } + } + std::cout << "\n" << " = " << this << "\n"; //!!! Убрать + return *this; +} + +// ( ) +CSRMatrix CSRMatrix::operator*(double value) const +{ + //!!! Почему изменяется первый операнд + + for (int i = 0; i < elementsSize; ++i) + { + this->elements[i] *= value; + } + return *this; +} + +// ( ) +CSRMatrix operator *(double value, const CSRMatrix& matrix) +{ + CSRMatrix temp(matrix); + for (int i = 0; i < temp.elementsSize; ++i) + { + temp.elements[i] *= value; + } + return temp; +} + +// +Vector CSRMatrix::operator*(const Vector& vector) const +{ + int size = vector.getsize(); + if (rowPointersSize - 1 != size) + { + throw InCompatibleDimException(); + } + Vector temp(size); + for (int row = 0; row < size; ++row) { + for (int i = rowPointers[row]; i < rowPointers[row + 1]; ++i) + { + temp[row] += elements[i] * elements[columns[i]]; + } + } + return temp; + +} + +// +Vector operator*(const Vector& vector, const CSRMatrix& matrix) +{ + int matrixSize = matrix.GetRows()-1; + int vectorSize = vector.getsize(); + Vector temp(matrixSize); + if (matrixSize != vectorSize) + { + throw InCompatibleDimException(); + } + for (int row = 0; row < matrixSize; ++row) + { + for (int i = matrix.rowPointers[row]; i < matrix.rowPointers[row + 1]; ++i) + { + temp[matrix.columns[i]] += matrix.elements[i] * vector[row]; //!!! Сомнительно + } + } + return temp; +} + +// +std::istream& operator >> (std::istream& in, CSRMatrix& matrix) +{ + //!!! Оператор должен спросить у пользователя новый размер и, + //!!! если он отличен от страрого, очистить память и выделить новую + + + std::cout << " " << "\n"; + for (int i = 0; i > matrix.elements[i]; + } + std::cout << " , " << "\n"; + for (int i = 0; i < matrix.columnsSize; ++i) + { + in >> matrix.columns[i]; + } + std::cout << " " << "\n"; + for (int i = 0; i < matrix.rowPointersSize; ++i) + { + in >> matrix.rowPointers[i]; + } + return in; +} + +// +std::ostream& operator <<(std::ostream& out, const CSRMatrix& matrix) +{ + //!!! НА ЗАЩИТУ: + //!!! Реализовать данный оператор для вывода полной матрицы (со всеми нулями), + //!!! но БЕЗ выделения памяти под всю матрицу + + for (int i = 0; i < matrix.elementsSize; ++i) + { + out << matrix.elements[i] << " "; + } + std::cout << " \n"; //!!! Что тут делает std::cout ? + + for (int i = 0; i < matrix.columnsSize; ++i) + { + out << matrix.columns[i] << " "; + } + std::cout << " , \n";//!!! Что тут делает std::cout ? + + for (int i = 0; i < matrix.rowPointersSize; ++i) + { + out << matrix.rowPointers[i] << " "; + } + std::cout << " \n";//!!! Что тут делает std::cout ? + return out; +} + + + + + diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.h" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.h" new file mode 100644 index 0000000000000000000000000000000000000000..7e3c352ff36016b00eeaa1681b8d39f6acb6fa1e --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/CSRMatrix.h" @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include +#include +#include "Exception.h" + +class Vector; +class CSRMatrix +{ +private: + int* columns; + int* rowPointers; + size_t elementsSize; + size_t columnsSize; + size_t rowPointersSize; + double* elements; +public: + CSRMatrix(); + CSRMatrix(double* element, int * column, int* rowPointer, size_t elementsSize, size_t columnsSize, size_t rowPointersSize);// + CSRMatrix(const CSRMatrix& other); + ~CSRMatrix(); + + CSRMatrix& operator = (const CSRMatrix& matrix); + CSRMatrix operator *(double value) const; + + friend CSRMatrix operator *(double value, const CSRMatrix& matrix); + Vector operator*(const Vector& vector) const; + friend Vector operator*(const Vector& vector, const CSRMatrix& matrix); + friend std::ostream& operator<<(std::ostream& output, const CSRMatrix& matrix); + friend std::istream& operator>>(std::istream& input, CSRMatrix& matrix); + + size_t GetRows() const; + size_t GetColumns() const; + size_t NonZeroElements() const; +}; + + + diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.cpp" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..22504544a232b1b962efce1915808f37380fb37e --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.cpp" @@ -0,0 +1,17 @@ +#include "Exception.h" +#include +#include + +OutOfRangeException::OutOfRangeException() :error_message(" ") {}; + +const char* OutOfRangeException::what() const throw() +{ + return error_message.c_str(); +} + +InCompatibleDimException::InCompatibleDimException() :error_message(" ") {}; + +const char* InCompatibleDimException::what() const throw() +{ + return error_message.c_str(); +} diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.h" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.h" new file mode 100644 index 0000000000000000000000000000000000000000..8eaae4926a672fcecda8cb5cb93dafb5d19fee7a --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Exception.h" @@ -0,0 +1,21 @@ +#pragma once +#include +#include + +class OutOfRangeException : public std::exception +{ +private: + std::string error_message; +public: + OutOfRangeException(); + virtual const char* what() const throw(); +}; + +class InCompatibleDimException : public std::exception +{ +private: + std::string error_message; +public: + InCompatibleDimException(); + virtual const char* what() const throw(); +}; diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.cpp" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..ceb5111b8662c2630f20718ca88f4aba346f32b8 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.cpp" @@ -0,0 +1,303 @@ +#include "Vector.h" +#include "CSRMatrix.h" +// +Vector::Vector() : vectorsize(0), vector(nullptr) {} + +// +Vector::Vector(size_t vectorsize) : vectorsize(vectorsize), vector(new double[vectorsize]) +{ + for (int i = 0; i < vectorsize; ++i) + { + vector[i] = 0; + } +} + +// +Vector::Vector(size_t vectorsize, double startingvalue) : vectorsize(vectorsize), vector(new double[vectorsize])// , +{ + for (int i = 0; i < vectorsize; ++i) + { + vector[i] = startingvalue; + } + std::cout << "\n" << " " << this << "\n"; //!!! Это зачем тут нужно? +} + +// +Vector::Vector(const Vector& other) : vectorsize(other.vectorsize), vector(new double[other.vectorsize]) +{ + for (int i = 0; i < other.vectorsize; ++i) + { + this->vector[i] = other.vector[i]; + } + std::cout << "\n" << " ! " << this << "\n"; //!!! Это зачем тут нужно? +} + +// +Vector::~Vector() +{ + delete[]vector; + std::cout << "\n" << " ! " << this << "\n";//!!! Это зачем тут нужно? +} + +// + +// = ( ) +Vector& Vector::operator = (const Vector& other) +{ + std::cout << "\n" << " = " << this << "\n";//!!! Это зачем тут нужно? + + //!!! Гже проверка на самоприсваивание? + + this->vectorsize = other.vectorsize; + + + //!!! Выделять память заново нужно только, если размеры не совпадают + + if (this->vector != nullptr) //!!! Это необязательно - delete для nullptr - не ошибка + { + delete[] this->vector; + } + + this->vector = new double[other.vectorsize]; + + + for (int i = 0; i < other.vectorsize; ++i) + { + this->vector[i] = other.vector[i]; + } + + return *this; +} + +// +Vector& Vector::operator ++ () +{ + for (int i = 0; i < vectorsize; ++i) + { + this->vector[i] += 1; // this->vector[i]++; + } + return *this; +} + +// +Vector Vector::operator ++ (int value) +{ + Vector temp(*this); // + for (int i = 0; i < vectorsize; ++i) + { + this->vector[i] += 1; // this->vector[i]++; + } + return temp; +} + +// +Vector& Vector::operator -- () +{ + for (int i = 0; i < vectorsize; ++i) + { + this->vector[i] -= 1; + } + return *this; +} + +// +Vector Vector:: operator --(int value) +{ + Vector temp(*this); + for (int i = 0; i < vectorsize; ++i) + { + this->vector[i] -= 1; + } + return temp; +} + +// [] +double& Vector::operator[](size_t index) +{ + return vector[index]; +} + +const double& Vector::operator [](size_t index) const +{ + return vector[index]; +} + +// +Vector Vector::operator + (const Vector& other) +{ + if (this->vectorsize != other.vectorsize) + { + throw OutOfRangeException(); + } + else + { + Vector temp(this->vectorsize, 0); + for (int i = 0; i < this->vectorsize; ++i) + { + temp.vector[i] = this->vector[i] + other.vector[i]; + } + return temp; + } +} + +// +Vector Vector::operator - (const Vector& other) +{ + if (this->vectorsize != other.vectorsize) + { + throw OutOfRangeException(); + } + else + { + Vector temp(this->vectorsize, 0); + for (int i = 0; i < this->vectorsize; ++i) + { + temp.vector[i] = this->vector[i] - other.vector[i]; + } + return temp; + } +} + +// += +Vector& Vector::operator += (const Vector& other) +{ + if (this->vectorsize != other.vectorsize) + { + throw OutOfRangeException(); + } + else + { + for (int i = 0; i < this->vectorsize; ++i) + { + this->vector[i] += other.vector[i]; + } + return *this; + } +} + +// -= +Vector& Vector::operator -= (const Vector& other) +{ + if (this->vectorsize != other.vectorsize) + { + throw OutOfRangeException(); + } + else + { + for (int i = 0; i < this->vectorsize; ++i) + { + this->vector[i] -= other.vector[i]; + } + return *this; + } +} + +// += double +Vector& Vector::operator += (double other) +{ + for (int i = 0; i < this->vectorsize; ++i) + { + this->vector[i] += other; + } + return *this; +} + +// -= double +Vector& Vector::operator -= (double other) +{ + for (int i = 0; i < this->vectorsize; ++i) + { + this->vector[i] -= other; + } + return *this; +} + +// +Vector Vector::operator *(double value) const +{ + //!!! Почему при произведении на число изменяется первый операнд? + + for (int i = 0; i < this->vectorsize; ++i) + { + this->vector[i] *= value; + } + return *this; +} + +// +double Vector::operator *(const Vector& other) +{ + double multiplication = 0; //!!! После else + + if (this->vectorsize != other.vectorsize) + { + throw OutOfRangeException(); + } + else + { + for (int i = 0; i < this->vectorsize; ++i) + { + multiplication += this->vector[i] * other.vector[i]; + } + return multiplication; + } +} + +// +Vector ::operator double* () const +{ + return vector; +} + +// +size_t Vector::getsize() const +{ + return vectorsize; +} + +// +double Vector::VectorLength() const +{ + double sum = 0; + for (int i = 0; i < vectorsize; ++i) + { + sum += vector[i] * vector[i]; + } + return sqrt(sum); +} + +// +Vector operator *(double value, const Vector& vector) +{ + Vector temp(vector); + for (int i = 0; i < temp.vectorsize; ++i) + { + temp.vector[i] = value * temp.vector[i]; + } + return temp; +} + +// +std::ostream& operator <<(std::ostream& out, const Vector& vector) +{ + for (size_t i = 0; i < vector.vectorsize; ++i) + { + out << vector[i] << " "; + } + return out;// +} + +// +std::istream& operator >> (std::istream& in, Vector& vector) +{ + //!!! Оператор должен спросить у пользователя новый размер и, + //!!! если он отличен от страрого, очистить память и выделить новую + + for (size_t i = 0; i < vector.getsize(); ++i) + { + in >> vector[i]; + } + return in; +} + +// diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.h" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.h" new file mode 100644 index 0000000000000000000000000000000000000000..404a9a9ee80941e5f5c00b007ee3739579fe57ec --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/Vector.h" @@ -0,0 +1,50 @@ +#pragma once +#include +#include +#include +#include +#include +#include "Exception.h" + +class CSRMatrix; +class Vector +{ +private: + double* vector; + size_t vectorsize; +public: + Vector(); + explicit Vector(size_t vectorsize); + Vector(size_t vectorsize, double startingvalue); + Vector(const Vector& other); + ~Vector(); + + Vector& operator ++ (); + Vector operator ++ (int value); + Vector& operator -- (); + Vector operator -- (int value); + Vector& operator = (const Vector& other); + Vector operator + (const Vector& other); + Vector operator - (const Vector& other); + Vector& operator += (const Vector& other); + Vector& operator -= (const Vector& other); + Vector& operator += (double other); + Vector& operator -= (double other); + Vector operator *(double value) const; + double operator *(const Vector& other); + explicit operator double* () const; + double& operator[](size_t index); + const double& operator [](size_t index) const; + + size_t getsize() const; + double VectorLength() const; + + friend std::ostream& operator <<(std::ostream& out, const Vector& vector); + friend Vector operator *(double value, const Vector& vector); + +}; + + + + + diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/main.cpp" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..dcd53ddae4d3fea8c4608d28ee5677d41d41f3bb --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/main.cpp" @@ -0,0 +1,144 @@ +#include "Vector.h" +#include "CSRMatrix.h" +#include "Exception.h" + + +int main() +{ + setlocale(LC_ALL, "russian"); + try + { + std::cout << " " << "\n"; + std::cout << " :\n"; + std::cout << " 1\n"; + int size1 = 0; + std::cin >> size1; + Vector a(size1, 0); + std::cout << " 1\n"; + for (int i = 0; i < size1; ++i) + { + std::cin >> a[i]; + } + std::cout << " 1:\n"; + std::cout << a << "\n"; + std::cout << " 2\n"; + int size2 = 0; + std::cin >> size2; + Vector b(size2, 0); + std::cout << " 2\n"; + for (int i = 0; i < size2; ++i) + { + std::cin >> b[i]; + } + std::cout << " 2:\n"; + std::cout << b; + std::cout << "\n\n :\n"; + std::cout << " " << " " << a.VectorLength() << ", " << " " << " " << b.VectorLength() << "\n\n"; + std::cout << " " << "\n"; + std::cout << " " << " " << a.getsize() << ", " << " " << " " << b.getsize() << "\n\n"; + std::cout << " " << "\n\n"; + std::cout << " :" << "\n"; + double multiplication = 0; + multiplication = a * b; + std::cout << " " << " " << multiplication << "\n"; + std::cout << "\n ( ):" << "\n"; + b = ++a; + std::cout << " :" << "\n"; + std::cout << "a ---> " << a << "\n"; + std::cout << "b ---> " << b << "\n"; + b = a++; + std::cout << " :" << "\n"; + std::cout << "a ---> " << a << "\n"; + std::cout << "b ---> " << b << "\n"; + b = --a; + std::cout << " :" << "\n"; + std::cout << "a ---> " << a << "\n"; + std::cout << "b ---> " << b << "\n"; + b = a--; + std::cout << " :" << "\n"; + std::cout << "a ---> " << a << "\n"; + std::cout << "b ---> " << b << "\n"; + std::cout << "\n :\n"; + a = a + b; + std::cout << "\n " << a << "\n"; + std::cout << "\n :\n"; + a = a - b; + std::cout << "\n " << a << "\n"; + std::cout << "\n += :\n"; + a += b; + std::cout << "\n " << a << "\n"; + std::cout << "\n -= :\n"; + a -= b; + std::cout << "\n " << a << "\n"; + + std::cout << "\n += :\n"; + a += 10; + std::cout << "\n " << a << "\n"; + std::cout << "\n -= :\n"; + a -= 10; + std::cout << "\n " << a << "\n"; + std::cout << "a ---> " << a << "\n"; + std::cout << "b ---> " << b << "\n"; + std::cout << " :\n"; + a = a * 5.0; + std::cout << " : " << a << "\n"; + a = 5.0 * a; + std::cout << " : " << a << "\n"; + // + std::cout << "\n\n \n"; + std::cout << " :\n"; + size_t elementsSize = 0; + std::cin >> elementsSize; + size_t columnsSize = elementsSize; + std::cout << " .\n"; + size_t rowPointersSize = 0; + std::cout << " :\n"; + std::cin >> rowPointersSize; + double* elements = new double[elementsSize]; + int* columns = new int[columnsSize]; + int* rowPointers = new int[rowPointersSize]; + std::cout << " \n"; + for (int i = 0; i < elementsSize; ++i) + { + std::cin >> elements[i]; + } + std::cout << " \n"; + for (int i = 0; i < columnsSize; ++i) + { + std::cin >> columns[i]; + } + std::cout << " \n"; + for (int i = 0; i < rowPointersSize; ++i) + { + std::cin >> rowPointers[i]; + } + CSRMatrix matrix1(elements, columns, rowPointers, elementsSize, columnsSize, rowPointersSize); + std::cout << " :\n"; + std::cout << matrix1; + std::cout << " , \n"; + std::cout << " : " << matrix1.NonZeroElements() << "\n: " << matrix1.GetColumns() << "\n: " << matrix1.GetRows() << "\n"; + std::cout << " ( ) :\n"; + matrix1 = matrix1 * 5.0; + std::cout << " :\n" << matrix1 << "\n"; + matrix1 = 5.0 * matrix1; + std::cout << " :\n" << matrix1 << "\n"; + std::cout << " :\n"; + a = a * matrix1; + std::cout << " : " << a << "\n"; + a = matrix1 * a; + std::cout << " : " << a << "\n"; + std::cout << " :\n"; + Vector c(b); + std::cout << c << "\n"; + c = b*(-6) + (b*matrix1)+a; + std::cout <<" "<< c << "\n"; + } + catch (const std::exception& exception) + { + std::cout << " : " << exception.what() << "\n"; + return -1; + } + + + return 0; +} \ No newline at end of file diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj" new file mode 100644 index 0000000000000000000000000000000000000000..89c3eac39384fe63eda9db54363f6cfb8c962243 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj" @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {b2b1102c-9898-4a3b-a121-691a80f4854a} + Лабораторнаяработа2 + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj.filters" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj.filters" new file mode 100644 index 0000000000000000000000000000000000000000..37c9453e18882022a73fd04374877466cfeacd0c --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 \342\204\2262.vcxproj.filters" @@ -0,0 +1,42 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + \ No newline at end of file