-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSv2.1.h
186 lines (181 loc) · 5.3 KB
/
MSv2.1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef _MSv2_1_h
#define _MSv2_1_h
#include <Windows.h>
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
void setColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void factor() {
char again;
int b, c, u, v;
bool canfactor;
cout << "This polynomial factorer assumes that the value of a, or the number next to x² is always 1.\n";
cout << "Enter the coefficient of x: ";
cin >> b;
cout << "Enter the constant: ";
cin >> c;
canfactor = true;
double discriminant;
int temp;
discriminant = b * b - 4 * c;
if (discriminant < 0)
canfactor = false;
else {
temp = static_cast<int>(sqrt(discriminant));
if (temp * temp != discriminant)
canfactor = false;
else {
if (((-b + temp) % 2) != 0 || ((-b - temp) % 2) != 0)
canfactor = false;
else {
u = (b + temp) / 2;
v = (b - temp) / 2;
}
}
}
//canfactor is the bool variable that makes sure that this is not a non factorable function.
if (canfactor) {
//these if statements just format the output so that the positive numbers get a + sign in front of them. The negatives already have a - sign, the they are in else statements.
if (b >= 0)
cout << "x^2 + " << b << "x";
else
cout << "x^2 " << b << "x";
if (c >= 0)
cout << " + " << c << " factored is\n";
else
cout << " " << c << " factored is\n";
cout << "(x ";
if (u >= 0)
cout << "+ " << u;
else
cout << u;
cout << ") (x ";
if (v >= 0)
cout << "+ " << v;
else
cout << v;
cout << ")\n\n";
//This simple code turns the values of x into their positives then prints them out.
if (u > 0)
u -= (2*u);
else if (u < 0)
u += (-2*u);
if (v > 0)
v -= (2*v);
else if (v < 0)
v += (-2*v);
cout << "So, x is " << u << " and " << v << ".\n";
}
else {
cout << "This function is not factorable.\n";
}
cout << "Would you like to factor something else? (y or n)\n";
cin >> again;
if (again == 'y') {
factor();
}
else
return;
}
void Multiples() {
int timesdone = 0;
int times = 0;
int i = 0;
char hr = 'h';
int first = 0;
int second = 0;
cout << "Which two numbers would you like to find multiples of?" << endl << "1st number: ";
cin >> first;
cout << "Okay, first number is " << first << ".\nNow enter your second number: ";
cin >> second;
cout << "Great, now how many multiples would you like me to find? (Just one works too)" << endl;
cin >> times;
cout << endl << "Okay! That will do!" << endl;
string goback = "notyet";
while (goback != "goback") {
if (timesdone == times) {
cout << "Would you like to go back home?"<< endl << "Click H to go back home and R to restart this!" << endl;
cin >> hr;
if (hr == 'H' || hr == 'h') {
goback = "goback";
}
else if (hr == 'R' || hr == 'r' ) {
Multiples();
}
else {
}
}
if (i % first == 0 && i % second == 0) {
cout << i << endl;
timesdone++;
}
i++;
}
}
void Triangles() {
float base = 0;
float height = 0;
float hypo = 0;
float area = 0;
char hr = 'h';
cout << "Enter the base of your triangle: ";
cin >> base;
cout << endl << "Now enter the height of your triangle: ";
cin >> height;
hypo = (base * base) + (height * height);
hypo = sqrt(hypo);
area = (base * 0.5) * height;
cout << "The hypotenuse of the triangle with the dimensions you entered with:\n Base: " << base << "\n Height: " << height << endl;
cout << "Has:\n Hypotenuse: " << hypo << "\n Area: " << area << endl;
cout << "Would you like to go back home?"<< endl << "Click H to go back home and R to restart this!" << endl;
cin >> hr;
if (hr == 'H' || hr == 'h')
return;
else if (hr == 'r' || hr == 'R' )
Triangles();
else
return;
}
void Calculator() {
char op = '*';
char hr;
int first = 0;
int second = 0;
cout << "Enter operator. ^, +, -, %, *:" << endl;
cin >> op;
cout << "Enter your first, then your second integer to go in.\n";
cin >> first >> second;
int result;
switch (op) {
case '^':
result = pow(first, second);
break;
case '+':
result = first + second;
break;
case '-':
result = first - second;
break;
case '%':
result = first % second;
break;
case '*':
result = first * second;
break;
default:
exit(0);
break;
}
cout << "Answer: " << result << endl;
cout << "Would you like to go back home?"<< endl << "Click H to go back home and R to restart this!" << endl;
cin >> hr;
if (hr == 'H' || hr == 'h') {
}
else if (hr == 'R' || hr == 'r' ) {
Calculator();
}
}
#endif