3rd semester files
This commit is contained in:
5
3rd-Semester-Fall-2022/PDS/Homework03/.vscode/settings.json
vendored
Executable file
5
3rd-Semester-Fall-2022/PDS/Homework03/.vscode/settings.json
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"string": "cpp"
|
||||
}
|
||||
}
|
28
3rd-Semester-Fall-2022/PDS/Homework03/.vscode/tasks.json
vendored
Executable file
28
3rd-Semester-Fall-2022/PDS/Homework03/.vscode/tasks.json
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
BIN
3rd-Semester-Fall-2022/PDS/Homework03/Bottle Rocket Wk 3 physics slides (2).pdf
Executable file
BIN
3rd-Semester-Fall-2022/PDS/Homework03/Bottle Rocket Wk 3 physics slides (2).pdf
Executable file
Binary file not shown.
BIN
3rd-Semester-Fall-2022/PDS/Homework03/HW03_Aidan_Sharpe
Executable file
BIN
3rd-Semester-Fall-2022/PDS/Homework03/HW03_Aidan_Sharpe
Executable file
Binary file not shown.
110
3rd-Semester-Fall-2022/PDS/Homework03/HW03_Aidan_Sharpe.cpp
Executable file
110
3rd-Semester-Fall-2022/PDS/Homework03/HW03_Aidan_Sharpe.cpp
Executable file
@ -0,0 +1,110 @@
|
||||
/****************************************************************
|
||||
* Name: Aidan Sharpe
|
||||
* Course: Principles of Data Structures
|
||||
* Class: CS04225
|
||||
* Assignment Date: October 10, 2022
|
||||
* File Name: HW03_Aidan_Sharpe.cpp
|
||||
*****************************************************************
|
||||
* ID: Homework 3 Problem 1
|
||||
* Purpose: Read, sort and write, ints from text files
|
||||
*****************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
/// @brief sort a dynamically allocated array in-place
|
||||
/// @param arrptr pointer to first element in dynamically allocated array
|
||||
/// @param len length of dynamically allocated array
|
||||
/// @return true if the array was sorted successfully
|
||||
bool dynamicArraySelectionSort(int *arrptr, int len);
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string fname;
|
||||
std::string line;
|
||||
std::ifstream readfile;
|
||||
std::ofstream writefile;
|
||||
std::cout << "Input file name:\n";
|
||||
std::cin >> fname;
|
||||
readfile.open(fname);
|
||||
std::getline(readfile, line);
|
||||
|
||||
int num_count = std::stoi(line);
|
||||
std::cout << "Reading " << num_count << " numbers...\n";
|
||||
|
||||
int *nums_ptr;
|
||||
nums_ptr = new int[num_count];
|
||||
|
||||
|
||||
// read numbers from file
|
||||
// numbers are multi-digit and separated by either a space or newline char
|
||||
int idx = 0;
|
||||
while (std::getline(readfile, line))
|
||||
{
|
||||
std::string snum;
|
||||
for (char c : line)
|
||||
{
|
||||
if (isdigit(c))
|
||||
snum.push_back(c);
|
||||
else if (c == ' ' || c == '\n')
|
||||
{
|
||||
*(nums_ptr + idx) = std::stoi(snum);
|
||||
snum = "";
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
readfile.close();
|
||||
std::cout << "Done reading values.\n";
|
||||
|
||||
// sort numbers
|
||||
std::cout << "Sorting values...\n";
|
||||
dynamicArraySelectionSort(nums_ptr, num_count);
|
||||
|
||||
std::cout << "Enter filename for sorted values:\n";
|
||||
std::cin >> fname;
|
||||
writefile.open(fname);
|
||||
|
||||
// write sorted nums to file with 8 columns
|
||||
std::cout << "Writing values to " << fname << "...\n";
|
||||
for (int i = 0; i < num_count/8 + 1; i++)
|
||||
{
|
||||
for (int j = 0; j < 8 && i*8 + j < num_count; j++)
|
||||
writefile << *(nums_ptr + i*8 + j) << " ";
|
||||
writefile << "\n";
|
||||
}
|
||||
writefile.close();
|
||||
std::cout << "Done writing values.\n";
|
||||
|
||||
// clear dynamically allocated pointers
|
||||
delete [] nums_ptr;
|
||||
nums_ptr = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool dynamicArraySelectionSort(int *arrptr, int len)
|
||||
{
|
||||
int temp; // throw-away variable for swapping
|
||||
int mindex = 0; // index of the smallest number
|
||||
for (int i = 0; i < len - 1; i++)
|
||||
{
|
||||
mindex = i;
|
||||
// find index of smallest element
|
||||
for (int j = i; j < len; j++)
|
||||
if (*(arrptr + j) < *(arrptr + mindex))
|
||||
mindex = j;
|
||||
|
||||
// swap element at i with smallest element
|
||||
if (mindex > i)
|
||||
{
|
||||
temp = *(arrptr + mindex);
|
||||
*(arrptr + mindex) = *(arrptr + i);
|
||||
*(arrptr + i) = temp;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
61
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input1.txt
Executable file
61
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input1.txt
Executable file
@ -0,0 +1,61 @@
|
||||
1200
|
||||
7208 77654 85070 28533 87834 22178 52619 85517 19695 3458 32378 17737 72813 72802 68711 69388 80828 17885 4353 24392
|
||||
39248 72336 83773 32282 28494 21754 720 17880 85790 72018 36274 9350 66024 31344 37884 63858 53523 6855 59375 73218
|
||||
10314 1753 7307 89479 80907 76019 75219 78087 3904 79572 12479 49505 68260 12605 88139 6755 34359 88859 30987 36502
|
||||
77229 73613 52204 53253 14958 88 27111 74833 13296 2838 64403 23610 4592 71711 29441 1851 64082 14661 79939 74338
|
||||
10585 8770 33843 78846 27727 31982 1953 68439 30841 32940 14941 24422 16554 67145 77675 37864 73586 21138 22697 86882
|
||||
23977 3452 26844 34921 75163 62637 36772 55597 77298 33063 39936 87884 48186 73779 76730 75913 15762 78683 60704 52955
|
||||
27975 75645 77378 50881 59143 65053 88745 49081 86192 27794 52315 26521 31247 85511 61442 22762 58148 14566 78360 45447
|
||||
53982 34648 49683 12168 18427 42765 4433 34189 37800 65138 87145 65775 57135 74523 26657 32630 55928 31754 81711 58472
|
||||
59549 50378 84993 7148 45889 56435 36262 14038 77354 30974 65837 41336 65622 25520 59856 84050 68285 64289 34591 16085
|
||||
45779 38088 88212 19267 28963 24869 51897 84892 56624 49961 53364 32525 10339 54710 39673 62581 27497 82287 76619 14851
|
||||
23262 52456 56187 88884 84328 26043 89286 62613 6685 33878 85050 58816 71966 83262 78083 10930 24484 46333 12174 87460
|
||||
12646 71890 29985 22985 36600 76010 1918 64098 68297 78537 78949 7911 47345 51489 13148 41673 77532 12434 20638 569
|
||||
52664 22040 59386 40983 21655 53821 58265 46139 16506 70439 43599 29152 52329 79936 58490 5282 72298 60408 69380 50595
|
||||
48946 64681 64859 12643 26170 84359 60669 20055 6793 87659 20624 65810 19700 86362 23145 41355 50184 81410 3846 66690
|
||||
68201 47445 5843 36882 43733 70685 42164 26031 41093 27896 82978 6391 2578 57837 19035 28748 52196 79704 55155 65342
|
||||
77363 75780 47504 13415 72142 70649 54770 38678 68411 58616 21721 52964 22413 33916 89846 72498 14601 48363 8529 55694
|
||||
76259 7860 62086 85189 72049 87473 30290 40598 77177 85445 22292 70892 71225 69796 84308 59720 56797 55430 14750 41560
|
||||
30399 36471 4524 59164 70387 4370 41663 84988 52733 56544 50683 45345 64404 29121 40534 46454 26594 70824 87052 20123
|
||||
72622 19344 1015 53847 5492 1675 29919 68641 57106 51022 20201 87505 87493 24725 56669 67881 35447 8332 69221 4533
|
||||
71229 36256 49878 45633 65377 6764 8439 8323 83941 5491 28446 66563 31187 35814 36762 43031 37489 66682 21672 10947
|
||||
34056 48225 8452 31549 72950 71474 15782 24750 86158 85004 29283 67387 37612 85513 29373 19342 2277 37812 27665 86218
|
||||
49656 62464 69133 87195 14630 15896 40227 58471 88930 68251 69419 32986 26477 84223 64535 15779 72049 86670 40529 68208
|
||||
88026 69812 45595 35638 71677 74968 54980 73955 29133 88998 76525 78789 67814 55659 75984 88796 71555 26211 57267 70485
|
||||
10815 43038 19823 37292 43614 84358 53071 25663 87380 3601 10223 85406 79765 55819 31045 61443 47139 2377 51750 76272
|
||||
7727 38275 71413 81893 10286 57398 80689 88193 89961 54309 68678 10776 13699 4853 54420 63665 5564 17492 89329 2944
|
||||
27445 9552 88351 23562 71723 35748 85005 35215 44477 53107 27839 58557 7735 9253 50450 18021 73003 47492 16215 79316
|
||||
18153 1245 93 38204 6099 54513 11870 11663 78357 17551 20959 15802 33455 25662 39365 15179 61410 40722 56746 22240
|
||||
10182 84585 80797 17917 10190 47599 35938 89545 5091 58505 78862 29596 59751 85307 67801 72202 49820 79671 217 44530
|
||||
7222 21176 66684 47029 46839 22401 62208 24601 63124 35306 53193 73306 36244 43990 7575 46434 1590 43513 45980 13033
|
||||
18371 34842 42630 84474 36501 20431 66676 86321 16454 73245 47203 30028 10773 23888 77057 57612 46289 55618 88566 25765
|
||||
924 51759 15423 37168 12102 22998 89955 20044 72864 52287 33077 1235 3481 82059 85709 39982 18842 68737 42655 41648
|
||||
51982 89859 71676 62755 23747 65086 36720 76388 30704 41638 12154 37980 9749 27577 81501 21851 50576 81456 41895 33440
|
||||
50095 81325 34675 53576 73384 36736 3558 8579 15473 52565 50227 73807 52424 31904 52914 82523 13342 89634 68912 50398
|
||||
47624 81066 88378 57374 24995 86231 79225 75571 84039 37473 25363 44134 28798 60038 14062 18534 13126 17620 27113 34951
|
||||
70186 77341 18758 38962 25597 78025 31486 38939 84011 16750 89337 41636 14168 4067 9010 39163 299 4587 24735 84338
|
||||
42060 50098 44825 70858 26489 58887 5745 45967 76508 32858 80919 63046 20199 16029 18360 45796 4054 56198 1087 88066
|
||||
72948 424 39702 87116 10844 55064 36280 11143 59651 67367 11833 18064 33817 56658 5274 60306 25546 11019 22626 18406
|
||||
43878 13545 81452 70429 29574 16164 32578 39981 72363 33665 38047 55311 40442 84101 52428 51286 49165 5060 68781 25168
|
||||
72427 80614 43232 16244 47273 48507 82903 72819 65878 15529 1225 19756 35426 89029 6538 71352 21545 39116 21333 3908
|
||||
79133 65732 59220 35927 59833 28000 87213 25350 33060 72346 50519 21839 62961 10103 44435 26586 64962 37338 9405 40841
|
||||
59219 16982 66949 4645 22363 73487 82350 43908 22603 13683 47817 18089 85768 23389 54016 55601 57741 57582 87304 7153
|
||||
39928 54175 28992 19241 64278 73427 45827 45593 27118 61584 86434 86337 78566 69735 7335 17281 53223 89685 61190 82178
|
||||
19720 25359 10267 15488 55100 70636 77442 29193 38218 74746 36346 84498 45273 71690 13740 25903 61469 59567 71496 4939
|
||||
37504 74282 1277 26070 54018 14964 49704 17241 21001 20894 15771 40721 52605 26039 62562 24057 13027 56356 53250 57597
|
||||
41102 5948 52095 86375 77638 72187 28630 49107 48107 10127 54047 85611 84409 61676 28033 54779 82992 77737 72020 20345
|
||||
14983 87792 67418 67588 30183 39980 7997 49562 6336 67599 17159 53790 73547 69254 56517 61185 57794 85148 26645 15901
|
||||
11627 87044 11512 6036 65072 39545 67168 64416 27283 49188 84761 48618 53332 62179 26207 89867 18512 40556 49429 24848
|
||||
18156 72940 84991 1703 52195 51508 69241 19989 53008 12238 42242 64635 15634 60106 77024 87058 9651 54192 61474 43286
|
||||
19732 62587 1905 79417 34766 34464 85636 53278 81372 51418 84479 9528 34358 85822 17584 2905 47330 3177 29246 16691
|
||||
15415 71488 81326 31049 41594 74702 34459 57598 38894 5933 17236 64979 68520 25493 60748 19638 59957 56384 79269 57682
|
||||
17802 73748 67210 58513 69570 1146 61418 33252 4323 665 49943 19738 78505 47622 57139 30100 32324 1598 4050 77571
|
||||
13883 21286 58902 88755 53132 29650 18394 29441 2386 14015 87123 26541 4115 70686 85054 80037 71832 62824 23289 76156
|
||||
63489 79585 12246 58347 43559 75738 4799 82235 83688 8849 76158 7572 36487 45060 12679 89619 81062 31073 29061 83449
|
||||
51440 32536 26342 55555 13222 21396 45592 85055 84220 75234 71211 64062 64819 89809 32409 24730 75547 43560 23317 69236
|
||||
58761 9476 83160 5248 60888 5839 11220 51951 43265 46633 51752 4705 79169 78094 60261 2392 15842 15853 3799 10062
|
||||
1087 81362 80476 72258 81171 29237 13340 66719 72797 36658 52307 41558 46134 45467 53159 17022 51306 70731 75325 4571
|
||||
27364 43429 15629 22885 31523 75890 31629 47365 8095 35428 63780 9183 26790 60608 87793 17962 6198 11134 1033 85347
|
||||
47792 53340 43258 10278 8807 6417 27300 66465 83500 18978 77389 20864 62407 3018 50101 10283 85260 81731 64000 3355
|
||||
27159 44132 18890 53950 14741 23036 78264 20939 34170 79297 16286 88314 42637 59544 8592 57796 72313 42244 34261 65813
|
||||
67574 28002 3029 39982 37372 53131 50265 32632 51214 30617 35988 78373 74750 61230 42323 5843 84266 36939 26782 34788
|
7
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input2.txt
Executable file
7
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input2.txt
Executable file
@ -0,0 +1,7 @@
|
||||
60
|
||||
148 312 197 86 339 444 102 186 136 118
|
||||
30 177 242 161 30 432 281 349 276 37
|
||||
426 95 12 354 347 294 443 157 213 222
|
||||
194 361 34 243 448 225 40 402 412 28
|
||||
20 442 205 114 455 236 46 237 437 323
|
||||
126 364 270 490 70 117 285 365 126 350
|
26
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input3.txt
Executable file
26
3rd-Semester-Fall-2022/PDS/Homework03/HW03_input3.txt
Executable file
@ -0,0 +1,26 @@
|
||||
200
|
||||
-2782 -25551 -8602 -15364 -12908 -23579 -25330 -22003
|
||||
-2854 -1104 -12268 -1829 -4658 -26906 -24245 -29246
|
||||
-24187 -25296 -5399 -2943 -2636 -825 -14677 -14568
|
||||
-16981 -26283 -465 -23903 -8126 -15535 -180 -17260
|
||||
-17438 -15135 -8977 -346 -15066 -10659 -22349 -17920
|
||||
-11763 -10969 -26101 -22773 -14227 -20346 -22020 -14767
|
||||
-15642 -27419 -17710 -24631 -4596 -2388 -9199 -21577
|
||||
-28671 -9664 -21832 -6797 -1551 -28365 -409 -25341
|
||||
-19852 -9386 -25687 -4918 -20045 -24388 -22838 -8160
|
||||
-11709 -18939 -934 -25937 -15638 -29306 -10704 -7632
|
||||
-3077 -4766 -2263 -7674 -7154 -11462 -5603 -5825
|
||||
-27478 -27436 -18974 -5381 -2153 -19384 -722 -22005
|
||||
-5122 -2761 -26923 -1520 -27149 -19761 -9680 -15211
|
||||
-15052 -16966 -17500 -690 -16272 -4556 -8323 -19350
|
||||
-9322 -16938 -3376 -16477 -28401 -8979 -22302 -2231
|
||||
-12767 -17629 -7613 -14920 -13365 -8335 -6925 -24839
|
||||
-11097 -3848 -26359 -14598 -29961 -12392 -29809 -21366
|
||||
-29358 -23661 -28408 -21983 -28217 -6731 -17685 -13892
|
||||
-22 -21061 -369 -4775 -40 -29023 -7006 -12808
|
||||
-23004 -14619 -27728 -6369 -29307 -11006 -1209 -16756
|
||||
-14854 -3920 -1354 -21168 -16312 -7516 -12534 -22023
|
||||
-7529 -10942 -14006 -5747 -24026 -1691 -25991 -24048
|
||||
-29104 -2712 -28823 -29144 -8087 -12181 -18304 -1092
|
||||
-26801 -22385 -13813 -2460 -3391 -15022 -19216 -24597
|
||||
-18943 -26922 -22117 -11607 -4438 -11003 -3630 -11968
|
Reference in New Issue
Block a user