This article explains how to create a talking calculator using a dialog based application. Complex calculation, sound with every click of the buttons are the specialty of this application. This application is a dialog based and has been developed using MFC AppWizard. We have a static control to display the numbers when buttons are clicked and to display the result. For numbers, operators and memory related activities we have used button control. We have written handlers for each button control. When we click on the buttons with number on them the handler for it is called. The handler is responsible to display the number in the static control as well as to play the sound file using Play Sound( ) function. There are 10 such sound files in the wave directory inside the application's project directory. When we click on any operator the handler function for the operator collects the number displayed in the static control in a variable m_num1 and sets a flag variable that the operation is on. Now if we click on some other operator or equal to operator the handler collects the number in a second variable m_num2 after checking the flag variable and displays the result in the static control. We have buttons like 'MC', 'MR', 'MS', 'M+' for memory clear, memory recall, memory store and memory plus respectively. 'Back' button is used to delete the displayed number. 'CE' clears the displayed numbers and 'C' clears the current calculation. 'Sqrt' gives the square root of the displayed number. '%' displays the remainder of x/y. '+/-' changes the sign of the displayed number. This application can be improved by adding the keyboard interface and functions for scientific calculations.
Labels: Visual C++