Question

In: Computer Science

Create a windows form application in C# that looks and functions like a basic calculator. It...

Create a windows form application in C# that looks and functions like a basic calculator. It must do the following:
  1. Add, subtract, multiply, and divide.
  2. Account for division by zero.
  3. Show at least two decimal places.
  4. Retain the last number on the window so that, when the user opens the calculator the next time, the number that was in the window at the last close appears.
  5. Have a memory, so that users can store values and recall them.
  6. Operate with a mouse clicking buttons
  7. Operate from the keyboard only with no mouse requirement.
  8. Contain a small box for a company logo. Make up a logo and insert it there.
  9. Contain a clear and clear all button.
  10. The user must not be able to enter data directly in the display window – they have to press the keys.
  11. Look like a calculator, and not a maximized window.
  12. Use naming conventions for all the elements on the form. In other words, do not use the default names for the labels, buttons, or other controls.

Solutions

Expert Solution

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Component Model;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8.   
  9. namespace Calculator
  10. {  
  11.     public partial class Form1 : Form  
  12.     {  
  13.         double FirstNumber;  
  14.         string Operation;  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.   
  20.          
  21.         private void n1_Click(object sender, EventArgs e)  
  22.         {  
  23.             if (textBox1.Text == "0" && textBox1.Text != null)  
  24.             {  
  25.                 textBox1.Text = "1";  
  26.             }  
  27.             else  
  28.             {  
  29.                 textBox1.Text = textBox1.Text + "1";  
  30.             }  
  31.         }  
  32.   
  33.         private void n2_Click(object sender, EventArgs e)  
  34.         {  
  35.             if (textBox1.Text == "0" && textBox1.Text != null)  
  36.             {  
  37.                 textBox1.Text = "2";  
  38.             }  
  39.             else  
  40.             {  
  41.                 textBox1.Text = textBox1.Text + "2";  
  42.             }  
  43.         }  
  44.   
  45.         private void n3_Click(object sender, EventArgs e)  
  46.         {  
  47.             if (textBox1.Text == "0" && textBox1.Text != null)  
  48.             {  
  49.                 textBox1.Text = "3";  
  50.             }  
  51.             else  
  52.             {  
  53.                 textBox1.Text = textBox1.Text + "3";  
  54.             }  
  55.         }  
  56.   
  57.         private void n4_Click(object sender, EventArgs e)  
  58.         {  
  59.             if (textBox1.Text == "0" && textBox1.Text != null)  
  60.             {  
  61.                 textBox1.Text = "4";  
  62.             }  
  63.             else  
  64.             {  
  65.                 textBox1.Text = textBox1.Text + "4";  
  66.             }  
  67.         }  
  68.   
  69.         private void n5_Click(object sender, EventArgs e)  
  70.         {  
  71.             if (textBox1.Text == "0" && textBox1.Text != null)  
  72.             {  
  73.                 textBox1.Text = "5";  
  74.             }  
  75.             else  
  76.             {  
  77.                 textBox1.Text = textBox1.Text + "5";  
  78.             }  
  79.         }  
  80.   
  81.         private void n6_Click(object sender, EventArgs e)  
  82.         {  
  83.             if (textBox1.Text == "0" && textBox1.Text != null)  
  84.             {  
  85.                 textBox1.Text = "6";  
  86.             }  
  87.             else  
  88.             {  
  89.                 textBox1.Text = textBox1.Text + "6";  
  90.             }  
  91.         }  
  92.   
  93.         private void n7_Click(object sender, EventArgs e)  
  94.         {  
  95.             if (textBox1.Text == "0" && textBox1.Text != null)  
  96.             {  
  97.                 textBox1.Text = "7";  
  98.             }  
  99.             else  
  100.             {  
  101.                 textBox1.Text = textBox1.Text + "7";  
  102.             }  
  103.         }  
  104.   
  105.         private void n8_Click(object sender, EventArgs e)  
  106.         {  
  107.             if (textBox1.Text == "0" && textBox1.Text != null)  
  108.             {  
  109.                 textBox1.Text = "8";  
  110.             }  
  111.             else  
  112.             {  
  113.                 textBox1.Text = textBox1.Text + "8";  
  114.             }  
  115.         }  
  116.   
  117.         private void n9_Click(object sender, EventArgs e)  
  118.         {  
  119.             if (textBox1.Text == "" && textBox1.Text != null)  
  120.             {  
  121.                 textBox1.Text = "9";  
  122.             }  
  123.             else  
  124.             {  
  125.                 textBox1.Text = textBox1.Text + "9";  
  126.             }  
  127.         }  
  128.   
  129.         private void n0_Click(object sender, EventArgs e)  
  130.         {  
  131.             textBox1.Text = textBox1.Text + "0";  
  132.         }  
  133.   
  134.         private void bad_Click(object sender, EventArgs e)  
  135.         {  
  136.             FirstNumber = Convert.ToDouble(textBox1.Text);  
  137.             textBox1.Text = "0";  
  138.             Operation = "+";  
  139.         }  
  140.   
  141.         private void bsub_Click(object sender, EventArgs e)  
  142.         {  
  143.             FirstNumber = Convert.ToDouble(textBox1.Text);  
  144.             textBox1.Text = "0";  
  145.             Operation = "-";  
  146.   
  147.         }  
  148.   
  149.         private void bmul_Click(object sender, EventArgs e)  
  150.         {  
  151.             FirstNumber = Convert.ToDouble(textBox1.Text);  
  152.             textBox1.Text = "0";  
  153.             Operation = "*";  
  154.         }  
  155.   
  156.         private void bdiv_Click(object sender, EventArgs e)  
  157.         {  
  158.             FirstNumber = Convert.ToDouble(textBox1.Text);  
  159.             textBox1.Text = "0";  
  160.             Operation = "/";  
  161.         }  
  162.   
  163.         private void bc_Click(object sender, EventArgs e)  
  164.         {  
  165.             textBox1.Text = "0";  
  166.         }  
  167.   
  168.         private void ndot_Click(object sender, EventArgs e)  
  169.         {  
  170.             textBox1.Text = textBox1.Text + ".";  
  171.         }  
  172.   
  173.         private void nequal_Click(object sender, EventArgs e)  
  174.         {  
  175.             double SecondNumber;  
  176.             double Result;  
  177.   
  178.             SecondNumber = Convert.ToDouble(textBox1.Text);  
  179.   
  180.             if (Operation == "+")  
  181.             {  
  182.                 Result = (FirstNumber + SecondNumber);  
  183.                 textBox1.Text = Convert.ToString(Result);  
  184.                 FirstNumber = Result;  
  185.             }  
  186.             if (Operation == "-")  
  187.             {  
  188.                 Result = (FirstNumber - SecondNumber);  
  189.                 textBox1.Text = Convert.ToString(Result);  
  190.                 FirstNumber = Result;  
  191.             }  
  192.             if (Operation == "*")  
  193.             {  
  194.                 Result = (FirstNumber * SecondNumber);  
  195.                 textBox1.Text = Convert.ToString(Result);  
  196.                 FirstNumber = Result;  
  197.             }  
  198.             if (Operation == "/")  
  199.             {  
  200.                 if (SecondNumber == 0)  
  201.                 {  
  202.                     textBox1.Text = "Cannot divide by zero";  
  203.   
  204.                 }  
  205.                 else  
  206.                 {  
  207.                     Result = (FirstNumber / SecondNumber);  
  208.                     textBox1.Text = Convert.ToString(Result);  
  209.                     FirstNumber = Result;  
  210.                 }  
  211.             }  
  212.         }
  213.     }  
  214. }  

Related Solutions

Create a Windows application in C# that can be used to change the form color. Your...
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code for calculator menus radio button input text boxes
C# windows application form. Create a base class to store characteristics about a loan. Include customer...
C# windows application form. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it...
Code, pls. Thank you. Exercise - MPG Calculator Create a Windows Forms application and call it MPGCalculator Build a form that looks like the form in the video provided. The form consists of 4 labels, 2 textboxes and 3 buttons Name all controls properly. Certain labels do not have to be named Pay attention to video and set all design time properties accordingly. The "x" should be a hot key for the exit button When Calculate is clicked, you should...
C# Programming Discuss how to build a Multi-Form Windows application in C#. That is an App...
C# Programming Discuss how to build a Multi-Form Windows application in C#. That is an App that has more than one form, like say maybe 5 forms. How do you connect these forms and pass data objects between these forms?
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
A, B:   Design and Implement a C# windows form application to ask the user for 10...
A, B:   Design and Implement a C# windows form application to ask the user for 10 integer numbers, sort them in ascending order and display the sorted list. Use bubble sort technique to sort the array elements and do not use any built-in sort method to sort the array elements.                                                        [02] C:    Test and evaluate your program by inputting variety of values.
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text....
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text. The application use to receive a string and display another encrypted string. The application also decrypt the encrypted string. The approach for encryption/decryption is simple one i.e. to encrypt we will add 1 to each character, so that "hello" would become "ifmmp", and to decrypt we would subtract 1 from each character.    C:   Test and evaluate application by applying different strings.      ...
Must be in Visual C# using windows forms : Create an application that opens a specified...
Must be in Visual C# using windows forms : Create an application that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Use a LINQ method to remove all duplicate words.
In C# Create a windows application which accepts the month number and displays the month name...
In C# Create a windows application which accepts the month number and displays the month name in a label.   Use a nested if... else statement to determine the month name. For months not in the range 1-12 display the message "Not a valid month"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT