diff --git a/.gitignore b/.gitignore index 259148f..d25420c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,336 @@ *.exe *.out *.app + +# Visual Studio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# 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 + +# 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/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.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 + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# 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 +# 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 + +# 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 + +# 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/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# 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/ + diff --git a/Øving 2/Øving 2/Øving 2.sln b/Øving 2/Øving 2/Øving 2.sln new file mode 100644 index 0000000..dc4394d --- /dev/null +++ b/Øving 2/Øving 2/Øving 2.sln @@ -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}") = "Øving 2", "Øving 2\Øving 2.vcxproj", "{7846FDBB-329B-4890-A7F4-1868D36342FB}" +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 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Debug|x64.ActiveCfg = Debug|x64 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Debug|x64.Build.0 = Debug|x64 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Debug|x86.ActiveCfg = Debug|Win32 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Debug|x86.Build.0 = Debug|Win32 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Release|x64.ActiveCfg = Release|x64 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Release|x64.Build.0 = Release|x64 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Release|x86.ActiveCfg = Release|Win32 + {7846FDBB-329B-4890-A7F4-1868D36342FB}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3E25C138-47B4-4BF9-BAAE-D9030FE6432F} + EndGlobalSection +EndGlobal diff --git a/Øving 2/Øving 2/Øving 2/main.cpp b/Øving 2/Øving 2/Øving 2/main.cpp new file mode 100644 index 0000000..fb307a7 --- /dev/null +++ b/Øving 2/Øving 2/Øving 2/main.cpp @@ -0,0 +1,232 @@ +#include "std_lib_facilities.h" + +#pragma region Oppgave 1 og 2 + + +void inputAndPrintInteger() { + cout << "Skriv inn et tall: "; + int input = 0; cin >> input; + cout << "Du skrev: " << input << "\n"; +} + + +int inputInteger() { + cout << "Skriv inn et tall: "; + int input = 0; cin >> input; + return input; +} + +void inputIntegersAndPrintSum() { + int a = inputInteger(); + int b = inputInteger(); + int number = a + b; + cout << "Summen av tallene: " << number << "\n"; +} + +bool IsOdd(int number) { + if (number % 2) + return true; + return false; +} + +void printHumanReadableTime(int seconds) { + int minSek = 60, timeSek = pow(minSek,2); + int timer = seconds / timeSek; + int timeLeft = seconds - timer * timeSek; + int minutter = timeLeft / minSek; + timeLeft = timeLeft - minutter * minSek; + cout << timer << " timer, " << minutter << " minutter, " << timeLeft << " sekunder" << "\n"; +} + +void inputIntegersUsingLoopAndPrintSum() { + int sum = 0; + int innlest = 0; + while (true) { + innlest = inputInteger(); + if (innlest == 0) + break; + sum += innlest; + } + cout << "Summen er: " << sum << "\n"; +} + +double inputDouble() { + double inndata = 0.0; + cout << "Skriv inn et desimaltall: "; + cin >> inndata; + return inndata; +} + +void NOKtoEUR(double eurValue = 9.75) { + double nok = inputDouble(); + while (nok < 0) + { + cout << "Tallet er negativt, skriv inn et positivt tall." << endl; + nok = inputDouble(); + } + cout << nok << " kroner er " << (nok / eurValue) << " euro." << endl; +} + + +#pragma endregion + +#pragma region Oppgave 3 + +void Gangetabell(int width, int height) { + string leng = std::to_string(width * height); + for (int i = 1; i <= width; i++) { + for (int j = 1; j <= height; j++) { + cout << setw(leng.length() + 1) << i * j; + } + cout << endl; + } +} + +void DrawGangetabell() { + int width = 0, height = 0; + cout << "Skriv inn bredden på gangetabellen: "; + cin >> width; + cout << "Skriv inn høyden på gangetabellen: "; + cin >> height; + Gangetabell(width, height); +} +#pragma endregion + +#pragma region Oppgave 4 + +double Discriminant(double a, double b, double c) { + return pow(b, 2) - (4 * a * c); +} + +void PrintRealRoots(double a, double b, double c) { + double disc = Discriminant(a, b, c); + if (disc > 0) { + double solved1 = (-b + sqrt(disc)) / (2 * a); + double solved2 = (-b - sqrt(disc)) / (2 * a); + cout << "The solutions are x_1 = " << solved1 << " and x_2 = " << solved2 << endl; + } + else if (disc == 0) + cout << "The solution are x = " << (-b / (2 * a)) << endl; + else if (disc < 0) + cout << "There are no real solutions."; +} + +void SolveQuadradicEquation() { + double a = 0, b = 0, c = 0; + cout << "ax^2 + bx + c = 0" << endl; + cout << "Enter a = "; + cin >> a; + cout << "Enter b = "; + cin >> b; + cout << "Enter c = "; + cin >> c; + PrintRealRoots(a, b, c); +} + +#pragma endregion + + +#pragma region Menu + +bool menyFunc() { + cout << "\nVelg funksjon:\n"; + cout << "(0) Avslutt\n"; + cout << "(1) Summer to tall\n"; + cout << "(2) Summer flere tall\n"; + cout << "(3) Konverter fra NOK til EURO\n"; + cout << "(4) Tegn gangetabell" << endl; + cout << "(5) Løs 2. gradsplynom" << endl; + cout << "Angi valg (0-5): "; + int valg = 0; + cin >> valg; + switch (valg) + { + case 0: + return false; + break; + case 1: + inputIntegersAndPrintSum(); + break; + case 2: + inputIntegersUsingLoopAndPrintSum(); + break; + case 3: + NOKtoEUR(); + break; + case 4: + DrawGangetabell(); + break; + case 5: + SolveQuadradicEquation(); + break; + default: + cout << "Tast inn et tall mellom 0 og 3. Prøv igjen.\n"; + break; + } + return true; +} +#pragma endregion + + +int main() { + { + /* + // Oppgave 1a + inputAndPrintInteger(); + + + // 1b + int number = inputInteger(); + cout << "Du skrev: " << number << "\n"; + + // 1c + cout << "\n\n1c\n"; + inputIntegersAndPrintSum(); + + // 1d - TEORI + // + //Jeg valgte inputInteger fordi den ikke printer tallet du skrev inn tilbake til skjermen. + // + + // 1e + for (int i = 0; i < 16; i++) { + cout << i << ": " << IsOdd(i) << "\n"; + } + + // 1f + printHumanReadableTime(10000); + */ + } + + { + /* + // Oppgave 2a + inputIntegersUsingLoopAndPrintSum(); + + // 2b - TEORI + /* + Dersom man velger å avslutte summing med 0, burde man bruke en "while"-løkke. Den kan fortsette i all evighet, siden den ikke krever noen start- og sluttverider. + + Der du sier hvor mange summinger du ønsker er en "for"-løkke det beste, da kjører den kun sp mange ganger du ønsker at den skal kjøre + */ + /* + // 2c + cout << "Halvparten :" << inputDouble() / 2; + */ + //2d + //NOKtoEUR(); + } + + +#pragma region Oppgave 3 - Menysystem + // a + + //while(menyFunc()){} + + Gangetabell(14, 14); + +#pragma endregion + + + return 0; +} \ No newline at end of file diff --git a/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj b/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj new file mode 100644 index 0000000..c9d3c38 --- /dev/null +++ b/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj @@ -0,0 +1,142 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {7846fdbb-329b-4890-a7f4-1868d36342fb} + Øving_2 + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + Console + + + + + + + + + \ No newline at end of file diff --git a/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj.filters b/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj.filters new file mode 100644 index 0000000..0d8d9e4 --- /dev/null +++ b/Øving 2/Øving 2/Øving 2/Øving 2.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;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 + + + + + Source Files + + + \ No newline at end of file diff --git a/Øving 2/Øving 2/Øving_2(11.jan)(1).pdf b/Øving 2/Øving 2/Øving_2(11.jan)(1).pdf new file mode 100644 index 0000000..9901d63 Binary files /dev/null and b/Øving 2/Øving 2/Øving_2(11.jan)(1).pdf differ diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4.sln b/Øving 2/Øving2_oppg4/Øving2_oppg4.sln new file mode 100644 index 0000000..d0c0c89 --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4.sln @@ -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}") = "Øving2_oppg4", "Øving2_oppg4\Øving2_oppg4.vcxproj", "{B0D04901-1E2C-4441-AB9A-1D045EB8506A}" +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 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Debug|x64.ActiveCfg = Debug|x64 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Debug|x64.Build.0 = Debug|x64 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Debug|x86.ActiveCfg = Debug|Win32 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Debug|x86.Build.0 = Debug|Win32 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Release|x64.ActiveCfg = Release|x64 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Release|x64.Build.0 = Release|x64 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Release|x86.ActiveCfg = Release|Win32 + {B0D04901-1E2C-4441-AB9A-1D045EB8506A}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E8FF668E-F3F6-43F7-B5FF-DA7CEF5BC2C1} + EndGlobalSection +EndGlobal diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.cpp b/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.cpp new file mode 100644 index 0000000..8dbc1a2 --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.cpp @@ -0,0 +1,76 @@ +#include "loan_drawer.h" + +using namespace Graph_lib; + +constexpr int win_x = 800; +constexpr int win_y = 600; +constexpr int margin = 30; +constexpr int axis_x_len = win_x - 2 * margin; +constexpr int axis_y_len = win_y - 2 * margin; +constexpr int origo_y = win_y - margin; +constexpr int y_max_val = 2000; + +const Color annuity_color = Color::dark_blue; +const Color series_color = Color::dark_red; + +void plot_mp(vector points, Marked_polyline& plt) +// Precondition: vector of size periods with values ranging from 0 to y_max_val +{ + int periods = static_cast(points.size()); + + constexpr double axis_y_scale = double{axis_y_len} / y_max_val; + int x_step = axis_x_len / periods; + int x = margin + x_step; + int y; + + for (int p : points) { + y = origo_y - static_cast(p * axis_y_scale); + plt.add({x, y}); + x += x_step; + } +} + +void drawPlot(vector annuity, vector series, int loan, int rate) +// Naiv funksjon. Den tar ikke høyde for at vectorene kan ha ulik størrelse, +// ingen transformering av koordinatsystem, osv. +{ + Point tl{100, 100}; + int periods = static_cast(series.size()); + const string win_label{"Ã…rlig utgift ved annuitetslÃ¥n og serielÃ¥n over " + + to_string(periods) + " Ã¥r pÃ¥lydende " + + to_string(loan) + " kroner med " + + to_string(rate) + " % rente."}; + Simple_window win{tl, win_x, win_y, win_label}; + + Axis x{Axis::x, {margin, origo_y}, axis_x_len, periods, "mÃ¥lemerke = 1 Ã¥r"}; + Axis y{Axis::y, {margin, origo_y}, axis_y_len, periods, + "mÃ¥lemerke = " + to_string(y_max_val / periods) + " kr"}; + x.set_color(Color::black); + y.set_color(Color::black); + win.attach(x); + win.attach(y); + + // AnnuitetslÃ¥n + Marked_polyline annuity_plt{"x"}; + plot_mp(annuity, annuity_plt); + annuity_plt.set_color(annuity_color); + + Text at{{margin + 20, margin + 20}, "Annuitet"}; + at.set_color(annuity_color); + + win.attach(annuity_plt); + win.attach(at); + + // SerielÃ¥n + Marked_polyline series_plt{"x"}; + plot_mp(series, series_plt); + series_plt.set_color(series_color); + + Text st{{margin + 20, margin + 40}, "Serie"}; + st.set_color(series_color); + + win.attach(series_plt); + win.attach(st); + + win.wait_for_button(); +} diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.h b/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.h new file mode 100644 index 0000000..36c1c06 --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4/loan_drawer.h @@ -0,0 +1,5 @@ +#include "std_lib_facilities.h" // vector (Vector) +#include "Graph.h" +#include "Simple_window.h" + +void drawPlot(vector annuity, vector series, int loan, int rate); diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4/main.cpp b/Øving 2/Øving2_oppg4/Øving2_oppg4/main.cpp new file mode 100644 index 0000000..e6fb477 --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4/main.cpp @@ -0,0 +1,53 @@ +// Example program in TDT4102_Graphics template, from PPP page 415 +#include "std_lib_facilities.h" +#include "Graph.h" +#include "Simple_window.h" +#include "loan_drawer.h" + +vector CalculateSeries(double loan, double years, double interest) { + vector payments(years); + int curLoan = loan; + for (int i = 0; i < years; i++) { + payments[i] = int((loan / years) + (interest / 100) * curLoan); + curLoan -= int(loan / years); + } + return payments; +} + +vector CalculateAnnuity(double loan, double years, double interest) { + int total = loan * ((interest / 100) /( 1 - pow(1 + interest / 100, -years))); + vector payments(10); + for (int i = 0; i < years; i++) { + payments[i] = total; + } + return payments; +} + +int SumVector(vector& vec) { + int total = 0; + for (int i = 0; i < vec.size(); i++) + total += vec[i]; + return total; +} + + +void DrawLoanTable(vector& seriesLoan, vector& annuityLoan) { + int tableW = 12; + cout << setw(tableW) << "Year" << setw(tableW) << "Series" << setw(tableW) << "Annuity" << setw(tableW) << "Difference" << endl; + + for (int i = 0; i < seriesLoan.size(); i++) { + cout << setw(tableW) << (i + 1) << setw(tableW) << seriesLoan[i] << setw(tableW) << annuityLoan[i] << setw(tableW) << (seriesLoan[i] - annuityLoan[i]) << endl; + } + + cout << setw(tableW) << "Total" << setw(tableW) << SumVector(seriesLoan) << setw(tableW) << SumVector(annuityLoan) << setw(tableW) << (SumVector(seriesLoan) - SumVector(annuityLoan)) << endl; +} + +int main() { + vector seriesLoan = CalculateSeries(10000, 10, 3); + vector annuityLoan = CalculateAnnuity(10000, 10, 3); + DrawLoanTable(seriesLoan, annuityLoan); + //drawPlot(annuityLoan, seriesLoan, 10000, 3); + keep_window_open(); + return 0; +} + diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj b/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj new file mode 100644 index 0000000..64be968 --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj @@ -0,0 +1,158 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + 15.0 + {b0d04901-1e2c-4441-ab9a-1d045eb8506a} + Øving2_oppg4 + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib32;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib32;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath) + + + C:\Program Files\TDT4102\includes;$(ProjectDir);C:\Program Files\TDT4102\Graph_lib\Graph;$(VCInstallDir);C:\Program Files\TDT4102\FLTK_1.3.4-2;$(IncludePath) + C:\Program Files\TDT4102\Graph_lib\lib64;C:\Program Files\TDT4102\FLTK_1.3.4-2\lib64;$(LibraryPath) + + + + Level3 + Disabled + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + Disabled + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + MaxSpeed + true + true + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + + Level3 + MaxSpeed + true + true + true + true + NOGDI;WIN32;_MBCS;%(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + + + true + true + Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + + + \ No newline at end of file diff --git a/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj.filters b/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj.filters new file mode 100644 index 0000000..a91ad0e --- /dev/null +++ b/Øving 2/Øving2_oppg4/Øving2_oppg4/Øving2_oppg4.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;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 + + + + + Source Files + + + \ No newline at end of file