Skip to main content

Write a program to dispaly the different operation of calculator in C++

  1. #include<iostream.h>  
  2. #include<stdio.h>  
  3. #include<conio.h>  
  4. #include<math.h>  
  5. #include<stdlib.h>  
  6. void add();  
  7. void sub();  
  8. void multi();  
  9. void division();  
  10. void sqr();  
  11. void srt();  
  12. void exit();  
  13. void main()  
  14. {  
  15. clrscr();  
  16. int opr;  
  17. // display different operation of the calculator  
  18. do  
  19. {  
  20. cout << "Select any operation from the C++ Calculator"  
  21.      "\n1 = Addition"  
  22.      "\n2 = Subtraction"  
  23.      "\n3 = Multiplication"  
  24.      "\n4 = Division"  
  25.      "\n5 = Square"  
  26.      "\n6 = Square Root"  
  27.      "\n7 = Exit"  
  28.      "\n \n Make a choice: ";  
  29.      cin >> opr;  
  30.   
  31.    switch (opr)  
  32.      {  
  33.      case 1:  
  34.     add();   // call add() function to find the Addition  
  35.     break;  
  36.     case 2:  
  37.     sub();   // call sub() function to find the subtraction  
  38.     break;  
  39.     case 3:  
  40.     multi(); // call multi() function to find the multiplication  
  41.     break;  
  42.     case 4:  
  43.     division(); // call division() function to find the division  
  44.     break;  
  45.     case 5:  
  46.     sqr(); // call sqr() function to find the square of a number  
  47.     break;  
  48.     case 6:  
  49.     srt(); // call srt() function to find the Square Root of the given number  
  50.     break;  
  51.     case 7:  
  52.     exit(0);   // terminate the program  
  53.     break;  
  54.     default:  
  55.     cout <<"Something is wrong..!!";  
  56.     break;  
  57.     }  
  58.     cout <<" \n------------------------------\n";  
  59.     }while(opr != 7);  
  60.     getch();  
  61.     }  
  62.   
  63. void add()  
  64. {  
  65. int n, sum = 0, i, number;  
  66. cout <<"How many numbers you want to add: ";  
  67. cin >> n;  
  68. cout << "Please enter the number one by one: \n";  
  69. for (i = 1; i <= n; i++)  
  70. {  
  71. cin >> number;  
  72. sum = sum + number;  
  73. }  
  74. cout << "\n Sum of the numbers = "<< sum;  
  75. }  
  76. void sub()  
  77. {  
  78. int num1, num2, z;  
  79. cout <<" \n Enter the First number = ";  
  80. cin >> num1;  
  81. cout << "\n Enter the Second number = ";  
  82. cin >> num2;  
  83. z = num1 - num2;  
  84. cout <<"\n Subtraction of the number = " << z;  
  85. }  
  86. void multi()  
  87. {  
  88. int num1, num2, mul;  
  89. cout <<" \n Enter the First number = ";  
  90. cin >> num1;  
  91. cout << "\n Enter the Second number = ";  
  92. cin >> num2;  
  93. mul = num1 * num2;  
  94. cout <<"\n Multiplication of two numbers = " << mul;  
  95. }  
  96. void division()  
  97. {  
  98. int num1, num2, div = 0;  
  99. cout <<" \n Enter the First number = ";  
  100. cin >> num1;  
  101. cout << "\n Enter the Second number = ";  
  102. cin >> num2;  
  103. while ( num2 == 0)  
  104.      {  
  105.      cout << "\n Divisor canot be zero"  
  106.          "\n Please enter the divisor once again: ";  
  107.          cin >> num2;  
  108.          }  
  109. div = num1 / num2;  
  110. cout <<"\n Division of two numbers = " << div;  
  111. }  
  112. void sqr()  
  113. {  
  114. int num1;  
  115. float sq;  
  116. cout <<" \n Enter a number to find the Square: ";  
  117. cin >> num1;  
  118. sq = num1 * num1;  
  119. cout <<" \n Square of " << num1<< " is : "<< sq;  
  120. }  
  121. void srt()  
  122. {  
  123. float q;  
  124. int num1;  
  125. cout << "\n Enter the number to find the Square Root:";  
  126. cin >> num1;  
  127. q = sqrt(num1);  
  128. cout <<" \n Square Root of " << num1<< " is : "<< q;  
  129. }  
Anurag Rana Educator CSE/IT

Comments

Popular posts from this blog

JAVA Scrollbar, MenuItem and Menu, PopupMenu

ava AWT Scrollbar The  object  of Scrollbar class is used to add horizontal and vertical scrollbar. Scrollbar is a  GUI  component allows us to see invisible number of rows and columns. AWT Scrollbar class declaration public   class  Scrollbar  extends  Component  implements  Adjustable, Accessible   Java AWT Scrollbar Example import  java.awt.*;   class  ScrollbarExample{   ScrollbarExample(){               Frame f=  new  Frame( "Scrollbar Example" );               Scrollbar s= new  Scrollbar();               s.setBounds( 100 , 100 ,  50 , 100 );               f.add(s);               f.setSize( 400 , 400 );               f.setLayout( null );               f.setVisible( true );   }   public   static   void  main(String args[]){           new  ScrollbarExample();   }   }   Output: Java AWT Scrollbar Example with AdjustmentListener import  java.awt.*;   import  java.awt.event.*;   class  ScrollbarExample{        ScrollbarExample(){               Frame f=  new  Frame( "Scro

Difference between net platform and dot net framework...

Difference between net platform and dot net framework... .net platform supports programming languages that are .net compatible. It is the platform using which we can build and develop the applications. .net framework is the engine inside the .net platform which actually compiles and produces the executable code. .net framework contains CLR(Common Language Runtime) and FCL(Framework Class Library) using which it produces the platform independent codes. What is the .NET Framework? The Microsoft .NET Framework is a platform for building, deploying, and running Web Services and applications. It provides a highly productive, standards-based, multi-language environment for integrating existing investments with next-generation applications and services as well as the agility to solve the challenges of deployment and operation of Internet-scale applications. The .NET Framework consists of three main parts: the common language runtime, a hierarchical set of unified class librari

C++ this Pointer, static, struct and Enumeration

C++ this Pointer In C++ programming,  this  is a keyword that refers to the current instance of the class. There can be 3 main usage of this keyword in C++. It can be used  to pass current object as a parameter to another method. It can be used  to refer current class instance variable. It can be used  to declare indexers. C++ this Pointer Example Let's see the example of this keyword in C++ that refers to the fields of current class. #include <iostream>    using   namespace  std;   class  Employee {       public :           int  id;  //data member (also instance variable)               string name;  //data member(also instance variable)            float  salary;          Employee( int  id, string name,  float  salary)             {                   this ->id = id;                  this ->name = name;                  this ->salary = salary;            }             void  display()             {                 cout<<id<< "  " <<name<&