{"id":25841957,"url":"https://github.com/courseworks/ap1400-2-hw6","last_synced_at":"2025-03-01T05:32:55.726Z","repository":{"id":38460914,"uuid":"496613202","full_name":"courseworks/AP1400-2-HW6","owner":"courseworks","description":"Advanced Programming - HW6","archived":false,"fork":false,"pushed_at":"2022-06-05T19:12:49.000Z","size":25,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-03-07T00:20:05.141Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/courseworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-26T12:33:00.000Z","updated_at":"2022-11-04T15:28:01.000Z","dependencies_parsed_at":"2022-08-19T06:21:16.444Z","dependency_job_id":null,"html_url":"https://github.com/courseworks/AP1400-2-HW6","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/courseworks","download_url":"https://codeload.github.com/courseworks/AP1400-2-HW6/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241322575,"owners_count":19944073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-01T05:32:55.166Z","updated_at":"2025-03-01T05:32:55.717Z","avatar_url":"https://github.com/courseworks.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advanced Programming - HW6\n\u003cp  align=\"center\"\u003e \u003cb\u003eHomework 6 - Spring 2022 Semester \u003cbr\u003e Deadline: Thursday khordad 12th - 11:59 pm\u003c/b\u003e \u003c/p\u003e\n\n## Outline\nIn this homework, we are going to Solve 4 questions using functions in the C++ STL library. Read each question carefully and write down your code.\n\n\u003c/br\u003e\n\n# Question 1\nIn this question, we want to implement the gradient descent algorithm in an STL way. As you know in gradient descent we aim to find where is the minimum of a function by moving in a way that our function is decreasing, like in the picture below:\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"resources/gradient_descent.jpeg\" alt=\"minor\"\ntitle=\"minor\" width=\"300\" align=\"middle\" /\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\nimplement a function called `gradient_descent` that calculates the minimum of any given math-function (like sine, cosine, ...). the math-function can be a pointer to function, lambda function or a functor (see tests 1 to 4). The first input of your function should be `the initial value` and the second input `the step size`.\n\n**Note.** implement all your code in `q1` namespace and `q1.h` file.\n\n\u003c/br\u003e\n\n# Question 2\nIn this question, we want to read the `resources/lung_cancer.csv` file and sort the patients by the possibility of whether or not they have lung cancer (in increasing order).\nFirst, implement a struct called `Patient` containing the necessary variables for a patient - something like this:\n\n```cpp\nstruct Patient\n{\n\tstd::string name;\n\tsize_t age;\n\tsize_t smokes;\n\tsize_t area_q;\n\tsize_t alkhol;\n};\n```\n\n**Note.** store both the first name and last name of the patients in the `name` variable in the above struct like `\"John Wick\"`.\n\nThen implement the `read_file` function and read the `resources/lung_cancer.csv` content and create a std::vector of the patients.\n\n```cpp\nstd::vector\u003cPatient\u003e read_file(std::string filename)\n```\n\nFinally, implement a function called `sort` and sort the patients by their possibility of having lung cancer. To sort them you have to compare the sum of the variables of each patient with the below weights:\n\n```cpp\n3*age + 5*smokes + 2*area_q + 4*alkhol\n```\n**Note.** you are not allowed to use any `for` in your `sort` function.\n\n**Note.** implement all your code in `q2` namespace and `q2.h` file.\n\n\u003c/br\u003e \n\n# Question 3\nIn this question, we want to store the flights in the `resources/flights.txt` file, in a `std::priority_queue` container.\nLike question2 create a struct for each flight like below:\n\n```cpp\nstruct Flight\n{\n\tstd::string flight_number;\n\tsize_t duration;\n\tsize_t connections;\n\tsize_t connection_times;\n\tsize_t price;\n};\n```\n\n**Note.** each flight may have one or more connections and therefore connection-times. the variable named `connection_times` is the overall connection time of the flight.\n\nNow implement a function called `gather_flights` and return a priority queue containing all the flights in the file. Your function has one input which is the `filename` i.e. `flights.txt`. To compare the flights you should compare the weighted sum of the properties of each flight with the below weights:\n\n```cpp\nduration + connection_times + 3*price\n```\n\n**Note.** you are not allowed to use any `for` in your `gather_flights` function.\n\n**Note.** implement all your code in `q3` namespace and `q3.h` file.\n\n\u003c/br\u003e\n\n# Question 4\nIn this question, we want to implement an algorithm called `kalman_filter` (at least a simple version of it).\nKalman filter is used to find the best estimate of a state by combining measurements from various sensors. meaning, sometimes to have a more accurate measurement of a variable you would use multiple sensors instead of just one and calculate the mean of these sensors as your measurement. It is worth mentioning: your sensors do not always have the same accuracy so instead of calculating the pure mean of your sensor, you should calculate the weighted mean of your sensors based on their accuracy.\nThe sensors we want to use in this question are position sensors that measure the position in a 2D plane.\nSo, implement the struct below to represent our position sensors. (you can add constructors or other stuff if needed)\n\n```cpp\nstruct Vector2D\n{\ndouble x{};\ndouble y{}; \n};\n\nstruct Sensor\n{\n\tVector2D pos;\n\tdouble accuracy;    \n};\n```\n\nand implement the below function for the kalman-filter:\n\n```cpp\nVector2D kalman_filter(std::vector\u003cSensor\u003e sensors)\n```\n\nthis function calculates our final position measurement based on the kalman-filter of `sensors`.\n\n**Note.** again you are not allowed to use any `for` in your `gather_flights` function.\n\n**Note.** implement all your code in `q4` namespace and `q4.h` file.\n\n\n\u003c/br\u003e\n\n# Finally\nAs mentioned before, do not alter other files already populated except otherwise indicated. In case you want to test your code you may use the `debug` section of the `main.cpp`.\n\n```cpp\nif (true) // make false to run unit tests  \n{ \n\t// debug section \n}  \nelse  \n{  \n\t::testing::InitGoogleTest(\u0026argc, argv);  \n\tstd::cout \u003c\u003c \"RUNNING TESTS ...\" \u003c\u003c std::endl;  \n\tint ret{RUN_ALL_TESTS()};  \n\tif (!ret)  \n\t\tstd::cout \u003c\u003c \"\u003c\u003c\u003cSUCCESS\u003e\u003e\u003e\" \u003c\u003c std::endl;  \n\telse  \n\t  std::cout \u003c\u003c \"FAILED\" \u003c\u003c std::endl;  \n}  \nreturn 0;\n```\n\u003cbr/\u003e\n\u003cp  align=\"center\"\u003e \u003cb\u003eGOOD LUCK\u003c/b\u003e \u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap1400-2-hw6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourseworks%2Fap1400-2-hw6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap1400-2-hw6/lists"}