string last = ""; bool minus = false; bool plus = false; bool divide = false; bool multiply = false; string memory = ""; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Contains(",")) { return;

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

C#(Sharp): I made my code and design below. Anybody can help me some correction and add some design button and code. "Need to make C# step by step design and code "Calculator where make a calculator program that can do add, subtract, multiply, divide and square root. It should have a memory save/restore function for one number. There should be a way to set the number of fraction digits displayed".

 

 

  • Code:

  • 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 AktCalc

    {

    public partial class Form1 : Form

    {

    string last = "";

    bool minus = false;

    bool plus = false;

    bool divide = false;

    bool multiply = false;

    string memory = "";

    public Form1()

    {

    InitializeComponent();

    }

    private void button2_Click(object sender, EventArgs e)

    {

  • if (textBox1.Text.Contains(","))

    {

    return;

    }

    else

    {

    textBox1.Text += ",";

    }

    }

    private void button21_Click(object sender, EventArgs e)

    {

    last = textBox1.Text;

    multiply = true;

    }

    private void button3_Click(object sender, EventArgs e)

    {

    last = textBox1.Text;

    plus = true;

    }

    private void button5_Click(object sender, EventArgs e)

    {

    last = textBox1.Text;

    divide = true;

    }

  • private void button4_Click(object sender, EventArgs e)

    {

    last = textBox1.Text;

    minus = true;

    }

    // Equalls =

    private void button6_Click(object sender, EventArgs e)

    {

    if (minus)

    {

    decimal equals1;

    equals1 = Convert.ToDecimal(last) - Convert.ToDecimal(textBox1.Text);

    textBox1.Text = Convert.ToString(equals1);

    }

    if (plus)

    {

    decimal equals1;

    equals1 = Convert.ToDecimal(last) + Convert.ToDecimal(textBox1.Text);

    textBox1.Text = Convert.ToString(equals1);

    }

    if (divide)

    {

    decimal equals1;

  • equals1 = Convert.ToDecimal(last) / Convert.ToDecimal(textBox1.Text);

    textBox1.Text = Convert.ToString(equals1);

    }

    if (multiply)

    {

    decimal equals1;

    equals1 = Convert.ToDecimal(last) * Convert.ToDecimal(textBox1.Text);

    textBox1.Text = Convert.ToString(equals1);

    }

    }

    private void button16_Click(object sender, EventArgs e)

    {

    textBox1.Text = Convert.ToString(Math.Sqrt(Convert.ToDouble(textBox1.Text)));

    }

    private void button1_Click(object sender, EventArgs e)

    {

    memory = textBox1.Text;

    label1.Text = "M";

    }

    private void button10_Click(object sender, EventArgs e)

    {

    memory = "";

    label1.Text = "";

    }

  • private void button15_Click(object sender, EventArgs e)

    {

    textBox1.Text = memory;

    }

    private void button11_Click(object sender, EventArgs e)

    {

    textBox1.Text = "";

    multiply = false;

    plus = false;

    minus = false;

    divide = false;

    }

    private void button20_Click(object sender, EventArgs e)

    {

    textBox1.Text += "0";

    }

    private void button19_Click(object sender, EventArgs e)

    {

    textBox1.Text += "1";

    }

    private void button18_Click(object sender, EventArgs e)

    {

  • textBox1.Text += "2";

    }

    private void button17_Click(object sender, EventArgs e)

    {

    textBox1.Text += "3";

    }

    private void button14_Click(object sender, EventArgs e)

    {

    textBox1.Text += "4";

    }

    private void button13_Click(object sender, EventArgs e)

    {

    textBox1.Text += "5";

    }

    private void button12_Click(object sender, EventArgs e)

    {

    textBox1.Text += "6";

    }

    private void button9_Click(object sender, EventArgs e)

    {

    textBox1.Text += "7";

    }

  • private void button8_Click(object sender, EventArgs e)

    {

    textBox1.Text += "8";

    }

    }

    }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,