Skip to content
Snippets Groups Projects
Commit e3c8368e authored by bmmazzet's avatar bmmazzet
Browse files

publish O09

parent d5e50b9f
No related branches found
No related tags found
No related merge requests found
Showing
with 199 additions and 0 deletions
File added
#include "MyArray.h"
// BEGIN 5d
// END 5d
\ No newline at end of file
#pragma once
#include <iostream>
#include <exception>
// BEGIN 5a
// END 5a
class MyArray
{
private:
// BEGIN 5b
// END 5b
public:
// BEGIN 5c
// END 5c
};
// BEGIN 5d
// END 5d
\ No newline at end of file
#include "Stopwatch.h"
void Stopwatch::start() {
startTime = std::chrono::steady_clock::now();
}
double Stopwatch::stop() {
std::chrono::time_point endTime = std::chrono::steady_clock::now();
long durationInMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime).count();
double durationInSeconds = double(durationInMicroseconds)/1000000.0;
return durationInSeconds;
}
\ No newline at end of file
#pragma once
#include <chrono>
// This class abstracts some (somewhat) nasty code that is
// definitely outside the scope of this course.
// Its main purpose is to return the amount of time
// taken by the program in main.cpp
// Calling start() starts the stopwatch
// Calling stop() stops it and returns the amount of time
// that has elapsed since start() was called in seconds
class Stopwatch {
std::chrono::time_point<std::chrono::steady_clock> startTime;
public:
void start();
double stop();
};
\ No newline at end of file
#include "Stopwatch.h"
#include "measurePerformance.h"
#include "optimizeVector.h"
#include "optimizationTask.h"
#include "templatefunctions.h"
#include "MyArray.h"
int main() {
// Oppgave 1
//measurePerformanceUnique();
//measurePerformanceShared();
//measurePerformanceStack();
//measurePerformanceHeap();
// Oppgave 2
//optimizeVector();
// Oppgave 3
//optimizationTask();
// Oppgave 4
//testTemplateFunctions();
// Oppgave 5
//testMyArray();
return 0;
}
\ No newline at end of file
#include "Stopwatch.h"
#include <memory>
#include <array>
#include <iostream>
// BEGIN 1a
// END 1a
\ No newline at end of file
#pragma once
double measurePerformanceUnique();
double measurePerformanceShared();
double measurePerformanceStack();
double measurePerformanceHeap();
#include "Stopwatch.h"
#include <vector>
#include <iostream>
// Utdelt program til oppgave 3
// BEGIN 3b
double sumMatrix(std::vector<std::vector<double>> matrix){
double sum = 0;
for (int row = 0; row < matrix.size(); row++){
for (int col = 0; col < matrix.size(); col++){
double value = matrix.at(row).at(col);
sum += value;
}
}
return sum;
}
void setDiagonalValue(std::vector<std::vector<double>>& matrix, double newValue){
for (int row = 0; row < matrix.size(); row++){
for (int col = 0; col < matrix.size(); col++){
bool isDiagonal = (row == col);
if (isDiagonal){
matrix.at(row).at(col) = newValue;
}
}
}
}
void optimizationTask(){
Stopwatch stopwatch;
stopwatch.start();
const int matrixSize = 10000;
// Oppretter nullmatrisen direkte ved bruk av konstruktøren som tar inn antall og verdi.
std::vector<std::vector<double>> matrix(matrixSize, std::vector<double>(matrixSize, 0.0));
// Setter alle elementer på diagonalen til 0.41
setDiagonalValue(matrix, 0.41);
// Summerer alle elementene i matrisen
double total = sumMatrix(matrix);
double coolerNumber = total + 2;
std::cout << "TDT" << coolerNumber << std::endl;
std::cout << "Time taken: " << stopwatch.stop() << "seconds" << std::endl;
}
// END 3b
\ No newline at end of file
#pragma once
void optimizationTask();
\ No newline at end of file
#include "Stopwatch.h"
#include "optimizeVector.h"
#include <vector>
#include <iostream>
// BEGIN 2a
// END 2a
void optimizeVector(){
// BEGIN 2d
// END 2d
// BEGIN 2e
// END 2e
}
\ No newline at end of file
#pragma once
void testVector();
void optimizeVector();
\ No newline at end of file
#include "templatefunctions.h"
void testTemplateFunctions(){
// Her kan du teste templatefunksjonene dine
}
#pragma once
#include <random>
#include <iostream>
#include <string>
#include <vector>
// BEGIN 4a
// END 4a
// BEGIN 4b
// END 4b
void testTemplateFunctions();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment