Oops Microproject
Oops Microproject
1. Calculators are widely used device nowadays It makes calculations easier and
faster.
2. Calculators are used to everyone in daily life. A simple calculator can be made using
a C++ program which is able to add, subtract, multiply and divide, two operands
entered by the user.
4. This program takes an arithmetic operator (+, -, *, /) and two operands from a user
and performs the operation on those two operands depending upon the operator
entered by the user.
6. Some of the scientific calculators are used to perform complex calculation more
easily like square root, function, exponential operations, logarithm, trigonometric
function and hyperbolic function, etc.
7. In this section, we will create calculator program in C++ using function and do-
while loop.
INTRODUCTION
2. the most basic calculator is the four-function calculator, which can perform basic
arithmetic such as addition, subtraction, multiplication and division. These are sometimes
called pocket calculators or hand-held electronic calculators because they are small enough to
fit in a shirt pocket.
Purpose: -
1. Calculators are simply a tool students use to help solve problems. Since they
eliminate tedious computations and algebraic manipulations that discourage many
students, calculators allow more students to solve problems and appreciate the power and
value of mathematics in the world today.
Material: -
To understand this example, you should have the knowledge of the following C++
programming topics:
Method: -
This program takes an operator and two operands from the user. The operator is stored
in variable op and two operands are stored in num1 and num2 .Respectively. Then, switch...case
statement is used for checking the operator entered by user. If user enters + then, statements for
case: '+' is executed and program is terminated. If user enters - then, statements for case: '-'
is executed and program is terminated. His program works similarly for the * and / operators.
But, if the operator doesn't matches any of the four character [+, -, * and /], the default statement
is executed which displays error message.
Theoretical Background: -
*What is a calculator?
A calculator is a device that performs arithmetic operations on numbers. Basic calculators can
do only addition, subtraction, multiplication and division mathematical calculations. However,
more sophisticated calculators can handle exponential operations, square roots, logarithms,
trigonometric functions and hyperbolic functions. Internally, some calculators perform all these
functions by repeated addition processes. The evolution of the calculator Most calculators these days
require electricity to operate or are battery-powered calculators. Calculators work by
performing programmed functions based on numerical inputs. Before the electronic calculator
(circa 1970), a more primitive calculator, the slide rule, was commonly used. It consisted of a slat of
wood called the slide that could be moved in and out of a reinforced pair of slats. Both the slide and
the outer pair of slats had calibrated numerical scales.
This technology allows students solve complicated problems quickly and in an efficient
manner. Additionally, it can reduce the problem to simpler tasks and allows the student to devote
more time in understanding the problem. Secondly, they are saved from monotonous
calculations and the same boring mundane procedure
Variables can be used in any equation and are substituted for their assigned value. Variables can
be inserted using the x button.
A computer can perform any operation that a calculator is capable of performing, but a
calculator cannot carry out the logical and highly complex problems. The reason behind this is that
a computer can be programmed to make decisions, but a calculator is not equipped with that
technology.
ALGORITHUM
Step 1: Start
Step 2: The operator is stored in variable op and two operands are stored in num1 and num2
respectively.
Step 3: Then, switch...case statement is used for checking the operator entered by user.
Step 4: If user enters + then, statements for case: '+' is executed and program is terminated.
Step 5: If user enters - then, statements for case: '-' is executed and program is terminated.
Step 6: This program works similarly for the * and / operators. But, if the operator doesn't matches
any of the four character [ +, -, * and / ], the default statement is executed which displays error
message.
Step 7: End
Coding
#include<iostream.h>
#include<conio.h>
class super
{
char ch;
int a,b;
float val;
public:
super ()
{
cout<<"\nEnter Opration:";
cin>>ch;
cout<<"\nEnter two values";
cin>>a>>b;
}
void Cal()
{
if(ch =='+')
{
val = a+b;
cout<<"\nAddition is:"<<val;
}
else if(ch=='-')
{
val = a-b;
cout<<"\nSubtraction is:"<<val;
}
else if(ch =='/')
{
val = a/b;
cout<<"\nDivision is:"<<val;
}
else if(ch == '*')
{
val = a*b;
cout<<"\nMultiplication is:"<<val;
}
else if(ch == '%')
{
val = a%b;
cout<<"\nModulous is:"<<val;
}
}
};
void main()
{
clrscr();
char x;
do
{
super s;
s.cal();
cout<<"\nEnter N to exit Enter Y to continue:\n";
cin>>(x);
}while(x != 'n');
getch();
}