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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
// Calculator 2.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <windows.h>
using namespace std;
void cls(HANDLE hConsole);
void Area();
void Volume();
int input, another_input;
double x, y, b, h, s, base_one, base_two, l, w;
const int rest = 4000; // This gives about 4 seconds before screen clears. Increase/decrease to change delay.
int main(int)
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
do
{
cls(hStdout);
cout << " ** MAIN MENU ** \n\n";
cout << "1. Multiplication\n";
cout << "2. Division\n";
cout << "3. Addition\n";
cout << "4. Subtraction\n";
cout << "5. Square\n";
cout << "6. Square Root\n";
cout << "7. Formulas\n\n";
cout << "8. Quit\n\n";
cout << "Select choice :\n";
cin >> input;
cls(hStdout);
switch (input)
{
case 1:
cout << "Please enter two numbers to be multiplied.";
cout << "First number : ";
cin >> x;
cout << "Now the second number : ";
cin >> y;
cout << "The product of " << x << " and " << y << " is " << x*y;
Sleep(rest);
break;
case 2:
cout << "Please enter two numbers to be divided.\n";
cout << "First number : ";
cin >> x;
cout << "Now the second number : ";
cin >> y;
cout << x << " divided by " << y << " is " << x/y;
Sleep(rest);
break;
case 3:
cout << "Please enter two numbers to be added.\n";
cout << "First number : ";
cin >> x;
cout << "Now the second number : ";
cin >> y;
cout << "The sum of " << x << " and " << y << " is " << x+y;
Sleep(rest);
break;
case 4:
cout << "Please enter two numbers to be subtracted.\n";
cout << "First number : ";
cin >> x;
cout << "Now the second number : ";
cin >> y;
cout << "The difference between " << x << " and " << y << " is " << x-y;
Sleep(rest);
break;
case 5:
cout << "Please enter a number to be squared and press ENTER:\n";
cin >> x;
cout << x << " squared is " << x*x << ".";
Sleep(rest);
break;
case 6:
cout << "Please enter a number to find it's square root and press ENTER:\n";
cin >> x;
cout << "the square root of " << x << " is " << sqrt(x) << ".";
Sleep(rest);
break;
case 7:
cout << "**FORMULAS**\n\n";
cout << "1. Area\n";
cout << "2. Volume\n\n";
cout << "Select formula type: ";
cin >> another_input;
cls(hStdout);
switch(another_input)
{
case 1:
Area();
break;
case 2:
Volume();
break;
}
}
} while (input!=8);
return 0;
}
void Volume()
{
int another_input;
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
cls(hStdout);
cout << "**VOLUME**\n\n";
cout << "1. Cube\n";
cout << "2. Rectangular Prism\n";
cout << "3. Pyramid\n\n";
cout << "Select volume type: ";
cin >> another_input;
switch (another_input)
{
case 1:
cout << "Please enter the side length of your cube and press ENTER: ";
cin >> s;
cout << "\nThe volume of your cube is " << s*s*s << ".";
Sleep(rest);
break;
case 2:
cout << "Please enter the length and press ENTER: ";
cin >> l;
cout << "Please enter the width and press ENTER: ";
cin >> w;
cout << "Please enter the height and press ENTER: ";
cin >> h;
cout << "\nThe volume of your rectangular prism is " << l*w*h << ".";
Sleep(rest);
break;
case 3:
cout << "Please enter the base and press ENTER: ";
cin >> b;
cout << "Please enter the height and press ENTER: ";
cin >> h;
cout << "\nThe volume of your pyramid is " << (b*h)/3 << ".";
Sleep(rest);
}
}
void Area()
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
int yet_another_input;
cls(hStdout);
cout << "**AREA**\n\n";
cout << "1. Triangle\n";
cout << "2. Square\n";
cout << "3. Rectangle\n";
cout << "4. Parallelogram\n";
cout << "5. Trapezoid\n\n";
cout << "Please select area formula: ";
cin >> yet_another_input;
switch(yet_another_input)
{
case 1:
cout << "Please enter the base of your triangle and press ENTER: ";
cin >> b;
cout << "Please enter the height of your triangle and press ENTER: ";
cin >> h;
cout << "\nThe area of your triangle is " << (b*h)/2 << ".";
Sleep(rest);
break;
case 2:
cout << "Please enter a side length of the square and press ENTER: ";
cin >> s;
cout << "\nThe area of your square is " << s*s << ".";
Sleep(rest);
break;
case 3:
cout << "Please enter the base of the rectangle and press ENTER: ";
cin >> b;
cout << "Please enter the height of the rectangle and press ENTER: ";
cin >> h;
cout << "\nThe area of the rectangle is " << b*h << ".";
Sleep(rest);
break;
case 4:
cout << "Please enter the base of the parallelogram and press ENTER: ";
cin >> b;
cout << "Please enter the height of the parallelogram and press ENTER: ";
cin >> h;
cout << "\nThe area of the parallelogram is " << b*h << ".";
Sleep(rest);
break;
case 5:
cout << "Please enter the height of the trapezoid and press ENTER: ";
cin >> h;
cout << "Please enter the first base and press ENTER: ";
cin >> base_one;
cout << "Please enter the second base and press ENTER: ";
cin >> base_two;
cout << "\nThe area of your trapezoid is " << (base_one+base_two)*(h/2) << ".";
Sleep(rest);
}
}
void cls( HANDLE hConsole)
{
COORD coordScreen = { 0, 1 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if( !FillConsoleOutputCharacter( hConsole, // Handle to console screen buffer
(TCHAR) ' ', // Character to write to the buffer
dwConSize, // Number of cells to write
coordScreen, // Coordinates of first cell
&cCharsWritten ))// Receive number of characters written
{
return;
}
// Get the current text attribute.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
// Set the buffer's attributes accordingly.
if( !FillConsoleOutputAttribute( hConsole, // Handle to console screen buffer
csbi.wAttributes, // Character attributes to use
dwConSize, // Number of cells to set attribute
coordScreen, // Coordinates of first cell
&cCharsWritten )) // Receive number of characters written
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition( hConsole, coordScreen );
}
|