summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp142
1 files changed, 0 insertions, 142 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
deleted file mode 100644
index 5d3d070..0000000
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-#include <iostream>
-#include <string> //used for converting things to strings
-#include <vector> //feeding my crippling addiction to overengineering everything
-#include <tuple> //^^^
-#include <windows.h> //colored couts go brrrr :)
-
-using namespace std;
-
-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
-
-//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); //Change the output color to whatever is chosen for the text (defaults to 15, which is white).
- cout << text;
- 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) { //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.
- }
-}
-
-//Super messy and really just here because if you're reusing more than one line, you're doing something wrong.
-float getWidthOrHeight(string d)
-{
- float input;
- vector<tuple< string, int, bool> > text;
- text.push_back(make_tuple("Please enter the ", 15, false));
- text.push_back(make_tuple(d, 11, false));
- text.push_back(make_tuple(" of your kite in ", 15, false));
- text.push_back(make_tuple("cm", 11, false));
- text.push_back(make_tuple(": ", 15, false));
- while (true)
- {
- multiColorPrint(text);
- if (cin >> input && 1 <= input <= 400) //This feels so wrong but it does in fact work.
- {
- break;
- }
- colorPrint("Oh no! It looks like something went wrong.\nPlease make sure your width is a number between 1 and 400 and try again.", 12);
- cin.clear();
- cin.ignore(80, '\n');
- }
- return input;
-}
-
-//Return the kite's area in square meters.
-float calulateKiteArea(float width, float height)
-{
- return ((width * height) / 2) / 10000;
-}
-
-//Computes and prints aspect ratio
-void aspectRatio(float width, float height)
-{
- float ratio = width / height;
- multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite has an aspect ratio of ", 15, false), make_tuple(to_string(ratio), 11, false), make_tuple(". ", 15, false)});
- if (ratio >= 5) {
- 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. Have fun!", 10);
- }
- else
- {
- colorPrint("Your kite is too wide, and will be unstable. Consider widening it or flying it sideways.", 6);
- }
-}
-
-//Returns the mass of the kite in kilograms.
-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("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);
-
- //Calculate the kite's area and tell it to the user.
- const float AREA = calulateKiteArea(width, height);
- multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite has an area of ", 15, false), make_tuple(to_string(AREA) + " square meters", 11, false), make_tuple(". ", 15, true)});
- cout << endl;
-
- //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