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

Standard and Formatted Input / Output in C++

The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming. C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called   input operation   and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc., this is called   output operation . Standard Input and Output in C++ is done through the use of  streams . Streams are generic places to send or receive data. In C++, I/O is done through classes and objects defined in the header file  <iostream> .  iostream  stands for standard input-output stream. This header file contains definitions to objects like  cin ,  cout , etc. /O Library Header Files There are...

Data Warehousing - An Overview

Anurag Information Technology (IT) has historically influenced organizational performance and competitive standing. The increasing processing power and sophistication of analytical tools and techniques have put the strong foundation for the product called data warehouse. There are a number of reasons that any organization should consider a data warehouse, which can be the critical tool for maximizing the organization’s investment in the information it has collected and stored throughout the enterprise. IT managers need to understand the rationale and benefits of data warehouses because they may need to design and implement, or procure this kingpin of business intelligence. The data warehouses are supposed to provide storage, functionality and responsiveness to queries beyond the capabilities of today's transaction-oriented databases. Also data warehouses are set to improve the data access performance of databases. Traditional databases balance the requirement of data access w...

Genotype Representation

Binary Representation This is one of the simplest and most widely used representation in GAs. In this type of representation the genotype consists of bit strings. For some problems when the solution space consists of Boolean decision variables – yes or no, the binary representation is natural. Take for example the 0/1 Knapsack Problem. If there are n items, we can represent a solution by a binary string of n elements, where the x th  element tells whether the item x is picked (1) or not (0). For other problems, specifically those dealing with numbers, we can represent the numbers with their binary representation. The problem with this kind of encoding is that different bits have different significance and therefore mutation and crossover operators can have undesired consequences. This can be resolved to some extent by using  Gray Coding,  as a change in one bit does not have a massive effect on the solution. Real Valued Representation For problems where we want to define ...