Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Homeworks / homework1.cpp
diff options
context:
space:
mode:
Commit414396b1292e2790c28a26de0b5d18bab1c5728f (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-21 18:53:47 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-21 18:53:47 +0200
Files0bc08c8399c19073312fadea9b9a507d62e7d262 /Year 1/Programming introduction/Homeworks/homework1.cpp
uni-projects-414396b1292e2790c28a26de0b5d18bab1c5728f.tar
uni-projects-414396b1292e2790c28a26de0b5d18bab1c5728f.tar.gz
uni-projects-414396b1292e2790c28a26de0b5d18bab1c5728f.zip
Parent69e2c19137a467ea0870b0297b6611e8bddb9f7d (diff)
Solved exercise 0 of homework1.cpp
1 files changed, 60 insertions, 2 deletions
-rw-r--r--Year 1/Programming introduction/Homeworks/homework1.cpp62
diff --git a/Year 1/Programming introduction/Homeworks/homework1.cpp b/Year 1/Programming introduction/Homeworks/homework1.cpp
index f76c172..f443cb9 100644
--- a/Year 1/Programming introduction/Homeworks/homework1.cpp
+++ b/Year 1/Programming introduction/Homeworks/homework1.cpp
@@ -5,6 +5,65 @@
using namespace std;
/*
+ * Exercise 0
+ */
+
+double distanceBetweenPoints(int x1, int y1, int x2, int y2)
+{
+ int sideA = x1 - x2, sideB = y1 - y2;
+ return sqrt(sideA * sideA + sideB * sideB); // Pythagorean theorem
+}
+
+void ex0() {
+ // These should be precalculated, but this shows how they're found out
+ float const SLOPE_B = 2.828 / 2.828,
+ SLOPE_C = -2.828 / -2.828,
+ SLOPE_D = -2.828 / 2.828,
+ SLOPE_E = 2.828 / -2.828;
+
+ double x, y;
+ cin >> x >> y;
+
+ if (x == 0) // if it's on the Y ordinate
+ cout << "On a line" << endl;
+ else if (distanceBetweenPoints(0, 0, x, y) < 4.0) {
+ float pointSlope = y / x;
+
+ if (x == -2.828 || x == 2.828 || pointSlope == SLOPE_B || pointSlope == SLOPE_C || pointSlope == SLOPE_D || pointSlope == SLOPE_E)
+ cout << "On a line" << endl;
+ else if (y >= 0 && x > 0) { // Check 1st quadrant
+ if (pointSlope > SLOPE_B)
+ cout << "Inside green area!" << endl;
+ else if (x > 2.828)
+ cout << "Inside purple area!" << endl;
+ else
+ cout << "Inside yellow area!" << endl;
+ }
+ else if (y >= 0 && x < 0) { // Check 2nd quadrant
+ if (pointSlope < SLOPE_D)
+ cout << "Inside red area!" << endl;
+ else if (x > -2.828)
+ cout << "Inside pink area!" << endl;
+ }
+ else if (y < 0 && x < 0) { // Check 3rd quadrant
+ if (pointSlope > SLOPE_C)
+ cout << "Inside blue area!" << endl;
+ else if (x > -2.828)
+ cout << "Inside pink area!" << endl;
+ }
+ else { // Check 4th quadrant
+ if (pointSlope > SLOPE_E && x > 2.828)
+ cout << "Inside purple area!" << endl;
+ else
+ cout << "Inside yellow area!" << endl;
+ }
+ }
+ else if ((-2.0 < x && x < 2.0) && (-6.0 < y && y < -7.0)) // outside circle and in rectangle
+ cout << "Inside grey area" << endl;
+
+}
+
+/*
* Exercise 1
*/
@@ -177,7 +236,6 @@ void countBullsAndCows(int secretNum, int guess, int *bulls, int *cows) {
void playBullsAndCows() {
int secNum = genSecretNum(), guess = 0, bulls = 0, cows = 0;
- cout << secNum << endl;
for (int i = 0; i < N; i++) {
cin >> guess;
@@ -199,5 +257,5 @@ void ex5() {
}
int main() {
- ex5();
+ ex0();
}