Question

Visual Studio Code C#

Well Document everyline saying what the code does.

Include designer code and .cscode

Extra 6-1 Create a simple calculator In this exercise, youl1 create a form that accepts two operands and an operator from the user and then performs the requested operation. Simple Calculator Operand 1: 86 Operator Operand 2 11.11 Resut 7.7408 1. Start a new project named SimpleCalculator in the Extra Exercises Chapter 06SimpleCalculator directory 2. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Enter key, the Click event of the Calculate button should fire. When the user presses the Esc key, the Click event of the Exit button should fire 3. Code a private method named Calculate that performs the requested operatiorn and returns a decimal value. This method should accept the following arguments Description Argument decimal operandi string operatorl decimal operand2 The value entered for the first operand. One of these four operators: +, -, *, or / The value entered for the second operand. 4. Create an event handler for the Click event of the Calculate button. This event handler should get the two numbers and operand the user enters, call the Calculate method to get the result of the calculation, display the result rounded to four decimal places, and move the focus to the Operand 1 text box. Create an event handler for the Click event of the Exit button that closes the form Create an event handler that clears the Result text box if the user changes the text in any of the other text boxes Test the application to be sure it works correctly 5. 6. 7.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Form Design

Simple Calculator Operand 1: Operator Operand 2: Result: Calculate Exit

Form1.Designer.cs

namespace SimpleCalculator
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.btn_Calculate = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(23, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(82, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Operand 1:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(23, 74);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Operator:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(23, 119);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(82, 16);
this.label3.TabIndex = 2;
this.label3.Text = "Operand 2:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(23, 167);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(54, 16);
this.label4.TabIndex = 3;
this.label4.Text = "Result:";
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(111, 29);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 23);
this.textBox1.TabIndex = 4;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox2.Location = new System.Drawing.Point(111, 71);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 23);
this.textBox2.TabIndex = 5;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
this.textBox2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox2_KeyDown);
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox3.Location = new System.Drawing.Point(111, 116);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(100, 23);
this.textBox3.TabIndex = 6;
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
this.textBox3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyDown);
//
// textBox4
//
this.textBox4.Enabled = false;
this.textBox4.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox4.Location = new System.Drawing.Point(111, 164);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(100, 23);
this.textBox4.TabIndex = 7;
//
// btn_Calculate
//
this.btn_Calculate.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_Calculate.Location = new System.Drawing.Point(26, 211);
this.btn_Calculate.Name = "btn_Calculate";
this.btn_Calculate.Size = new System.Drawing.Size(95, 26);
this.btn_Calculate.TabIndex = 8;
this.btn_Calculate.Text = "Calculate";
this.btn_Calculate.UseVisualStyleBackColor = true;
this.btn_Calculate.Click += new System.EventHandler(this.btn_Calculate_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Location = new System.Drawing.Point(136, 211);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 26);
this.button2.TabIndex = 9;
this.button2.Text = "Exit";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(237, 258);
this.Controls.Add(this.button2);
this.Controls.Add(this.btn_Calculate);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Simple Calculator";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button btn_Calculate;
private System.Windows.Forms.Button button2;
}
}

***************************************************************************

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimpleCalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
  
// method for calculation
private double Calculate(double operand1,double operand2,char operator1)
{
double ans = 0.0;
if (operator1.Equals('+')) // if operator is + then do addition
ans = operand1 + operand2;
else
if (operator1.Equals('-'))   // if operator is - then do subtraction
ans = operand1 - operand2;
else
if (operator1.Equals('*'))   // if operator is * then do multplication
ans = operand1 * operand2;
else
if (operator1.Equals('/'))   // if operator is / then do division
ans = operand1 / operand2;
return Math.Round(ans, 4); // Rounding number to 4th decimal position
}

// when calculate button is clicked
private void btn_Calculate_Click(object sender, EventArgs e)
{
try
{

// getting two operands and one operator from form
double operand1 = Convert.ToDouble(textBox1.Text);
double operand2 = Convert.ToDouble(textBox3.Text);
char operator1 = Convert.ToChar(textBox2.Text);

// call Calculate method to get output
double answer=Calculate(operand1,operand2,operator1);
textBox4.Text = answer + ""; // display output in text box
}
catch (Exception)
{
MessageBox.Show("Invalid input");
}
}

private void button2_Click(object sender, EventArgs e)
{
// when user clicks on exit button or press esc
// then from will be closed
this.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

// if text box1 text changed then clearing result text box
textBox4.Clear();
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox4.Clear();
}

private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox4.Clear();
}
// following three methods for calculate button on enter key
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
this.AcceptButton = btn_Calculate;
}

private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
this.AcceptButton = btn_Calculate;
}

private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
this.AcceptButton = btn_Calculate;
}
// for escape button
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Escape))
{
Close();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
}

Output

