About The Project: DEFINITION OF Calculator
About The Project: DEFINITION OF Calculator
DEFINITION OF Calculator
A calculator is a device that is used for performing mathematical calculations. It differs from a computer by having a limited problem solving ability and an interface optimized for interactive calculation rather than programming. Calculators can be hardware or software, mechanical or electronic, and are often built into devices such as PDAs or mobile phones. Modern electronic calculators are generally small, digital, (often pocketsized) and usually inexpensive.
History
The first calculators were abathia, and were often constructed as a wooden frame with beads sliding on wires. Abathias were in use centuries before the adoption of the written Arabic numerals system and are still used by some merchants, fishermen and clerks in Africa, Asia, and elsewhere.
Scottish mathematician and physicist John Napierr noted multiplication and division of numbers could be performed by addition and subtraction, respectively, of logarithms of those numbers. While producing the first logarithmic tables Napier needed to perform many multiplications, and it was at this point that he designed Napier's boness, an abacus-like device used for multiplication and division. In 1622 William Oughtredd invented the slide rule, which was revealed by his student Richard Delamain in 1630. Since real numberss can be represented as distances or intervals on a line, the slide rule allows multiplication and division operations to be carried out significantly faster than was previously possible. The devices were used by generations of engineers and other mathematically inclined professional workers, until the invention of the pocket caculator.
Advantages
In the past, mechanical clerical aids such as abaci, comptometers, Napier's bones, books of mathematical tables, slide rules, or mechanical adding machines were used for numeric work. This semi-manual process of calculation was tedious and error-prone. Modern calculators are electrically powered (usually by battery and/or solar cell) and vary from cheap, give-away, credit-card sized models to sturdy adding machine-like models with built-in printers. They first became popular in the late 1960s as decreasing size and cost of electronics made possible devices for calculations, avoiding the use of scarce and expensive computer resources. By the 1980s, calculator prices had reduced to a point where a basic calculator was affordable to most. By the 1990s they had become common in math classes in schools, with the idea that students could be freed from basic calculations and focus on the concepts. The market for calculators is extremely price-sensitive, to an even greater extent than the personal computer market; typically the user desires the least expensive model having a specific feature set, but does not care much about speed (since speed is constrained by how fast the user can press the buttons).
void main() { A a1; int a,b,c,ask=1,tel; float d; char x; while(ask==1) { reset: clrscr(); a1.priscl(); a1.prical(); cout<<"\n\n\n\n\n\n\n\n\t\tEnter number and press enter :"; cin>>a; more: clrscr(); cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; cout<<a; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t"; a1.prical(); cout<<"\n\n\n\n\n\n\n\n\t\tEnter operator or press c to reset\n\t\t\t\t and press enter :"; cin>>x; if(x=='c') goto reset; clrscr(); cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; cout<<a<<" "<<x; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t";
a1.prical(); cout<<"\n\n\n\n\n\n\n\n\t\tEnter number and press enter :"; cin>>b; clrscr(); cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; cout<<a<<" "<<x<<" "<<b<<" "; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t"; a1.prical(); switch(x) { case '+': c=a+b; break; case '-': c=a-b; break; case '*': c=a*b; break; case '/': c=a/b; break; } clrscr(); cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; cout<<a<<" "<<x<<" "<<b<<" = "<<c; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t"; a1.prical(); cout<<"\n\n\n\n\n\n\n\n\t\tTo calculate further press 1 otherwise 2 ";
cin>>tel; if(tel==1) { a=c; goto more; } clrscr(); cout<<"\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; cout<<a<<" "<<x<<" "<<b<<" = "<<c; cout<<"\n\n\n\n\n\n"; cout<<"\t\t\t\t"; a1.prical(); cout<<"\n\n\n\n\n\n\n\n\tPress 1 to calculate more and 2 to exit "; cin>>ask; } }
OUTPUT
1+ 1 4 7 2 5 8 0 3 6 9 + * /
PROJECT OF CALCULATOR IN C
#include <stdio.h> #include <conio.h> #include<dos.h> void priscl() { printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t"); } void prical() { printf("1 2 3"); printf("\n\n\n\n"); printf("\t\t\t\t"); printf("4 5 6"); printf("\n\n\n\n"); printf("\t\t\t\t"); printf("7 8 9"); printf("\n\n\n\n"); printf("\t\t\t\t"); printf(" } void main() { int a,b,c; float d; char x; clrscr(); priscl(); 9 0 ");
prical(); printf("\n\n\n\n\t\t\t\t"); scanf("%d",&a); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d",a); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); fflush(0); scanf("%c",&x); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c",a,x); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); if(x=='+') { scanf("%d",&b); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d",a,x,b); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); c=a+b; clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d = %d",a,x,b,c); printf("\n\n\n\n\n\n");
10
printf("\t\t\t\t"); prical(); } if(x=='-') { scanf("%d",&b); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d",a,x,b); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); c=a-b; clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d = %d",a,x,b,c); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); } if(x=='*') { scanf("%d",&b); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d",a,x,b); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); c=a*b; clrscr();
11
printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d = %d",a,x,b,c); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); } if(x=='/') { scanf("%d",&b); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d",a,x,b); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); d=(a/b); clrscr(); printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t"); printf("%d %c %d = %f",a,x,b,d); printf("\n\n\n\n\n\n"); printf("\t\t\t\t"); prical(); } getch(); }
12
OUTPUT
1 4 7 1 -------------------------------------------------1+ 1 4 7 2 5 8 0 -------------------------------------------------1+2=3 1 4 7 2 5 8 0 3 6 9 3 6 9 2 5 8 0 3 6 9
13
PROJECT OF CALCULATOR IN VB
Dim c As Integer Dim i, j As Integer Dim add1, add2, value, value1 As Double Dim adding As Double Dim d As Integer Private Sub Command1_Click() End End Sub Private Sub Command10_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "5" i=i+1 End If End Sub Private Sub Command11_Click() If (i = 0) Then
14
Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "6" i=i+1 End If End Sub Private Sub Command12_Click() j=0 c=0 value = Text1.Text Text1.Text = "" temp = 3 Text2.Text = 3 End Sub Private Sub Command13_Click() j=0 c=0 value = Text1.Text value = value * value Text1.Text = value i=0 End Sub Private Sub Command14_Click() If (i = 0) Then
15
Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "1" i=i+1 End If End Sub Private Sub Command15_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "2" i=i+1 End If End Sub Private Sub Command16_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep
16
Else Text1.Text = Text1.Text + "3" i=i+1 End If End Sub Private Sub Command17_Click() j=0 c=0 value = Text1.Text Text1.Text = "" temp = 4 Text2.Text = 4 End Sub Private Sub Command18_Click() j=0 value1 = Text1.Text If Text2.Text = "1" Then adding = value + value1 Text1.Text = adding i=0 ElseIf Text2.Text = "2" Then adding = value / value1 Text1.Text = adding i=0 ElseIf Text2.Text = "3" Then adding = value * value1 Text1.Text = adding i=0 ElseIf Text2.Text = "4" Then
17
adding = value - value1 Text1.Text = adding i=0 End If End Sub Private Sub Command19_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "0" i=i+1 End If End Sub Private Sub Command2_Click() Text1.Text = 0 i=0 End Sub Private Sub Command20_Click() If d = 0 Then Text3.Text = Text1.Text d=1 End If If j = 0 Then Text1.Text = "-" + Text3.Text
18
j=1 Else Text1.Text = "+" + Text3.Text j=0 End If End Sub Private Sub Command21_Click() If c = 0 Then Text1.Text = Text1.Text + "." c=1 End If End Sub Private Sub Command22_Click() d=0 c=0 value = Text1.Text Text1.Text = "" temp = 1 Text2.Text = 1 End Sub Private Sub Command3_Click() Text1.Text = 0 i=0 End Sub Private Sub Command4_Click() If (i = 0) Then Text1.Text = ""
19
End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "7" i=i+1 End If End Sub Private Sub Command5_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else Text1.Text = Text1.Text + "8" i=i+1 End If End Sub Private Sub Command6_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else
20
Text1.Text = Text1.Text + "9" i=i+1 End If End Sub Private Sub Command7_Click() j=0 c=0 value = Text1.Text Text1.Text = "" temp = 2 Text2.Text = 2 End Sub Private Sub Command8_Click() j=0 c=0 value = Text1.Text value = 1 / value Text1.Text = value i=0 End Sub Private Sub Command9_Click() If (i = 0) Then Text1.Text = "" End If If (i = 8) Then SendKeys "{backspace}" Beep Else
21
Text1.Text = Text1.Text + "4" i=i+1 End If End Sub Private Sub Form_Load() Top = (Screen.Height - Height) / 2 Left = (Screen.Width - Width) / 2 i=0 End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) SendKeys "{backspace}" End Sub
22
OUTPUT
23
24
Font f=new Font("Courier",Font.BOLD|Font.BOLD,18); Font f1=new Font("Courier",Font.BOLD|Font.BOLD,32); p1=new Panel(); p2=new Panel(); p3=new Panel(); p4=new Panel(); bt1=new Button("1"); bt2=new Button("2"); bt3=new Button("3"); bt4=new Button("4"); bt5=new Button("5"); bt6=new Button("6"); bt7=new Button("7"); bt8=new Button("8"); bt9=new Button("9"); bt0=new Button("0"); btclr=new Button("Clear"); bteq=new Button("="); btadd=new Button("+"); btsub=new Button("-"); btmul=new Button("*"); btdiv=new Button("/"); btdot=new Button("."); tf1=new TextField(""); p1.setLayout(new GridLayout(1,2)); p2.setLayout(new GridLayout(4,4)); p4.setLayout(new GridLayout(1,1)); p3.setLayout(null); p3.setBackground(Color.RED); p1.add(tf1); tf1.setBackground(Color.CYAN); tf1.setFont(f1); p4.add(btclr); bt1.setFont(f); bt2.setFont(f); bt3.setFont(f); bt4.setFont(f); bt5.setFont(f); bt6.setFont(f); bt7.setFont(f);
25
bt8.setFont(f); bt9.setFont(f); bt0.setFont(f); btclr.setFont(f); bteq.setFont(f); btadd.setFont(f); btsub.setFont(f); btmul.setFont(f); btdiv.setFont(f); btdot.setFont(f); p2.add(bt1); p2.add(bt2); p2.add(bt3); p2.add(bt4); p2.add(bt5); p2.add(bt6); p2.add(bt7); p2.add(bt8); p2.add(bt9); p2.add(bt0); p2.add(btdot); p2.add(bteq); p2.add(btadd); p2.add(btsub); p2.add(btmul); p2.add(btdiv); p3.add(p1); p1.setBounds(40,40,360,60); p3.add(p4); p4.setBounds(420,40,90,60); p3.add(p2); p2.setBounds(40,130,360,360); add(p3); setVisible(true); setSize(550,650); bt1.addActionListener(this); bt2.addActionListener(this); bt3.addActionListener(this); bt4.addActionListener(this); bt5.addActionListener(this);
26
bt6.addActionListener(this); bt7.addActionListener(this); bt8.addActionListener(this); bt9.addActionListener(this); bt0.addActionListener(this); btclr.addActionListener(this); btadd.addActionListener(this); btsub.addActionListener(this); btmul.addActionListener(this); btdiv.addActionListener(this); bteq.addActionListener(this); } public void actionPerformed(ActionEvent ae) { try { if(ae.getActionCommand()=="1") { if(yes==true)//if(oper=="+"||oper=="-"||oper=="*"|| oper=="/") { tf=""; tf=tf+"1"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; } else { tf=tf+"1"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="2") { if(yes==true) { tf=""; tf=tf+"2"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; }
27
else { tf=tf+"2"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="3") { if(yes==true) { tf=""; tf=tf+"3"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; } else { tf=tf+"3"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="4") { if(yes==true) { tf=""; tf=tf+"4"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; } else { tf=tf+"4"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="5") {
28
if(yes==true) { tf=""; tf=tf+"5"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; } else { tf=tf+"5"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="6") { if(yes==true) { tf=""; tf=tf+"6"; tf1.setText(tf); yes=false; var=Integer.parseInt(tf); } else { tf=tf+"6"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="7") { if(yes==true) { tf=""; tf=tf+"7"; tf1.setText(tf); yes=false; var=Integer.parseInt(tf); } else {
29
tf=tf+"7"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="8") { if(yes==true) { tf=""; tf=tf+"8"; tf1.setText(tf); yes=false; var=Integer.parseInt(tf); } else { tf=tf+"8"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="9") { if(yes==true) { tf=""; tf=tf+"9"; tf1.setText(tf); var=Integer.parseInt(tf); yes=false; } else { tf=tf+"9"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="0") { if(yes==true) {
30
tf=""; tf=tf+"0"; tf1.setText(tf); yes=false; var=Integer.parseInt(tf); } else { tf=tf+"0"; tf1.setText(tf); var=Integer.parseInt(tf); } } if(ae.getActionCommand()=="+") { oper="+"; temp1=tf1.getText(); yes=true; } if(ae.getActionCommand()=="-") { oper="-"; temp1=tf1.getText(); yes=true; } if(ae.getActionCommand()=="*") { oper="*"; temp1=tf1.getText(); yes=true; } if(ae.getActionCommand()=="/") { oper="/"; temp1=tf1.getText(); yes=true; } if(ae.getActionCommand()=="=") { if(oper=="+") {
31
res=Integer.parseInt(temp1)+var; put=Integer.toString(res); tf1.setText(put); temp1=Integer.toString(res); } if(oper=="-") { res=Integer.parseInt(temp1)-var; put=Integer.toString(res); tf1.setText(put); temp1=Integer.toString(res); } if(oper=="*") { res=Integer.parseInt(temp1)*var; put=Integer.toString(res); tf1.setText(put); temp1=Integer.toString(res); } if(oper=="/") { res=Integer.parseInt(temp1)/var; put=Integer.toString(res); tf1.setText(put); temp1=Integer.toString(res); } } if(ae.getActionCommand()=="Clear") { tf=""; tf1.setText(tf); yes=false; var=0; temp1=""; } } catch(NumberFormatException nfe) { JOptionPane.showMessageDialog(this,"No calculation done."); } } public static void main(String args[]) {
32
OUTPUT
33
34