Moved to new folders

This commit is contained in:
2020-02-12 15:04:09 +01:00
parent 6645dca35f
commit 1a68ecad3d
162 changed files with 2 additions and 0 deletions

31
Oving9/Oving 9.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.271
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Oving 9", "Oving 9\Oving 9.vcxproj", "{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}"
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
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Debug|x64.ActiveCfg = Debug|x64
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Debug|x64.Build.0 = Debug|x64
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Debug|x86.ActiveCfg = Debug|Win32
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Debug|x86.Build.0 = Debug|Win32
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Release|x64.ActiveCfg = Release|x64
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Release|x64.Build.0 = Release|x64
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Release|x86.ActiveCfg = Release|Win32
{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBE7449-87B1-48E7-9388-D08CFDEE15D6}
EndGlobalSection
EndGlobal

39
Oving9/Oving 9/Dummy.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include "pch.h"
#include "Dummy.h"
void dummyTest()
{
Dummy a;
*a.num = 4;
Dummy b{ a };
Dummy c;
c = a;
cout << "a: " << *a.num << endl;
cout << "b: " << *b.num << endl;
cout << "c: " << *c.num << endl;
*b.num = 3;
*c.num = 5;
cout << "a: " << *a.num << endl;
cout << "b: " << *b.num << endl;
cout << "c: " << *c.num << endl;
cin.get();
}
Dummy::Dummy(const Dummy & other) : num{nullptr}
{
this->num = new int{};
*num = *other.num;
}
Dummy &Dummy::operator=(Dummy rhs)
{
swap(num, rhs.num);
return *this;
}

28
Oving9/Oving 9/Dummy.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include <iostream>
using namespace std;
class Dummy
{
public:
int *num;
Dummy()
{
num = new int{ 0 };
}
Dummy(const Dummy &other);
Dummy &operator=(Dummy rhs);
~Dummy()
{
delete num;
}
};
void dummyTest();

View File

@@ -0,0 +1,45 @@
#include "pch.h"
#include "Fibonacci.h"
void fillInFibonacciNumbers(int result[], int length)
{
int lo = 0;
int hi = 1;
int sum;
for (int i = 0; i < length; ++i)
{
result[i] = lo;
sum = lo + hi;
lo = hi;
hi = sum;
}
}
void printArray(int arr[], int length)
{
for (int i = 0; i < length; ++i)
{
cout << arr[i] << endl;
}
}
void createFibonacci()
{
int length;
cout << "How many fibonacci numbers? ";
cin >> length;
int *numbers = new int[length] {};
fillInFibonacciNumbers(numbers, length);
printArray(numbers, length);
delete[] numbers;
numbers = nullptr;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <iostream>
using namespace std;
void fillInFibonacciNumbers(int result[], int length);
void printArray(int arr[], int length);
void createFibonacci();

190
Oving9/Oving 9/Matrix.cpp Normal file
View File

@@ -0,0 +1,190 @@
#include "pch.h"
#include "Matrix.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
using namespace std;
/////////////
// Private //
/////////////
//Finds the longest number in the matrix
int Matrix::findLongestNumber() const
{
int longest = 0;
if (isValid())
{
int word;
ostringstream s;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
s << get(i, j);
word = s.str().length();
s.str("");
s.clear();
if (word > longest)
longest = word;
}
}
}
return longest;
}
////////////
// Public //
////////////
// Default
Matrix::Matrix()
{
matrix = nullptr;
rows = 0, cols = 0; // Illegal size
}
// General
Matrix::Matrix(const int nRows, const int nColumns)
{
// To make cleanup easier
rows = nRows;
cols = nColumns;
matrix = new double*[nRows] {}; // Create a list of pointers to array of ints
for (int i = 0; i < nRows; ++i)
{
matrix[i] = new double[nColumns] {0}; // Fill the list with an array of ints
for (int j = 0; j < nColumns; j++)
{
matrix[i][j] = 0;
}
}
}
// Identity-matrix
Matrix::Matrix(int nRows) : Matrix(nRows, nRows)
{
for (int i = 0; i < nRows; i++)
{
matrix[i][i] = 1; // Set the default diagonal to 1
}
}
// Set-get-functions
double Matrix::get(int row, int col) const
{
return matrix[row][col];
}
void Matrix::set(int row, int col, double value)
{
matrix[row][col] = value;
}
int Matrix::getRows() const
{
return rows;
}
int Matrix::getCols() const
{
return cols;
}
bool Matrix::isValid() const
{
if (matrix == nullptr || rows * cols == 0) // If the size is 0 in either direction, then the matrix is invalid
return false;
return true;
}
// Outsream-operator
ostream & operator<<(ostream & os, const Matrix & m)
{
if (m.isValid())
{
int width = m.findLongestNumber();
for (int i = 0; i < m.rows; i++)
{
for (int j = 0; j < m.cols; j++)
{
os << ' ' << setw(width) << m.get(i, j);
}
os << endl;
}
return os;
}
// If the matrix is non-valid, print this
return os << "The matrix is in an invalid state" << endl;
}
// Copy-constructor
Matrix::Matrix(const Matrix & rhs) : matrix{nullptr}
{
this->rows = rhs.rows; // Copy size
this->cols = rhs.cols; // Copy size
this->matrix = new double*[rhs.rows] {}; // Create a list of pointers to array of ints
for (int i = 0; i < this->rows; ++i)
{
matrix[i] = new double[this->cols] {0}; // Allocate the right amount of memory
for (int j = 0; j < this->cols; j++)
{
this->matrix[i][j] = rhs.matrix[i][j]; // Copy all values
}
}
}
// Copy-operator
Matrix & Matrix::operator=(Matrix rhs)
{
swap(rows, rhs.rows);
swap(cols, rhs.cols);
swap(matrix, rhs.matrix);
return *this;
}
// Add rhs to lhs (RightHandSide and LeftHandSide)
Matrix & Matrix::operator+=(const Matrix & rhs)
{
if (this->isValid() && rhs.isValid() && this->rows == rhs.rows && this->cols == rhs.cols)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
this->matrix[i][j] += rhs.get(i, j);
}
}
return *this;
}
this->matrix = nullptr;
return *this;
}
// Binary-add-operator
Matrix operator+(Matrix lhs, const Matrix & rhs)
{
lhs += rhs;
return lhs;
}
Matrix::~Matrix()
{
if (isValid())
{
for (int i = 0; i < rows; i++)
{
delete[] matrix[i]; // Delete all pointers to array of ints
}
delete[] matrix; // Delete all pointers to array of pointers
}
matrix = nullptr; // Sets the matrix to an illegal state
}

45
Oving9/Oving 9/Matrix.h Normal file
View File

@@ -0,0 +1,45 @@
#pragma once
#include <iostream>
using namespace std;
class Matrix
{
double **matrix; // Array of pointers to pointers
int rows, cols;
int findLongestNumber() const;
public:
// Constructors
Matrix(); // default
Matrix(const int nRows, const int nColumns); // Most common
explicit Matrix(int nRows); // Identity matrix
// Set-get
double get(int row, int col) const;
void set(int row, int col, double value);
int getRows() const;
int getCols() const;
// Check if matrix is valid
bool isValid() const;
// Out-operator
friend ostream& operator<<(ostream& os, const Matrix& m);
// Copy-operators
Matrix(const Matrix &rhs);
Matrix &operator=(Matrix rhs);
// Other operators
Matrix &operator+=(const Matrix &rhs);
friend Matrix operator+(Matrix lhs, const Matrix &rhs);
// Destructor
~Matrix();
};

121
Oving9/Oving 9/Oving 9.cpp Normal file
View File

@@ -0,0 +1,121 @@
// Oving 9.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include "Fibonacci.h"
#include "Matrix.h"
#include "Dummy.h"
using namespace std;
int main()
{
// createFibonacci();
/*
Matrix m1{ 10 };
Matrix m2{ m1 };
Matrix m3;
Matrix m4{ 4, 5 };
m3 = m2;
m1.set(0, 0, 2);
m3.set(0, 1, 10);
m2.set(0, 1, 42);
cout << m1 << endl;
cout << m2 << endl;
cout << m3 << endl;
m3 += m2;
cout << m3 << endl;
m3 += m4;
cout << m3 << endl;
*/
Matrix A{ 2,2 };
Matrix B{ 2,2 };
Matrix C{ 2,2 };
A.set(0, 0, 1);
A.set(0, 1, 2);
A.set(1, 0, 3);
A.set(1, 1, 4);
B.set(0, 0, 4);
B.set(0, 1, 3);
B.set(1, 0, 2);
B.set(1, 1, 1);
C.set(0, 0, 1);
C.set(0, 1, 3);
C.set(1, 0, 1.5);
C.set(1, 1, 2);
cout << A << endl;
cout << B << endl;
cout << C << endl;
A += B + C;
cout << A << endl;
cout << B << endl;
cout << C << endl;
#pragma region Task 3
/*
N<>r dummy kj<6B>rer vil det skrives ut:
"a: 4"
"b: 4"
"c: 4"
"a: 4"
"b: 3"
"c: 5"
*/
//dummyTest(); // Stemmer ikke overens med ovenfor
/* Skriver ut
"a: 4"
"b: 4"
"c: 4"
"a: 5"
"b: 5"
"c: 5"
*/
/* 3c)
Etter kopikonstrukt<6B>ren fungerer Dummy b
*/
/* 3d)
Etter =-operat<61>ren fungerer programmet som forventet
*/
#pragma endregion
return 0;
}

View File

@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{9A4AEA5B-40FF-4273-9277-F6866AC53A9D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Oving9</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Dummy.h" />
<ClInclude Include="Fibonacci.h" />
<ClInclude Include="Matrix.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Dummy.cpp" />
<ClCompile Include="Fibonacci.cpp" />
<ClCompile Include="Matrix.cpp" />
<ClCompile Include="Oving 9.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Fibonacci.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Matrix.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dummy.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Oving 9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Fibonacci.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Matrix.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Dummy.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

5
Oving9/Oving 9/pch.cpp Normal file
View File

@@ -0,0 +1,5 @@
// pch.cpp: source file corresponding to pre-compiled header; necessary for compilation to succeed
#include "pch.h"
// In general, ignore this file, but keep it around if you are using pre-compiled headers.

14
Oving9/Oving 9/pch.h Normal file
View File

@@ -0,0 +1,14 @@
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#ifndef PCH_H
#define PCH_H
// TODO: add headers that you want to pre-compile here
#endif //PCH_H

Binary file not shown.