Add a comment
Know the answer?
Add Answer to:
Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help! Visual Basic - Windows App Form .NET Framework. ​Option Explicit ON ​Option Strict ON...

    Please help! Visual Basic - Windows App Form .NET Framework. ​Option Explicit ON ​Option Strict ON ​Option Infer ON calculate Letter Grade Number grade: I Letter grade: Calculate Exxt Start a new Project named GradeConverter Add labels, textboxes, and button to the default form. Create an event handler for Calculate and Exit. . When the user enters a number- between 0.0 and 100.0 and clicks Calculate, the letter grade will display for the user The form should be able to...

  • must be visual basic code please include any properties that have to be changed. rcises-3.pdf -...

    must be visual basic code please include any properties that have to be changed. rcises-3.pdf - Adobe Acrobat Reader DC View Window Help Tools Extra exerases-3.pdf X 14 Extra exercises tor Murach's Visual Basie 2015 Extra 8-1 Display a test scores array In this exercise, you'll enhance the Score Caleulator form of extra exercise 4-2 so it saves the scores the user enters in an array and then lets the user display the sorted scores in a dialog box. Elle-a...

  • Using Visual Studio 2015, how would I code the following Uodate button event handler in c#?...

    Using Visual Studio 2015, how would I code the following Uodate button event handler in c#? then displayed in the student list box. Create an interface as follows The initial form for the application should appear as follows Student Scores Students dd New. Lpdate Delete Ext To update, delete or add student information create the following form Enter Student Information Name Student ID MdtemRna Cancel Note: the Control Box property is set to false

  • PLEASE USE VISUAL BASIC* BY VISUAL STUDIO. Visual Basic INTERMEDIATE Create a Windows Forms application. Use...

    PLEASE USE VISUAL BASIC* BY VISUAL STUDIO. Visual Basic INTERMEDIATE Create a Windows Forms application. Use the following names for the project and solution, respectively: Chopkins Project and Chopkins Solution. Save the application in the VB2017\Chap03 folder. Change the form file's name to Main Form.vb. Change the form's name to frmMain. Create the interface shown in Figure 3-37. The interface contains six labels, three text boxes, and two buttons. The application calculates and displays the total number of packs ordered...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • circle the correct answer please. Please reply Asap. 8. What does the following jQuery code do?...

    circle the correct answer please. Please reply Asap. 8. What does the following jQuery code do? s ("inage").attr(are", imagoURL) a Gets the value of the sre aribute for the element with an id of "image" and stores it in a variable named imageURL Sets the value of the sre attribute for the element with an id of "image" to the value in a variable named imageURL Gets the values of the sre attribute for each element with a class of...

  • Can someone help fix this JAVASCRIPT code according to comment instructions javascriot code: window.addEventListener("click", () =>...

    Can someone help fix this JAVASCRIPT code according to comment instructions javascriot code: window.addEventListener("click", () => { console.log("You clicked?"); }); let button = document.querySelector("button"); button.addEventListener("click", () => { console.log("First Button clicked."); }); // How can we modify this so that it will occur when the 2nd button is clicked? // We need to use querySelectorAll which will produce a nodelist/array of all the buttons. Then we can reference which button we want to apply the click event using [] with...

  • Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The...

    Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The main form contains a reset button and sets the form's background colour according to the colour values indicated by the colour control objects. Each colour control object is controlled by a corresponding colour control form which provides a progress bar to show the value (in the range 0 to 255) of the corresponding colour control object. The user can click the increase (+) or...

  • Use Visual Basic language(only basic no, C# or others). Use of Try-Catch Blocks In retail sales,...

    Use Visual Basic language(only basic no, C# or others). Use of Try-Catch Blocks In retail sales, management needs to know the average inventory figure and the turnover of merchandise. Create a project that allows the user to enter the beginning inventory, the ending inventory and the cost of goods sold. Form: Include labeled text boxes for the beginning inventory, the ending inventory, and the cost of goods sold. After calculating the answers. Display the average inventory and the turnover formatted...

  • NEED HELP BEING SOLVED IN C++! USE ORIGINAL CODE TO ADD TO AS WELL! #include<iostream> using...

    NEED HELP BEING SOLVED IN C++! USE ORIGINAL CODE TO ADD TO AS WELL! #include<iostream> using namespace std; int main(){    for (int i = 0; i < 7; i++) { int x,y; char opr; cin>>x>>y>>opr;    switch(opr) { case '+': cout<<x<<" + "<<y<<" = "<<x+y; break; case '-': cout<<x<<" - "<<y<<" = "<<x-y; break; case '*': cout<<x<<" * "<<y<<" = "<<x*y; break; case '/': if(y == 0) cout<<x<<" / "<<y<<" = "<<"ERROR"; else cout<<x<<" / "<<y<<" = "<<x/y<<"R"<<x%y; break;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT