Lab 1 Manual
Lab 1 Manual
Objective: The goal of this lab is to guide students through the process of creating a simple desktop
calculator using C# in Visual Studio. By the end of this lab, students should have a functional
calculator that can perform basic arithmetic operations.
Prerequisites:
Lab Steps:
Open Visual Studio and create a new Windows Forms App (.NET Core) project.
Name the project "CalculatorApp" and choose a suitable location for your project.
Drag and drop buttons for digits (0-9), arithmetic operators (+, -, *, /), and other necessary buttons
onto the form.
Double-click on each digit button and implement the code to append the corresponding digit to the
TextBox.
Implement the logic for the arithmetic operator buttons to store the current operator and the first
operand.
Implement the code for the "=" button to perform the calculation based on the stored operator and
operands.
Example Code:
double firstOperand = 0;
public Form1()
InitializeComponent();
}
private void DigitButton_Click(object sender, EventArgs e)
textBox1.Text += button.Text;
currentOperator = button.Text;
firstOperand = double.Parse(textBox1.Text);
textBox1.Clear();
double result = 0;
switch (currentOperator)
case "+":
break;
case "-":
break;
case "*":
break;
case "/":
if (secondOperand != 0)
else
break;
textBox1.Text = result.ToString();
Run the application and test each button to ensure that the calculator performs the expected
operations.
Debug and fix any issues that may arise during testing.