diff options
author | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
commit | af98ee7ff28cff97f5f29a5d9e65f9153531b0ee (patch) | |
tree | 86bfc53a0bc04512ac2936ee067a2b43e901e688 | |
download | imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.tar.gz imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.zip |
Imperial C++ Directory
These are all the projects I’ve been working on at university.
-rw-r--r-- | 2048 Game/Game | bin | 0 -> 12544 bytes | |||
-rw-r--r-- | 2048 Game/Game.cpp | 96 | ||||
-rw-r--r-- | 2048 Game/configFile.txt | 4 | ||||
-rw-r--r-- | Append | bin | 0 -> 30164 bytes | |||
-rw-r--r-- | Append.cpp | 29 | ||||
-rwxr-xr-x | BinarySearch | bin | 0 -> 15340 bytes | |||
-rw-r--r-- | BinarySearch.cpp | 23 | ||||
-rw-r--r-- | CodeEval/ChessKnight | bin | 0 -> 13960 bytes | |||
-rw-r--r-- | CodeEval/ChessKnight.cpp | 123 | ||||
-rw-r--r-- | CodeEval/DetectingCycles | bin | 0 -> 14080 bytes | |||
-rw-r--r-- | CodeEval/DetectingCycles.cpp | 108 | ||||
-rw-r--r-- | CodeEval/KnightLocations.txt | 5 | ||||
-rw-r--r-- | CodeEval/LongestLines | bin | 0 -> 8624 bytes | |||
-rw-r--r-- | CodeEval/LongestLines.cpp | 38 | ||||
-rw-r--r-- | CodeEval/MineFile.txt | 4 | ||||
-rw-r--r-- | CodeEval/Minesweeper | bin | 0 -> 17824 bytes | |||
-rw-r--r-- | CodeEval/Minesweeper.cpp | 124 | ||||
-rw-r--r-- | CodeEval/list.txt | 3 | ||||
-rw-r--r-- | Collatz | bin | 0 -> 15392 bytes | |||
-rw-r--r-- | Collatz.cpp | 34 | ||||
-rw-r--r-- | Collatz.exe | bin | 0 -> 124943 bytes | |||
-rw-r--r-- | DictRealEstate.txt | 6 | ||||
-rwxr-xr-x | DynamicArray | bin | 0 -> 40372 bytes | |||
-rw-r--r-- | DynamicArray.cpp | 78 | ||||
-rw-r--r-- | Euclid | bin | 0 -> 9365 bytes | |||
-rw-r--r-- | Euclid.cpp | 19 | ||||
-rw-r--r-- | EvenOddCom1ex.cpp | 18 | ||||
-rw-r--r-- | Factorisation | bin | 0 -> 25564 bytes | |||
-rw-r--r-- | Factorisation.cpp | 55 | ||||
-rw-r--r-- | FirstFile.txt | 5 | ||||
-rw-r--r-- | Firstname.txt | 5 | ||||
-rw-r--r-- | HelloWorld | bin | 0 -> 9864 bytes | |||
-rw-r--r-- | HelloWorld.cpp | 18 | ||||
-rw-r--r-- | LinkedLists | bin | 0 -> 9984 bytes | |||
-rw-r--r-- | LinkedLists.cpp | 37 | ||||
-rw-r--r-- | MinMax | bin | 0 -> 25168 bytes | |||
-rw-r--r-- | MinMax.cpp | 42 | ||||
-rw-r--r-- | NamesandSurnames | bin | 0 -> 68020 bytes | |||
-rw-r--r-- | NamesandSurnames.cpp | 39 | ||||
-rw-r--r-- | PointFile.txt | 54 | ||||
-rw-r--r-- | Preferences1.txt | 406 | ||||
-rw-r--r-- | Preferences2.txt | 35 | ||||
-rw-r--r-- | RawMemory | bin | 0 -> 15332 bytes | |||
-rw-r--r-- | RawMemory.cpp | 14 | ||||
-rw-r--r-- | RealEstate | bin | 0 -> 77100 bytes | |||
-rw-r--r-- | RealEstate.cpp | 60 | ||||
-rw-r--r-- | SecondFile.txt | 5 | ||||
-rw-r--r-- | Sets | bin | 0 -> 24388 bytes | |||
-rw-r--r-- | Sets.cpp | 63 | ||||
-rw-r--r-- | SumAndScalar | bin | 0 -> 30688 bytes | |||
-rw-r--r-- | SumAndScalar.cpp | 47 | ||||
-rw-r--r-- | Surname.txt | 5 | ||||
-rw-r--r-- | Test1 | bin | 0 -> 62516 bytes | |||
-rw-r--r-- | Test1.cpp | 94 | ||||
-rw-r--r-- | Test3 | bin | 0 -> 19636 bytes | |||
-rw-r--r-- | TestExample2 | bin | 0 -> 27192 bytes | |||
-rw-r--r-- | TestExample2.cpp | 55 | ||||
-rwxr-xr-x | TriangularDivisor | bin | 0 -> 9732 bytes | |||
-rw-r--r-- | TriangularDivisor.cpp | 29 | ||||
-rw-r--r-- | Warehouse1.txt | 5 | ||||
-rw-r--r-- | Warehouse2.txt | 3 | ||||
-rw-r--r-- | smalltest.cpp | 16 | ||||
-rw-r--r-- | something.py | 5 | ||||
-rw-r--r-- | test1.py | 16 | ||||
-rw-r--r-- | thinkCScpp.pdf | bin | 0 -> 845116 bytes | |||
-rw-r--r-- | w4 | bin | 0 -> 14359 bytes | |||
-rw-r--r-- | w4.cpp | 24 |
67 files changed, 1849 insertions, 0 deletions
diff --git a/2048 Game/Game b/2048 Game/Game Binary files differnew file mode 100644 index 0000000..9aef631 --- /dev/null +++ b/2048 Game/Game diff --git a/2048 Game/Game.cpp b/2048 Game/Game.cpp new file mode 100644 index 0000000..553593e --- /dev/null +++ b/2048 Game/Game.cpp @@ -0,0 +1,96 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <sstream> + +#define GRIDSIZE 4 +#define UP 'w' +#define DOWN 's' +#define RIGHT 'd' +#define LEFT 'a' + +using namespace std; + +// defines the functions +void printGrid(int (&)[GRIDSIZE][GRIDSIZE]); +bool checkGameOver(int (&)[GRIDSIZE][GRIDSIZE]); + +int main(int argc, char* argv[]) { + // defines the 2D and tmp array + int grid[GRIDSIZE][GRIDSIZE]; + string fileName; + ifstream configFile; + + cout << "enter initial configuration file name:" << endl; + cin >> fileName; + + // opens the user defined file + configFile.open(fileName.c_str()); + + if(configFile.is_open()) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + configFile >> grid[i][j]; + } + } + configFile.close(); + } else { + cout << "the file doesn't exist, using default start" << endl; + // creates default grid + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + grid[i][j] = 0; + } + } + grid[GRIDSIZE-1][GRIDSIZE-1] = 2; + } + + printGrid(grid); + + while(!checkGameOver(grid)) { + + } + + return 0; +} + +void printGrid(int (&gridArray)[GRIDSIZE][GRIDSIZE]) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + cout << gridArray[i][j] << '\t'; + } + cout << endl; + } + cout << endl; +} + +void moveVertical() { + +} + +void moveHorizontal() { + +} + +void merge() { + +} + +bool checkGameOver(int (&gridArray)[GRIDSIZE][GRIDSIZE]) { + for(int i = 0; i < GRIDSIZE; ++i) { + for(int j = 0; j < GRIDSIZE; ++j) { + if(gridArray[i][j] == 0) { + return false; + } else if(i > 0 && gridArray[i][j] == gridArray[i-1][j]) { + return false; + } else if(i < GRIDSIZE-1 && gridArray[i][j] == gridArray[i+1][j]) { + return false; + } else if(j > 0 && gridArray[i][j] == gridArray[i][j-1]) { + return false; + } else if(j < GRIDSIZE-1 && gridArray[i][j] == gridArray[i][j+1]) { + return false; + } + } + } + return true; +}
\ No newline at end of file diff --git a/2048 Game/configFile.txt b/2048 Game/configFile.txt new file mode 100644 index 0000000..b4f6ca6 --- /dev/null +++ b/2048 Game/configFile.txt @@ -0,0 +1,4 @@ +128 64 2 0 +0 0 32 0 +0 0 0 16 +0 8 4 0
\ No newline at end of file Binary files differdiff --git a/Append.cpp b/Append.cpp new file mode 100644 index 0000000..5b88e6c --- /dev/null +++ b/Append.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include <cmath> +#include <vector> + +using namespace std; + +vector<int> append(vector<int> v1, vector<int> v2) { + for(int i = 0; i < v2.size(); i++) { + v1.push_back(v2[i]); + } + return v1; +} + +int main() { + vector<int> a, b, c; + a.push_back(1); + a.push_back(2); + a.push_back(3); + b.push_back(4); + b.push_back(5); + b.push_back(6); + c = append(a, b); + cout << "c: "; + for(int k = 0; k < c.size(); k++) { + cout << c[k] << " "; + } + cout << endl; + return 0; +}
\ No newline at end of file diff --git a/BinarySearch b/BinarySearch Binary files differnew file mode 100755 index 0000000..6b06bfa --- /dev/null +++ b/BinarySearch diff --git a/BinarySearch.cpp b/BinarySearch.cpp new file mode 100644 index 0000000..a9e73b6 --- /dev/null +++ b/BinarySearch.cpp @@ -0,0 +1,23 @@ +#include <iostream> + +using namespace std; + +int main() { + double result, num, divi; + result = 0.0; + num = 1.0; + divi = 1.0; + + for(int i = 2; i < 1000; i++) { + for(int j = 2; j < 1000; j++) { + num = (double)i; + divi = (double)j; + result = (double)(num/divi)*((num-1)/(divi-1)); + if(result == 0.5) { + cout << i << " " << j << endl; + } + cout << j << endl; + } + } + return 0; +}
\ No newline at end of file diff --git a/CodeEval/ChessKnight b/CodeEval/ChessKnight Binary files differnew file mode 100644 index 0000000..a0308c1 --- /dev/null +++ b/CodeEval/ChessKnight diff --git a/CodeEval/ChessKnight.cpp b/CodeEval/ChessKnight.cpp new file mode 100644 index 0000000..5b3eca4 --- /dev/null +++ b/CodeEval/ChessKnight.cpp @@ -0,0 +1,123 @@ +#include <iostream> +#include <cstdlib> +#include <fstream> +#include <sstream> +#include <string> + +using namespace std; + +/* 8 * * * * * * * * + 7 * * * * * * * * + 6 * * _ * _ * * * + 5 * _ * * * _ * * + 4 * * * k * * * * + 3 * _ * * * _ * * + 2 * * _ * _ * * * + 1 * * * * * * * * + a b c d e f g h */ + +void find_possible_jumps(string&, string*&, int&); + +int main(int argc, char** argv) { + ifstream file_stream; + string tmp_str; + string* post_loc; + int post_loc_count; + + file_stream.open(argv[1]); + //file_stream.open("./KnightLocations.txt"); + if(!file_stream.is_open()) { + cout << "Couln't open file: " << argv[1] << endl; + } + + while(getline(file_stream, tmp_str)) { + find_possible_jumps(tmp_str, post_loc, post_loc_count); + for(int i = 0; i < post_loc_count; ++i) { + if(i != post_loc_count-1) { + cout << post_loc[i] << " "; + } else { + cout << post_loc[i] << endl; + } + } + + } + + delete[] post_loc; + file_stream.close(); + return 0; +} + +void find_possible_jumps(string &knight_loc, string* &chess_loc, int &count) { + int posx, negx, posy, negy, pos2x, neg2x, pos2y, neg2y; + chess_loc = new string[8]; + char* ch = new char[2]; + count = 0; + + posx = int(knight_loc[0]) + 2; + posy = int(knight_loc[1]) + 1; + negx = int(knight_loc[0]) - 2; + negy = int(knight_loc[1]) - 1; + pos2x = int(knight_loc[0]) + 1; + pos2y = int(knight_loc[1]) + 2; + neg2x = int(knight_loc[0]) - 1; + neg2y = int(knight_loc[1]) - 2; + + if(negx > 96) { + if(negy > 48) { + ch[0] = negx; + ch[1] = negy; + chess_loc[count] = ch; + ++count; + } if(posy < 57) { + ch[0] = negx; + ch[1] = posy; + chess_loc[count] = ch; + ++count; + } + } + + if(neg2y > 48) { + if(neg2x > 96) { + ch[0] = neg2x; + ch[1] = neg2y; + chess_loc[count] = ch; + ++count; + } + } if(pos2y < 57) { + if(neg2x > 96) { + ch[0] = neg2x; + ch[1] = pos2y; + chess_loc[count] = ch; + ++count; + } + } if(neg2y > 48) { + if(pos2x < 105) { + ch[0] = pos2x; + ch[1] = neg2y; + chess_loc[count] = ch; + ++count; + } + } if(pos2y < 57) { + if(pos2x < 105) { + ch[0] = pos2x; + ch[1] = pos2y; + chess_loc[count] = ch; + ++count; + } + } + + if(posx < 105) { + if(negy > 48) { + ch[0] = posx; + ch[1] = negy; + chess_loc[count] = ch; + ++count; + } if(posy < 57 ) { + ch[0] = posx; + ch[1] = posy; + chess_loc[count] = ch; + ++count; + } + } + delete[] ch; +}
\ No newline at end of file diff --git a/CodeEval/DetectingCycles b/CodeEval/DetectingCycles Binary files differnew file mode 100644 index 0000000..fc0d203 --- /dev/null +++ b/CodeEval/DetectingCycles diff --git a/CodeEval/DetectingCycles.cpp b/CodeEval/DetectingCycles.cpp new file mode 100644 index 0000000..1e66f30 --- /dev/null +++ b/CodeEval/DetectingCycles.cpp @@ -0,0 +1,108 @@ +#include <iostream> +#include <string> +#include <fstream> +#include <cstdlib> +#include <sstream> + +using namespace std; + +int find_cycle(int*&, int*&); + +int main(int argc, char** argv) { + // Initialisation of arrays and filestream + ifstream file_stream; + int* tmp_array = new int[50]; + int* cycle_array; + int array_count, cycle_count; + string tmp_str; + stringstream str_stream; + + // Opens the file and checks if no error occured + file_stream.open(argv[1]); + // file_stream.open("./list.txt"); + if(!file_stream.is_open()) { + cout << "Couldn't open the file: " << argv[1] << endl; + exit(EXIT_FAILURE); + } + + // Waits till file ends + while(getline(file_stream, tmp_str)) { + // Init counter + array_count = 0; + cycle_array = new int[50]; + // Set Stringstream + str_stream.str(tmp_str); + // Put stringstream into int array + while(str_stream >> tmp_array[array_count]) { + ++array_count; + } + // Clear ss + str_stream.clear(); + // Get cycles + cycle_count = find_cycle(tmp_array, cycle_array); + // Delete int array + delete[] tmp_array; + tmp_array = new int[50]; + // Print cycles + for(int i = 0; i < cycle_count; ++i) { + cout << cycle_array[i] << " "; + } + cout << endl; + // Delete cycle array + delete[] cycle_array; + cycle_count = 0; + } + + // Closing sequence + file_stream.close(); + delete[] tmp_array; + return 0; +} + +// Takes input of a vector by reference and makes it the vector containing the sequence +int find_cycle(int* &f_list, int* &cycle) { + // Defines the 2 pointers and the positioning of sequence + int s_point, f_point, mu, lambda, power, count; + count = 0; + s_point = f_list[count]; + f_point = f_list[++count]; + power = 1; + lambda = 1; + + // Goes through list and increments s_point by a factor of 2^i + // If s = f then there is a cycle with length of current lambda + while(s_point != f_point) { + // Increases power as it went through all of lambda + if(power == lambda) { + s_point = f_point; + power *= 2; + // Reset Lambda so that it always stays correct + lambda = 0; + } + // Increments the f_pointer by 1 and lambda + f_point = f_list[++count]; + ++lambda; + } + + // Init mu, the distance from the start + mu = 0; + // Reset count + count = 0; + // Set the s and f to be lambda apart and then cycle through the sequence + s_point = f_list[count]; + f_point = f_list[lambda]; + // Stops when they are equal because it means it found mu + while(s_point != f_point) { + ++count; + s_point = f_list[count]; + f_point = f_list[lambda+count]; + ++mu; + } + // Set cycle to be equal to the first appearance of the cycle + count = 0; + for(int i = mu; i < mu+lambda; ++i) { + cycle[count] = f_list[i]; + ++count; + } + return count; +}
\ No newline at end of file diff --git a/CodeEval/KnightLocations.txt b/CodeEval/KnightLocations.txt new file mode 100644 index 0000000..118426a --- /dev/null +++ b/CodeEval/KnightLocations.txt @@ -0,0 +1,5 @@ +g2 +a1 +d6 +e5 +b1
\ No newline at end of file diff --git a/CodeEval/LongestLines b/CodeEval/LongestLines Binary files differnew file mode 100644 index 0000000..a3b4eb4 --- /dev/null +++ b/CodeEval/LongestLines diff --git a/CodeEval/LongestLines.cpp b/CodeEval/LongestLines.cpp new file mode 100644 index 0000000..71b592e --- /dev/null +++ b/CodeEval/LongestLines.cpp @@ -0,0 +1,38 @@ +#include <iostream> +#include <fstream> +#include <string> + +using namespace std; + +int main(int argc, char** argv) { + ifstream file_stream; + int num, array_size; + string* lines = new string[1024]; + bool sorted = true; + string tmp; + + array_size = 0; + file_stream.open(argv[1]); + file_stream >> num; + while(getline(file_stream, lines[array_size])) { + ++array_size; + } + while(sorted) { + sorted = false; + for(int i = 1; i < array_size; ++i) { + if(lines[i].length() > lines[i-1].length()) { + tmp = lines[i]; + lines[i] = lines[i-1]; + lines[i-1] = tmp; + sorted = true; + } + } + } + for(int j = 0; j < num; ++j) { + cout << lines[j] << endl; + } + + file_stream.close(); + delete[] lines; + return 0; +}
\ No newline at end of file diff --git a/CodeEval/MineFile.txt b/CodeEval/MineFile.txt new file mode 100644 index 0000000..61986d2 --- /dev/null +++ b/CodeEval/MineFile.txt @@ -0,0 +1,4 @@ +3,5;**.........*... +4,4;*........*...... +10,10;**...*..*...*..*..*.........*.*.**.*..*.**.....*.*..*..*.........*..***....*..*.**......*...*..*.....**..*..*. +10,10;**...*..*...*..*...****.....*.*.*..*..*..............*...........*.......**.............*....*.*..**.*.......*
\ No newline at end of file diff --git a/CodeEval/Minesweeper b/CodeEval/Minesweeper Binary files differnew file mode 100644 index 0000000..725e6b4 --- /dev/null +++ b/CodeEval/Minesweeper diff --git a/CodeEval/Minesweeper.cpp b/CodeEval/Minesweeper.cpp new file mode 100644 index 0000000..950fffb --- /dev/null +++ b/CodeEval/Minesweeper.cpp @@ -0,0 +1,124 @@ +#include <iostream> +#include <cstdlib> +#include <sstream> +#include <string> +#include <fstream> +#include <unistd.h> + +/* + * <title>: Minesweeper.cpp + * <author>: Yann Herklotz + * <date>: 25-01-2016 + * <description>: This is a program that creates a Minesweeper field + * + */ + +// declares namespace +using namespace std; + +// declares the function +void getMineField(int&, int&, string&, string*&); +void timing(int& , int&, string*&); + +// main function that prints and inputs data +int main(int argc, char** argv) { + // declares the variables + ifstream file_stream; + // strings for input + string y_coord_str, x_coord_str, matrix; + int y_coord, x_coord; + // output string array + string* field; + string nothing; + + // opens and checks file + file_stream.open(argv[1]); + if(!file_stream.is_open()) { + cout << "Couldn't open the file: " << argv[1] << endl; + exit(EXIT_FAILURE); + } + + // reads the lines from the file and stops when there are none left + while(getline(file_stream, y_coord_str, ',')) { + getline(file_stream, x_coord_str, ';'); + getline(file_stream, matrix); + + // using stringstream to convert string to int + stringstream ss; + ss << y_coord_str << " " << x_coord_str; + ss >> y_coord >> x_coord; + + // calls function and prints the results + getMineField(x_coord, y_coord, matrix, field); + cout << string(100, '\n'); + for(int i = 0; i < y_coord; ++i) { + for(int j = 0; j < x_coord; ++j) { + cout << field[i][j] << ' '; + } + cout << endl; + } + cin >> nothing; + } + // closes and deletes necessary variables + delete[] field; + file_stream.close(); + return 0; +} + +// function that creates the minefield with numbers +void getMineField(int &x, int &y, string &mtrx, string* &fld) { + // declares dynamic array from input + fld = new string[1024]; + int int_sum; + // puts subset correctly into dynamic array + for(int i = 0; i < y; ++i) { + fld[i] = mtrx.substr(i*x, x); + } + + // checks all the cases around the current box + for(int i = 0; i < y; ++i) { + for(int j = 0; j < x; ++j) { + int_sum = 0; + if(fld[i][j] == '.') { + if((i-1 >= 0) && (j-1 >= 0) && (fld[i-1][j-1] == '*')) { + int_sum += 1; + } + if((i-1 >= 0) && (fld[i-1][j] == '*')) { + int_sum += 1; + } + if((i-1 >= 0) && (j+1 >= 0) && (fld[i-1][j+1] == '*')) { + int_sum += 1; + } + if((j+1 >= 0) && (fld[i][j+1] == '*')) { + int_sum += 1; + } + if((i+1 >= 0) && (j+1 >= 0) && (fld[i+1][j+1] == '*')) { + int_sum += 1; + } + if((i+1 >= 0) && (fld[i+1][j] == '*')) { + int_sum += 1; + } + if((i+1 >= 0) && (j-1 >= 0) && (fld[i+1][j-1] == '*')) { + int_sum += 1; + } + if((j-1 >= 0) && (fld[i][j-1] == '*')) { + int_sum += 1; + } + char ch = '0' + int_sum; + fld[i][j] = ch; + timing(y, x, fld); + } + } + } +} + +void timing(int &y_c, int &x_c, string* &str_array) { + usleep(100000); + cout << string(100, '\n'); + for(int i = 0; i < y_c; ++i) { + for(int j = 0; j < x_c; ++j) { + cout << str_array[i][j] << ' '; + } + cout << endl; + } +}
\ No newline at end of file diff --git a/CodeEval/list.txt b/CodeEval/list.txt new file mode 100644 index 0000000..4effff8 --- /dev/null +++ b/CodeEval/list.txt @@ -0,0 +1,3 @@ +2 0 6 3 1 6 3 1 6 3 1 +3 4 8 0 11 9 7 2 5 6 10 1 49 49 49 49 +1 2 3 1 2 3 1 2 3
\ No newline at end of file Binary files differdiff --git a/Collatz.cpp b/Collatz.cpp new file mode 100644 index 0000000..5263710 --- /dev/null +++ b/Collatz.cpp @@ -0,0 +1,34 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() { + int usrNum, usrNum1, usrNum2; + int count; + + cout << "Please Enter a range: "; + cin >> usrNum1 >> usrNum2; + + cout << "\nnumber\tsteps\n"; +// cout << usrNum1 << "\t" << usrNum2 << endl; + for(usrNum=usrNum1; usrNum<=usrNum2; usrNum++) { + count = 0; + int initNum = usrNum; + while(initNum > 1) { + if(initNum % 2 == 0) { + initNum = initNum / 2; + } + else { + initNum = initNum*3 + 1; + } + + count ++; + } + cout << usrNum << "\t" << count << "\t"; + for(int x = 0; x < count; x++) { + cout << "*"; + } + cout << endl; + } +}
\ No newline at end of file diff --git a/Collatz.exe b/Collatz.exe Binary files differnew file mode 100644 index 0000000..7c429ba --- /dev/null +++ b/Collatz.exe diff --git a/DictRealEstate.txt b/DictRealEstate.txt new file mode 100644 index 0000000..5858691 --- /dev/null +++ b/DictRealEstate.txt @@ -0,0 +1,6 @@ +exclusive expensive +cosy small +bedsit room +quiet remote +luxurious expensive +lovely tiny
\ No newline at end of file diff --git a/DynamicArray b/DynamicArray Binary files differnew file mode 100755 index 0000000..5ba3de2 --- /dev/null +++ b/DynamicArray diff --git a/DynamicArray.cpp b/DynamicArray.cpp new file mode 100644 index 0000000..4875109 --- /dev/null +++ b/DynamicArray.cpp @@ -0,0 +1,78 @@ +#include <iostream> +#include <fstream> +#include <cstdlib> +#include <string> + +using namespace std; + +// point object structure +struct point { + double x, y; + + void p_str() { + cout << "(" << x << ", " << y << ")" << endl; + } +}; + +// declaration of method +void readPoints(string, int&, int&, point*&); + +int main() { + string fileLocation = "./PointFile.txt"; + // declares the size and capacity of the array which both have to be tracked and initialises them + int size = 0; + int capacity = 1; + point* pArray = new point[capacity]; + readPoints(fileLocation, capacity, size, pArray); + + // prints out the content of the array + for(int i = 0; i < size; i++) { + pArray[i].p_str(); + } + + // prints out the characteristics of the array + cout << "array capacity:\t\t" << capacity << endl << "array size:\t\t" << size << endl << "array physical size:\t" << size*sizeof(point) << " bits\t=\t" << size*sizeof(point)/8 << " bytes" << endl; + + delete[] pArray; + return 0; +} + +// method that creates the array +void readPoints(string fileloc, int &cpcty, int &sz, point* &pa) { + // declares file and other variables + ifstream pointFile; + point tmpp; + + pointFile.open(fileloc); + + // Error opening file + if(!pointFile.is_open()) { + cout << "couldn't open input file" << endl; + exit(EXIT_FAILURE); + } + + // reads the two points from the file + while(pointFile >> tmpp.x >> tmpp.y) { + // increases the sz of the array + sz++; + // checks if the array is still large enough for the element + if(sz <= cpcty) { + // adds point to the end of the array + pa[sz-1] = tmpp; + } else { + // if array isn't large enough creates new dynamic array + // of two times the sz + point* tmpa = new point[cpcty*=2]; + for(int i = 0; i < sz; i++) { + tmpa[i] = pa[i]; + } + // never have to delete the tmpa as it points to the new pa + tmpa[sz-1] = tmpp; + // delete old pa + delete[] pa; + pa = tmpa; + } + } + + pointFile.close(); +}
\ No newline at end of file Binary files differdiff --git a/Euclid.cpp b/Euclid.cpp new file mode 100644 index 0000000..b2daaaa --- /dev/null +++ b/Euclid.cpp @@ -0,0 +1,19 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int mgcd(int a, int b) { + if(a % b != 0) { + mgcd(b, a % b); + } else { + cout << "\nGreatest common divisor: " << b << endl; + } +} + +int main() { + int x, y; + cout << "Enter 2 numbers: "; + cin >> x >> y; + mgcd(x, y); +} diff --git a/EvenOddCom1ex.cpp b/EvenOddCom1ex.cpp new file mode 100644 index 0000000..aa3410e --- /dev/null +++ b/EvenOddCom1ex.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() { + int num; + cout << "Please enter a number: "; + cin >> num; + if(num % 2 == 0) { + cout << "even" << endl; + } + else { + cout << "odd" << endl; + } + + return 0; +}
\ No newline at end of file diff --git a/Factorisation b/Factorisation Binary files differnew file mode 100644 index 0000000..c9655e3 --- /dev/null +++ b/Factorisation diff --git a/Factorisation.cpp b/Factorisation.cpp new file mode 100644 index 0000000..034a975 --- /dev/null +++ b/Factorisation.cpp @@ -0,0 +1,55 @@ +#include <iostream> +#include <cmath> +#include <vector> + +using namespace std; + +void is_prime(int); +void print_vector(vector<int>); + +void is_prime(int x) { + int original = x; + vector<int> primes, factors; + primes.push_back(2); + primes.push_back(3); + + for(int i = 5; i <= x; i++) { + bool itsPrime = false; + for(int j = 0; j < primes.size(); j++) { + if(i % primes[j] == 0) { + itsPrime = false; + break; + } else { + itsPrime = true; + } + } + if(itsPrime) { + primes.push_back(i); + } + } + // cout << "Prime numbers to consider: "; + // print_vector(primes); + while(x != 1) { + for(int l = 0; l < primes.size(); l++) { + if(x % primes[l] == 0) { + factors.push_back(primes[l]); + x = x / primes[l]; + break; + } + } + } + cout << "Factors of " << original << ": "; + print_vector(factors); +} + +void print_vector(vector<int> v) { + for(int k = 0; k < v.size(); k++) { + cout << v[k] << " "; + } + cout << endl; +} + +int main() { + is_prime(103); + return 0; +}
\ No newline at end of file diff --git a/FirstFile.txt b/FirstFile.txt new file mode 100644 index 0000000..afd10c4 --- /dev/null +++ b/FirstFile.txt @@ -0,0 +1,5 @@ +Donald Trump +Martin Wiersema +Alex Blanc +Yann Herklotz +Sam Wiggins diff --git a/Firstname.txt b/Firstname.txt new file mode 100644 index 0000000..26e8146 --- /dev/null +++ b/Firstname.txt @@ -0,0 +1,5 @@ +Donald +Martin +Alex +Yann +Sam
\ No newline at end of file diff --git a/HelloWorld b/HelloWorld Binary files differnew file mode 100644 index 0000000..8b7e0d0 --- /dev/null +++ b/HelloWorld diff --git a/HelloWorld.cpp b/HelloWorld.cpp new file mode 100644 index 0000000..aa3410e --- /dev/null +++ b/HelloWorld.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() { + int num; + cout << "Please enter a number: "; + cin >> num; + if(num % 2 == 0) { + cout << "even" << endl; + } + else { + cout << "odd" << endl; + } + + return 0; +}
\ No newline at end of file diff --git a/LinkedLists b/LinkedLists Binary files differnew file mode 100644 index 0000000..efb0ad2 --- /dev/null +++ b/LinkedLists diff --git a/LinkedLists.cpp b/LinkedLists.cpp new file mode 100644 index 0000000..2966f76 --- /dev/null +++ b/LinkedLists.cpp @@ -0,0 +1,37 @@ +#include <iostream> + +using namespace std; + +struct intList { + int val; + intList* next_el; +}; + +int main() { + intList* ilist = NULL; + int el, n; + + cout << "How many elements do you want to add to the list?" << endl; + cin >> n; + cout << "Now please enter the " << n << " integers: " << endl; + for(int i = 0; i < n; ++i) { + cin >> el; + intList* tmp = new intList; + tmp->val = el; + tmp->next_el = ilist; + ilist = tmp; + } + cout << endl; + intList* lit = ilist; + while(lit != NULL) { + cout << lit->val << endl; + lit = lit->next_el; + } + + while(ilist != NULL) { + intList* tmpilist = ilist->next_el; + delete ilist; + ilist = tmpilist; + } + return 0; +} Binary files differdiff --git a/MinMax.cpp b/MinMax.cpp new file mode 100644 index 0000000..070c33f --- /dev/null +++ b/MinMax.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <vector> +#include <string> +#include <sstream> + +using namespace std; + +int main() { + double input, maxtmp, maxloc, mintmp, minloc, + addtmp, average; + vector<double> vin; + + cout << "Enter Number <q to exit>: "; + cin >> input; + + do { + cout << "Enter Number <q to exit>: "; + vin.push_back(input); + } while(cin >> input); + + mintmp = vin[0]; + maxtmp = vin[0]; + addtmp = 0; + + // cout << "values: " << mintmp << ", " << maxtmp << endl; + + for(int i = 0; i < vin.size(); i++) { + if(maxtmp <= vin[i]) { + maxtmp = vin[i]; + maxloc = i; + } else if (mintmp >= vin[i]) { + mintmp = vin[i]; + minloc = i; + } + addtmp += vin[i]; + } + average = addtmp / vin.size(); + cout << "\nmin: " << mintmp << " at pos: " << minloc << "\nmax: " + << maxtmp << " at pos: " << maxloc << "\naverage: " << + average << endl; + return 0; +} diff --git a/NamesandSurnames b/NamesandSurnames Binary files differnew file mode 100644 index 0000000..0c00953 --- /dev/null +++ b/NamesandSurnames diff --git a/NamesandSurnames.cpp b/NamesandSurnames.cpp new file mode 100644 index 0000000..8d10b39 --- /dev/null +++ b/NamesandSurnames.cpp @@ -0,0 +1,39 @@ +#include <iostream> +#include <cstdlib> +#include <string> +#include <fstream> +#include <sstream> +#include <vector> + +using namespace std; + +struct name { + string first_name, last_name; + + string _str() { + stringstream ss; + ss << last_name << ", " << first_name << endl; + return ss.str(); + } +}; + +int main() { + name student_name; + ifstream firstname, surname; + ofstream firstFile, secondFile; + + firstname.open("Firstname.txt"); + surname.open("Surname.txt"); + firstFile.open("FirstFile.txt"); + secondFile.open("SecondFile.txt"); + + while(firstname >> student_name.first_name) { + surname >> student_name.last_name; + firstFile << student_name.first_name << " " << student_name.last_name << endl; + secondFile << student_name._str(); + } + return 0; +} + + + diff --git a/PointFile.txt b/PointFile.txt new file mode 100644 index 0000000..74705a9 --- /dev/null +++ b/PointFile.txt @@ -0,0 +1,54 @@ +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23 +2 3 +4 2 +1 9 +49 29 +382 93 +1 23
\ No newline at end of file diff --git a/Preferences1.txt b/Preferences1.txt new file mode 100644 index 0000000..ca1c4d2 --- /dev/null +++ b/Preferences1.txt @@ -0,0 +1,406 @@ +// Place your settings in the file "User/Preferences.sublime-settings", which +// overrides the settings in here. +// +// Settings may also be placed in file type specific options files, for +// example, in Packages/Python/Python.sublime-settings for python files. +{ + // Sets the colors used within the text area + "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", + + // Note that the font_face and font_size are overridden in the platform + // specific settings file, for example, "Preferences (Linux).sublime-settings". + // Because of this, setting them here will have no effect: you must set them + // in your User File Preferences. + "font_face": "", + "font_size": 10, + + // Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias", + // "subpixel_antialias", "no_round" (OS X only), "gdi" (Windows only) and + // "directwrite" (Windows only) + "font_options": [], + + // Characters that are considered to separate words + "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?", + + // Set to false to prevent line numbers being drawn in the gutter + "line_numbers": true, + + // Set to false to hide the gutter altogether + "gutter": true, + + // Spacing between the gutter and the text + "margin": 4, + + // Fold buttons are the triangles shown in the gutter to fold regions of text + "fold_buttons": true, + + // Hides the fold buttons unless the mouse is over the gutter + "fade_fold_buttons": true, + + // Columns in which to display vertical rulers + "rulers": [], + + // Set to true to turn spell checking on by default + "spell_check": false, + + // The number of spaces a tab is considered equal to + "tab_size": 4, + + // Set to true to insert spaces when tab is pressed + "translate_tabs_to_spaces": false, + + // If translate_tabs_to_spaces is true, use_tab_stops will make tab and + // backspace insert/delete up to the next tabstop + "use_tab_stops": true, + + // Set to false to disable detection of tabs vs. spaces on load + "detect_indentation": true, + + // Calculates indentation automatically when pressing enter + "auto_indent": true, + + // Makes auto indent a little smarter, e.g., by indenting the next line + // after an if statement in C. Requires auto_indent to be enabled. + "smart_indent": true, + + // Adds whitespace up to the first open bracket when indenting. Requires + // auto_indent to be enabled. + "indent_to_bracket": false, + + // Trims white space added by auto_indent when moving the caret off the + // line. + "trim_automatic_white_space": true, + + // Disables horizontal scrolling if enabled. + // May be set to true, false, or "auto", where it will be disabled for + // source code, and otherwise enabled. + "word_wrap": "auto", + + // Set to a value other than 0 to force wrapping at that column rather than the + // window width + "wrap_width": 0, + + // Set to false to prevent word wrapped lines from being indented to the same + // level + "indent_subsequent_lines": true, + + // Draws text centered in the window rather than left aligned + "draw_centered": false, + + // Controls auto pairing of quotes, brackets etc + "auto_match_enabled": true, + + // Word list to use for spell checking + "dictionary": "Packages/Language - English/en_US.dic", + + // Sets which scopes are checked for spelling errors + "spelling_selector": "markup.raw, source string.quoted - punctuation - meta.preprocessor.c.include, source comment - source comment.block.preprocessor, -(source, constant, keyword, storage, support, variable, markup.underline.link, meta.tag)", + + // Set to true to draw a border around the visible rectangle on the minimap. + // The color of the border will be determined by the "minimapBorder" key in + // the color scheme + "draw_minimap_border": false, + + // Always visualise the viewport on the minimap, as opposed to only + // showing it on mouse over + "always_show_minimap_viewport": false, + + // If enabled, will highlight any line with a caret + "highlight_line": false, + + // Valid values are "smooth", "phase", "blink" and "solid". + "caret_style": "smooth", + + // These settings control the size of the caret + "caret_extra_top": 0, + "caret_extra_bottom": 0, + "caret_extra_width": 0, + + // Set to false to disable underlining the brackets surrounding the caret + "match_brackets": true, + + // Set to false if you'd rather only highlight the brackets when the caret is + // next to one + "match_brackets_content": true, + + // Set to false to not highlight square brackets. This only takes effect if + // match_brackets is true + "match_brackets_square": true, + + // Set to false to not highlight curly brackets. This only takes effect if + // match_brackets is true + "match_brackets_braces": true, + + // Set to false to not highlight angle brackets. This only takes effect if + // match_brackets is true + "match_brackets_angle": false, + + // Enable visualization of the matching tag in HTML and XML + "match_tags": true, + + // Highlights other occurrences of the currently selected text + "match_selection": true, + + // Additional spacing at the top of each line, in pixels + "line_padding_top": 0, + + // Additional spacing at the bottom of each line, in pixels + "line_padding_bottom": 0, + + // Set to false to disable scrolling past the end of the buffer. + // On OS X, this value is overridden in the platform specific settings, so + // you'll need to place this line in your user settings to override it. + "scroll_past_end": true, + + // This controls what happens when pressing up or down when on the first + // or last line. + // On OS X, this value is overridden in the platform specific settings, so + // you'll need to place this line in your user settings to override it. + "move_to_limit_on_up_down": false, + + // Set to "none" to turn off drawing white space, "selection" to draw only the + // white space within the selection, and "all" to draw all white space + "draw_white_space": "selection", + + // Set to false to turn off the indentation guides. + // The color and width of the indent guides may be customized by editing + // the corresponding .tmTheme file, and specifying the colors "guide", + // "activeGuide" and "stackGuide" + "draw_indent_guides": true, + + // Controls how the indent guides are drawn, valid options are + // "draw_normal" and "draw_active". draw_active will draw the indent + // guides containing the caret in a different color. + "indent_guide_options": ["draw_normal"], + + // Set to true to removing trailing white space on save + "trim_trailing_white_space_on_save": false, + + // Set to true to ensure the last line of the file ends in a newline + // character when saving + "ensure_newline_at_eof_on_save": false, + + // Set to true to automatically save files when switching to a different file + // or application + "save_on_focus_lost": false, + + // Save via writing to an alternate file, and then renaming it over the + // original file. + "atomic_save": false, + + // The encoding to use when the encoding can't be determined automatically. + // ASCII, UTF-8 and UTF-16 encodings will be automatically detected. + "fallback_encoding": "Western (Windows 1252)", + + // Encoding used when saving new files, and files opened with an undefined + // encoding (e.g., plain ascii files). If a file is opened with a specific + // encoding (either detected or given explicitly), this setting will be + // ignored, and the file will be saved with the encoding it was opened + // with. + "default_encoding": "UTF-8", + + // Files containing null bytes are opened as hexadecimal by default + "enable_hexadecimal_encoding": true, + + // Determines what character(s) are used to terminate each line in new files. + // Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and + // 'unix' (LF only). + "default_line_ending": "system", + + // When enabled, pressing tab will insert the best matching completion. + // When disabled, tab will only trigger snippets or insert a tab. + // Shift+tab can be used to insert an explicit tab when tab_completion is + // enabled. + "tab_completion": true, + + // Enable auto complete to be triggered automatically when typing. + "auto_complete": true, + + // The maximum file size where auto complete will be automatically triggered. + "auto_complete_size_limit": 4194304, + + // The delay, in ms, before the auto complete window is shown after typing + "auto_complete_delay": 50, + + // Controls what scopes auto complete will be triggered in + "auto_complete_selector": "source - comment, meta.tag - punctuation.definition.tag.begin", + + // Additional situations to trigger auto complete + "auto_complete_triggers": [ {"selector": "text.html", "characters": "<"} ], + + // By default, auto complete will commit the current completion on enter. + // This setting can be used to make it complete on tab instead. + // Completing on tab is generally a superior option, as it removes + // ambiguity between committing the completion and inserting a newline. + "auto_complete_commit_on_tab": false, + + // Controls if auto complete is shown when snippet fields are active. + // Only relevant if auto_complete_commit_on_tab is true. + "auto_complete_with_fields": false, + + // Controls what happens when pressing the up key while the first item in + // the auto complete window is selected: if false, the window is hidden, + // otherwise the last item in the window is selected. Likewise for the + // down key when the last item is selected. + "auto_complete_cycle": false, + + // Automatically close HTML and XML tags when </ is entered. + "auto_close_tags": true, + + // By default, shift+tab will only unindent if the selection spans + // multiple lines. When pressing shift+tab at other times, it'll insert a + // tab character - this allows tabs to be inserted when tab_completion is + // enabled. Set this to true to make shift+tab always unindent, instead of + // inserting tabs. + "shift_tab_unindent": false, + + // If true, the copy and cut commands will operate on the current line + // when the selection is empty, rather than doing nothing. + "copy_with_empty_selection": true, + + // If true, the selected text will be copied into the find panel when it's + // shown. + // On OS X, this value is overridden in the platform specific settings, so + // you'll need to place this line in your user settings to override it. + "find_selected_text": true, + + // When auto_find_in_selection is enabled, the "Find in Selection" flag + // will be enabled automatically when multiple lines of text are selected + "auto_find_in_selection": false, + + // When drag_text is enabled, clicking on selected text will begin a + // drag-drop operation. This is not currently implemented under Linux. + "drag_text": true, + + // + // User Interface Settings + // + + // The theme controls the look of Sublime Text's UI (buttons, tabs, scroll bars, etc) + "theme": "Default.sublime-theme", + + // Set to 0 to disable smooth scrolling. Set to a value between 0 and 1 to + // scroll slower, or set to larger than 1 to scroll faster + "scroll_speed": 1.0, + + // Controls side bar animation when expanding or collapsing folders + "tree_animation_enabled": true, + + // Controls animation throughout the application + "animation_enabled": true, + + // Makes tabs with modified files more visible + "highlight_modified_tabs": false, + + "show_tab_close_buttons": true, + + // Show folders in the side bar in bold + "bold_folder_labels": false, + + // OS X only: Set to true to disable Lion style full screen support. + // Sublime Text must be restarted for this to take effect. + "use_simple_full_screen": false, + + // OS X only. Valid values are true, false, and "auto". Auto will enable + // the setting when running on a screen 2560 pixels or wider (i.e., a + // Retina display). When this setting is enabled, OpenGL is used to + // accelerate drawing. Sublime Text must be restarted for changes to take + // effect. + "gpu_window_buffer": "auto", + + // Valid values are "system", "enabled" and "disabled" + "overlay_scroll_bars": "system", + + // Allows tabs to scroll left and right, instead of simply shrinking + "enable_tab_scrolling": true, + + // Display file encoding in the status bar + "show_encoding": false, + + // Display line endings in the status bar + "show_line_endings": false, + + // + // Application Behavior Settings + // + + // Exiting the application with hot_exit enabled will cause it to close + // immediately without prompting. Unsaved modifications and open files will + // be preserved and restored when next starting. + // + // Closing a window with an associated project will also close the window + // without prompting, preserving unsaved changes in the workspace file + // alongside the project. + "hot_exit": true, + + // remember_full_screen will allow Sublime Text to start in full screen + // mode if it was exited in full screen mode. When set to false, Sublime + // Text will never start in full screen mode. + "remember_full_screen": false, + + // Always prompt before reloading a file, even if the file hasn't been + // modified. The default behavior is to automatically reload a file if it + // hasn't been edited. If a file has unsaved changes, a prompt will always + // be shown. + "always_prompt_for_file_reload": false, + + // OS X only: When files are opened from finder, or by dragging onto the + // dock icon, this controls if a new window is created or not. + "open_files_in_new_window": true, + + // OS X only: This controls if an empty window is created at startup or not. + "create_window_at_startup": true, + + // Set to true to close windows as soon as the last file is closed, unless + // there's a folder open within the window. + // On OS X, this value is overridden in the platform specific settings, so + // you'll need to place this line in your user settings to override it. + "close_windows_when_empty": false, + + // Show the full path to files in the title bar. + // On OS X, this value is overridden in the platform specific settings, so + // you'll need to place this line in your user settings to override it. + "show_full_path": true, + + // Shows the Build Results panel when building. If set to false, the Build + // Results can be shown via the Tools/Build Results menu. + "show_panel_on_build": true, + + // Preview file contents when clicking on a file in the side bar. Double + // clicking or editing the preview will open the file and assign it a tab. + "preview_on_click": true, + + // folder_exclude_patterns and file_exclude_patterns control which files + // are listed in folders on the side bar. These can also be set on a per- + // project basis. + "folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"], + "file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db", "*.sublime-workspace"], + // These files will still show up in the side bar, but won't be included in + // Goto Anything or Find in Files + "binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"], + + // File indexing parses all files in the side bar, and builds an index of + // their symbols. This is required for Goto Definition to work. + "index_files": true, + + // Set the number threads to use for indexing. A value of 0 will make + // Sublime Text guess based on the number of cores. Use the index_files + // setting to disable all workers. + "index_workers": 0, + + // index_exclude_patterns indicate which files won't be indexed. + "index_exclude_patterns": ["*.log"], + + // When enabled, anonymised usage data is sent back, assisting Sublime HQ + // in making informed decisions about improving Sublime Text. File names + // and file contents are never included, but data such as computer + // specifications, startup time, installed packages, and edited file types + // are. When disabled, telemetry is neither recorded or sent. + // A setting of auto will enable telemetry in dev builds, and disable + // telemetry in regular builds. + "enable_telemetry": "auto", + + // List any packages to ignore here. When removing entries from this list, + // a restart may be required if the package contains plugins. + "ignored_packages": ["Vintage"] +} diff --git a/Preferences2.txt b/Preferences2.txt new file mode 100644 index 0000000..7af229b --- /dev/null +++ b/Preferences2.txt @@ -0,0 +1,35 @@ +{ + "auto_complete": true, + "caret_style": "solid", + "color_scheme": "Packages/User/SublimeLinter/Tomorrow-Night (SL).tmTheme", + "draw_white_space": "selection", + "find_selected_text": true, + "fold_buttons": false, + "font_face": "SourceCodePro-Medium", + "font_options": + [ + "subpixel_antialias", + "no_bold" + ], + "font_size": 14, + "highlight_line": true, + "highlight_modified_tabs": true, + "ignored_packages": + [ + "Vintage" + ], + "line_padding_bottom": 0, + "line_padding_top": 0, + "rulers": + [ + 72, + 79 + ], + "scroll_past_end": false, + "show_full_path": true, + "show_minimap": true, + "theme": "Soda Dark.sublime-theme", + "wide_caret": true, + "word_wrap": true, + "wrap_width": 80 +} diff --git a/RawMemory b/RawMemory Binary files differnew file mode 100644 index 0000000..05699be --- /dev/null +++ b/RawMemory diff --git a/RawMemory.cpp b/RawMemory.cpp new file mode 100644 index 0000000..f6247f6 --- /dev/null +++ b/RawMemory.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include <string> + +using namespace std; + +int main() { + int a = 15; + int* point = &a; + + cout << "a: " << a << ", &a: " << &a << ", point: " + << point << ", &point: " << &point << ", *point: " << + *point << endl; + +}
\ No newline at end of file diff --git a/RealEstate b/RealEstate Binary files differnew file mode 100644 index 0000000..8e896a4 --- /dev/null +++ b/RealEstate diff --git a/RealEstate.cpp b/RealEstate.cpp new file mode 100644 index 0000000..5f69c91 --- /dev/null +++ b/RealEstate.cpp @@ -0,0 +1,60 @@ +#include <iostream> +#include <vector> +#include <string> +#include <cstdlib> +#include <sstream> +#include <fstream> + +using namespace std; + +void check_string(); +// void translate(stringstream); + +struct dict_type { + string false_m, real_m; +}; + +void check_string() { + ifstream dict_file; + dict_type dict; + vector<string> false_statement, real_statement, words; + stringstream statement; + string word, original; + + dict_file.open("DictRealEstate.txt"); + if(dict_file.is_open()){ + cout << "open\n"; + while(dict_file >> dict.false_m >> dict.real_m) { + false_statement.push_back(dict.false_m); + real_statement.push_back(dict.real_m); + } + cout << "finished...\n"; + dict_file.close(); + } + + cout << "Enter Statement: "; + getline(cin, original); + statement << original; + + while(statement >> word) { + words.push_back(word); + } + + for(int i = 0; i < words.size(); i++) { + for(int j = 0; j < false_statement.size(); j++) { + if(words[i] == false_statement[j]) { + words[i] = real_statement[j]; + } + } + } + cout << "Translation: "; + for(int k = 0; k < words.size(); k++) { + cout << words[k] << " "; + } + cout << endl; +} + +int main() { + check_string(); + return(0); +}
\ No newline at end of file diff --git a/SecondFile.txt b/SecondFile.txt new file mode 100644 index 0000000..352813f --- /dev/null +++ b/SecondFile.txt @@ -0,0 +1,5 @@ +Trump, Donald +Wiersema, Martin +Blanc, Alex +Herklotz, Yann +Wiggins, Sam Binary files differdiff --git a/Sets.cpp b/Sets.cpp new file mode 100644 index 0000000..cba50fc --- /dev/null +++ b/Sets.cpp @@ -0,0 +1,63 @@ +m#include <iostream> +#include <cmath> +#include <vector> + +using namespace std; + +vector<int> v_union(vector<int>, vector<int>); +vector<int> v_intersection(vector<int>, vector<int>); +bool v_subset(vector<int>, vector<int>); + +vector<int> v_union(vector<int> v1, vector<int> v2) { + for(int i = 0; i < v2.size(); i++) { + bool present = false; + for(int j = 0; j < v1.size(); j++) { + if(v2[i] == v1[j]) { + present = true; + } + } + if(!present) { + v1.push_back(v2[i]); + } + } + return v1; +} + +vector<int> v_intersection(vector<int> v1, vector<int> v2) { + vector<int> vInt; + for(int i = 0; i < v2.size(); i++) { + for(int j = 0; j < v1.size(); j++) { + if(v2[i] == v1[j]) { + vInt.push_back(v2[i]); + } + } + } + return vInt; +} + +bool v_subset(vector<int> v1, vector<int> v2) { + for(int i = 0; i < v2.size(); i++) { + bool present = false; + for(int j = 0; j < v1.size(); j++) { + if(v1[j] == v2[i]) { + present = true; + } + } + if(!present) { + return false; + } + } + return true; +} + +int main() { + vector<int> a, b, c; + a.push_back(1); + a.push_back(2); + a.push_back(3); + b.push_back(1); + b.push_back(1); + b.push_back(2); + cout << v_subset(a, b) << endl; + return 0; +}
\ No newline at end of file diff --git a/SumAndScalar b/SumAndScalar Binary files differnew file mode 100644 index 0000000..fb86c0e --- /dev/null +++ b/SumAndScalar diff --git a/SumAndScalar.cpp b/SumAndScalar.cpp new file mode 100644 index 0000000..04af50c --- /dev/null +++ b/SumAndScalar.cpp @@ -0,0 +1,47 @@ +#include <iostream> +#include <cmath> +#include <vector> + +using namespace std; + +vector<double> vector_sum(vector<double>, vector<double>); +double vector_product(vector<double>, vector<double>); + +vector<double> vector_sum(vector<double> v1, vector<double> v2) { + vector<double> vSum; + for(int i = 0; i < v1.size(); i++) { + vSum.push_back(v1[i] + v2[i]); + } + return vSum; +} + +double vector_product(vector<double> v1, vector<double> v2) { + double vProduct; + for(int j = 0; j < v1.size(); j++) { + vProduct += v1[j] * v2[j]; + } + return vProduct; +} + +int main() { + vector<double> v1, v2, vSum; + double tmp, tmp2, vProduct; + int dimensions, x; + cout << "How many dimensions are you using? "; + cin >> dimensions; + do { + cout << "Please enter both vectors: "; + cin >> tmp >> tmp2; + v1.push_back(tmp); + v2.push_back(tmp2); + x++; + } while (x < dimensions); + vSum = vector_sum(v1, v2); + vProduct = vector_product(v1, v2); + cout << "Sum: "; + for(int k = 0; k < vSum.size(); k++) { + cout << vSum[k] << " "; + } + cout << "\nProduct: " << vProduct << endl; + return 0; +}
\ No newline at end of file diff --git a/Surname.txt b/Surname.txt new file mode 100644 index 0000000..a2e62ec --- /dev/null +++ b/Surname.txt @@ -0,0 +1,5 @@ +Trump +Wiersema +Blanc +Herklotz +Wiggins
\ No newline at end of file Binary files differdiff --git a/Test1.cpp b/Test1.cpp new file mode 100644 index 0000000..a3ef13c --- /dev/null +++ b/Test1.cpp @@ -0,0 +1,94 @@ +#include <iostream> +#include <cstdlib> +#include <fstream> +#include <sstream> +#include <string> +#include <vector> + +using namespace std; + +struct item { + string name; + int num; + + void print_str() { + cout << name << ": " << num << endl; + } +}; + +void merge_items(const vector<item> &vec1, vector<item> &vec2, vector<item> &vec_final) { + // bool running = false; + // for(int i = 0; i < vec1.size(); i++) { + // if(vec1[i].name == vec2[i].name) { + // vec2[i].num += vec1[i].num; + // vec_final.push_back(vec2[i]); + // } else if(vec1[i].name < vec2[i].name) { + // vec_final.push_back(vec1[i]); + // vec_final.push_back(vec2[i]); + // } else { + // vec_final.push_back(vec2[i]); + // vec_final.push_back(vec1[i]); + // } + // } + int count1, count2; + count1 = 0; + count2 = 0; + do { + if(count1 < vec1.size()) { + if(vec1[count1].name == vec2[count2].name) { + vec2[count2].num += vec1[count1].num; + vec_final.push_back(vec2[count2]); + count1++; + count2++; + } else if(vec1[count1].name < vec2[count2].name) { + vec_final.push_back(vec1[count1]); + count1++; + } else if(vec1[count1].name > vec2[count2].name) { + vec_final.push_back(vec2[count2]); + count2++; + } + } else { + vec_final.push_back(vec2[count2]); + count2++; + } + } while (vec_final.size() < vec1.size() + vec2.size()); + for(int i = vec1.size(); i < vec2.size(); i++) { + vec_final.push_back(vec2[i]); + } +} + +int main() { + string ware1, ware2; + ifstream fileware1, fileware2; + vector<item> vecware1, vecware2, vecfinal; + item tmpitem; + + ware1 = "Warehouse1.txt"; + ware2 = "Warehouse2.txt"; + + fileware1.open(ware1); + fileware2.open(ware2); + + if(!fileware1.is_open()) { + cout << "couldn't open fileware1: '" << ware1 << "'" << endl; + } + if(!fileware2.is_open()) { + cout << "couldn't open fileware2: '" << ware2 << "'" << endl; + } + + while(fileware1 >> tmpitem.name >> tmpitem.num) { + vecware1.push_back(tmpitem); + } + while(fileware2 >> tmpitem.name >> tmpitem.num) { + vecware2.push_back(tmpitem); + } + + merge_items(vecware2, vecware1, vecfinal); + for(int i = 0; i < vecfinal.size(); i++) { + cout << vecfinal[i].name << ": " << vecfinal[i].num << endl; + } + + fileware1.close(); + fileware2.close(); + return(0); +}
\ No newline at end of file Binary files differdiff --git a/TestExample2 b/TestExample2 Binary files differnew file mode 100644 index 0000000..649e119 --- /dev/null +++ b/TestExample2 diff --git a/TestExample2.cpp b/TestExample2.cpp new file mode 100644 index 0000000..fb7510f --- /dev/null +++ b/TestExample2.cpp @@ -0,0 +1,55 @@ +#include <iostream> +#include <string> +#include <vector> + +using namespace std; + +struct codon_pairing { + string amino; + string codon; + + void prnt_pair() { + cout << amino << " " << codon << endl; + } +}; + +void wrong_entries(vector<codon_pairing>&, vector<codon_pairing>&, vector<codon_pairing>&); + +int main() { + vector<codon_pairing> experiment_log, correct_pair, wrong_pairs; + codon_pairing tmpcp; + + cout << "Please enter the experiment log (end end pair terminates):" << endl; + + do { + cin >> tmpcp.amino >> tmpcp.codon; + experiment_log.push_back(tmpcp); + } while(tmpcp.amino != "end" && tmpcp.codon != "end"); + + cout << "Please enter the known correct pairings (end end pair terminates):" << endl; + + do { + cin >> tmpcp.amino >> tmpcp.codon; + correct_pair.push_back(tmpcp); + } while(tmpcp.amino != "end" && tmpcp.codon != "end"); + wrong_entries(experiment_log, correct_pair, wrong_pairs); + cout << "Wrong entries:" << endl; + for(int i = 0; i < wrong_pairs.size(); ++i) { + wrong_pairs[i].prnt_pair(); + } +} + +void wrong_entries(vector<codon_pairing>& exp_log, vector<codon_pairing>& crrct_pair, vector<codon_pairing>& wrng_pairs) { + bool present = false; + for(int i = 0; i < exp_log.size(); ++i) { + for(int j = 0; j < crrct_pair.size(); ++j) { + if(exp_log[i].amino == crrct_pair[j].amino && exp_log[i].codon == crrct_pair[j].codon) { + present = true; + } + } + if(!present) { + wrng_pairs.push_back(exp_log[i]); + } + present = false; + } +}
\ No newline at end of file diff --git a/TriangularDivisor b/TriangularDivisor Binary files differnew file mode 100755 index 0000000..9fcd14e --- /dev/null +++ b/TriangularDivisor diff --git a/TriangularDivisor.cpp b/TriangularDivisor.cpp new file mode 100644 index 0000000..4e1278c --- /dev/null +++ b/TriangularDivisor.cpp @@ -0,0 +1,29 @@ +#include <iostream> + +using namespace std; + +int main() { + int count, triangle, k, result; + int* allcount = new int[100000000000]; + k = 0; + result = 1; + for(int i = 2; i < 50000; ++i) { + triangle = (i*(i+1))/2; + int realtriangle = triangle; + for(int j = 2; j <= triangle; ++j) { + count = 0; + while(triangle % j == 0) { + triangle /= j; + ++count; + } + allcount[k] = count; + ++k; + } + for(int j = 0; j < k; ++j) { + result *= (allcount[j]+1); + } + if(result > 500) { + cout << realtriangle << endl; + } + } +}
\ No newline at end of file diff --git a/Warehouse1.txt b/Warehouse1.txt new file mode 100644 index 0000000..b334063 --- /dev/null +++ b/Warehouse1.txt @@ -0,0 +1,5 @@ +apple 12 +banana 14 +mango 4 +orange 15 +pineapple 10
\ No newline at end of file diff --git a/Warehouse2.txt b/Warehouse2.txt new file mode 100644 index 0000000..8d564e6 --- /dev/null +++ b/Warehouse2.txt @@ -0,0 +1,3 @@ +avocado 9 +banana 22 +papaya 5
\ No newline at end of file diff --git a/smalltest.cpp b/smalltest.cpp new file mode 100644 index 0000000..52e5044 --- /dev/null +++ b/smalltest.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include <string> + +using namespace std; + +int main() { + string str1 = "Hello"; + string str2 = "Hella"; + if(str1 == str2) { + cout << str1 << " equals " << str2 << endl; + } else if(str1 < str2) { + cout << str1 << " is smaller than " << str2 << endl; + } else if(str1 > str2){ + cout << str1 << " is greater than " << str2 << endl; + } +} diff --git a/something.py b/something.py new file mode 100644 index 0000000..94685e0 --- /dev/null +++ b/something.py @@ -0,0 +1,5 @@ +def function(): + + +if __name__ == '__main__': + main()
\ No newline at end of file diff --git a/test1.py b/test1.py new file mode 100644 index 0000000..db3f188 --- /dev/null +++ b/test1.py @@ -0,0 +1,16 @@ +def fib(*arg): + fib1 = [0, 1] + if(len(arg) == 1): + for x in range(2, arg[0]): + fib1.append(fib1[x-2]+fib1[x-1]) + print(fib1) + elif(len(arg) == 2): + for x in range(2, arg[1]): + fib1.append(fib1[x-2]+fib1[x-1]) + print(fib1[arg[0]-1:]) + +def main(): + fib(10, 20) + +if __name__ == '__main__': + main()
\ No newline at end of file diff --git a/thinkCScpp.pdf b/thinkCScpp.pdf Binary files differBinary files differnew file mode 100644 index 0000000..a2f4ed5 --- /dev/null +++ b/thinkCScpp.pdf @@ -0,0 +1,24 @@ +#include <iostream> +#include <vector> +#include <sstream> + +using namespace std; + +struct point { + double x; + double y; + + string returnString() { + stringstream ss; + ss << "(" << x << ", " << y << ")"; + return ss.str(); + } +}; + +int main() { + point userPt; + + cout << "Please enter a point: "; + cin >> userPt.x >> userPt.y; + cout << "Your point was: " << userPt.returnString() << endl; +} |