summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index 892f002..5d3d070 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -6,35 +6,42 @@
using namespace std;
-const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //I don't fully understand everything going on with printing in color, but I *think* that this creates a way to access the console so that the program can change text colors.
//I always put constants in all caps. Makes it easier to see what never gets changed.
-const float EARTH_GRAVITY = 9.807; //(m/s)
+const float EARTH_GRAVITY = 9.807; // m/s
-//Prints in full color with (optional) automatic line breaks. Requires <windows.h> Returns nothing and takes up to 4 parameters:
-//console (HANDLE): Used for colored text. Always set it to hConsole and don't worry about it.
+//Uses black magic to print in full color with (optional) automatic line breaks. Requires <windows.h>. Returns nothing and takes up to 4 parameters:
//text (string): The text to be printed. Don't put a newline at the end.
//color (int): The color code of the text. Optional, defaults to white.
//linebreak (bool): Whether to end the line after printing. Optional, defaults to true.
+//console (HANDLE) the console the function is printing to, used for changing color. Defaults to hConsole, so as long as you define the console as hConsole somewhere, you can probably ignore it.
void colorPrint(string text, int color = 15, bool linebreak = true, HANDLE console = hConsole)
{
- SetConsoleTextAttribute(console, color); //Use black magic (native OS commands) to change the color of any text we print.
+ SetConsoleTextAttribute(console, color); //Change the output color to whatever is chosen for the text (defaults to 15, which is white).
cout << text;
- SetConsoleTextAttribute(console, 15); //Use more black magic to set the color back to white so that we don't start randomly printing other colors.
+ SetConsoleTextAttribute(console, 15); //Use moret the color back to white so that we don't start randomly printing other colors.
if (linebreak) //Add a line break to the end of the text unless told not to
{
cout << endl;
}
}
+//I made this to avoid having to write a dozen lines of couts and colorPrints just to print multiple colors in a line. It basically just loops through a list of text blocks and colorPrints each of them. Requires <windows.h> and colorPrint. Returns nothing and takes up to 2 parameters:
+//text (vector): All the text fragments. Made up of a series of tuples (a different type of list that can contain multiple data types) containing the following elements:
+// string: The block of text to be printed. Don't put a newline of endl at the end.
+// int: The color of the block of text. 15 is white.
+// bool: Whether to add a line break at the end of the block.
+//console (HANDLE) the console the function is printing to, used for changing color. Defaults to hConsole, so as long as you define the console as hConsole somewhere, you can probably ignore it.
void multiColorPrint(vector<tuple<string, int, bool> > text, HANDLE console = hConsole)
{
string fragmentText;
int fragmentColor;
bool fragmentBreak;
- for (auto i : text) {
- tie(fragmentText, fragmentColor, fragmentBreak) = i;
- colorPrint(fragmentText, fragmentColor, fragmentBreak, console);
+
+ for (auto i : text) { //Loop through the text data
+ tie(fragmentText, fragmentColor, fragmentBreak) = i; //"Unpack" the current block tuple and pass its elements to their respective variables.
+ colorPrint(fragmentText, fragmentColor, fragmentBreak, console); //Print the current block.
}
}
@@ -77,11 +84,11 @@ void aspectRatio(float width, float height)
colorPrint("Well, your aspect ratio is higher than 1, but this seems a little overkill.", 6);
}
else if (ratio >= 1) {
- colorPrint("Your kite will fly nice and stable, provided you actually know how to fly it.", 10);
+ colorPrint("Your kite will fly nice and stable. Have fun!", 10);
}
else
{
- colorPrint("Your kite is too wide and will be unstable. Or you could just, like, fly it sideways or something.", 6);
+ colorPrint("Your kite is too wide, and will be unstable. Consider widening it or flying it sideways.", 6);
}
}
@@ -91,19 +98,27 @@ float calculateKiteMass(float area)
return area * 0.135;
}
+//Returns the gravitational pull.
+float calculateKiteGForce(float mass)
+{
+ return mass * EARTH_GRAVITY;
+}
+
int main()
{
float width, height;
+ //Say hi to the user.
colorPrint("Welcome to Kite Calculator, can I take your order.", 13);
+ //Get the dimensions of the kite from the user.
colorPrint("Let's start with getting the dimensions of your kite.", 9);
width = getWidthOrHeight("width");
height = getWidthOrHeight("height");
cout << endl;
//Tell the user what they just entered, because...reasons.
- colorPrint("Great job. Let's do some math.", 10);
+ colorPrint("Now, let's do some math.", 10);
multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite is ", 15, false), make_tuple(to_string(width) + "cm", 11, false), make_tuple(" wide and ", 15, false), make_tuple(to_string(height) + "cm", 11, false), make_tuple(" high.", 15, true), }); //I hate this but its still better than stacking like 20 couts.
colorPrint("I'm sure it's beautiful.\n", 9);
@@ -115,8 +130,13 @@ int main()
//Do aspect ratio stuff.
aspectRatio(width, height);
+ //Do mass stuff.
const float MASS = calculateKiteMass(AREA);
multiColorPrint(vector<tuple<string, int, bool> >{make_tuple("Your kite has a mass of ", 15, false), make_tuple(to_string(MASS) + " kilograms", 11, false), make_tuple(".", 15, true)});
+ //Do gravity stuff.
+ const float G_FORCE = calculateKiteGForce(MASS);
+ multiColorPrint(vector<tuple<string, int, bool> >{make_tuple("The gravitational pull on your kite is ", 15, false), make_tuple(to_string(G_FORCE) + " newtons", 11, false), make_tuple(".", 15, true)});
+
return 0;
} \ No newline at end of file