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
|
// Calc.cpp : Defines the entry point for the application.
//
#include "Calc.h"
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
char menu1();
int addition(int a, int b);
void substraction(int a, int b);
int multiplication(int a, int b);
double circle(int a);
int triangle(int a, int b);
int square(int a);
void evenodd(int q);
//Calcualtor Menu
char menu1()
{
char choice = 'Z';
while ((choice > 'O') || (choice < 'A'))
{
cout << "Enter O to quit\n";
cout << "Enter A for Addition\n";
cout << "Enter B for Area of a Circle\n";
cout << "Enter C for Area of a Right triangle \n";
cout << "Enter D for Area of a Square \n";
cout << "Enter E for Covnert decimal to bases 2 - 16 \n";
cout << "Enter F for Exponent of 2 integers \n";
cout << "Enter G for Get Factorial \n";
cout << "Enter H for Even/odd \n";
cout << "Enter I for Integer Division \n";
cout << "Enter J for Get real division of 2 integers \n";
cout << "Enter K for Multiplication \n";
cout << "Enter L for Quotient of 2 numbers \n";
cout << "Enter M for Remainder if 2 integers \n";
cout << "Enter N for Substraction \n";
cin >> choice;
choice = toupper(choice); //Convert to non-case-sensitive
}
return choice;
}
//Calculator Menu Printout
int _tmain(int argc, _TCHAR* argv[])
{
int choice, i1, i2;
char s1[4], s2[4];
choice = menu1();
if (choice == 'Q')
return 0;
cout << "Enter number x: ";
cin >> s1;
i1 = atoi(s1);
if ((choice != 'G') && (choice != 'H') && (choice != 'B') && (choice != 'D'))
{
cout << "Enter number y: ";
cin >> s2;
}
i2 = atoi(s2);
if (choice == 'A')
cout << addition(i1, i2) << endl;
else if (choice == 'O')
substraction(i1, i2);
else if (choice == 'H')
evenodd(i1);
if (choice == 'L')
cout << multiplication(i1, i2) << endl;
else if (choice == 'B')
cout << "Area of circle: " << circle(i1) << endl;
if (choice == 'C')
cout << "Area of a Right triangle: " << triangle(i1, i2) << endl;
else if (choice == 'D')
cout << "Area of square: " << square(i1) << endl;;
}
//Addition: Choice 'A'
int addition(int a, int b)
{
return(a + b);
}
//Area of a circle: Choice 'B'
double circle(int a)
{
return (3.14*a*a);
}
//Area of a right triangle: Choice 'C'
int triangle(int a, int b)
{
return(((a*b) / 2));
}
//Area of a square: Choice 'D'
int square(int a)
{
return(a * a);
}
//Convert decimal to bases 2 - 16: Choice 'E'
//Even/Odd: Choice 'H'
void evenodd(int q)
{
if (q % 2 == 0)
cout << "Number " << q << " is even\n";
else cout << "Number " << q << " is odd\n";
}
// Multiplication: Choice 'L'
int multiplication(int a, int b)
{
return(a*b);
}
//Substraction: Choice 'O'
void substraction(int a, int b)
{
cout << a << " - " << b << " = " << a - b << endl;
}
|