Question

In: Computer Science

Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...

Create an ASP.Net Website using Visual Studio with C#:

Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results

Create 4 buttons to add, subtract, multiply, and divide

Prevent the user from entering text in the number fields

Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box

Create two additional buttons:

- One to store data - The store data will store the results into array

- One to display data - The display data will display the contents of the array (use 10 for the array size)

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Asp.net website  using C# is created using Visual Studio 2017 with name "simpleCalculatorUsingASPNet".This website contains a web page with name "Calculator.aspx".

Calculator.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Calculator.aspx.cs" Inherits="simpleCalculatorUsingASPNet.Calculator" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%-- title for web page --%>
<title>Simple Calculator</title>
<%-- internal stylesheet --%>
<style type="text/css">
.auto-style1 {
width: 39%;
height: 199px;
}
.auto-style2 {
text-align: center;
}
</style>
<%-- <script> is used for javascript --%>
<script>
//javascript function that allows only numbers to be entered
function numbersOnly(evt)
{
var et = event || evt;
var cCode = et.which || et.keyCode;
//allows only numbers to be entered and backspace
if (cCode > 31 && (cCode < 48 || cCode > 57)) {
return false;//return false
}
else {
return true;//return true
}
}
</script>
</head>
<body>
<form id="form1" runat="server">

<table class="auto-style1">
<tr>
<td class="auto-style2" colspan="2"><strong>SIMPLE CALCULATOR</strong></td>
</tr>
<tr>
<td>First Number</td>
<td>
<asp:TextBox ID="txtFirstNumber" runat="server" onkeypress="return numbersOnly();"></asp:TextBox>
</td>
</tr>
<tr>
<td>Second Number</td>
<td>
<asp:TextBox ID="txtSecondNumber" runat="server" onkeypress="return numbersOnly();"></asp:TextBox>
</td>
</tr>
<tr>
<td>Result</td>
<td>
<asp:TextBox ID="txtResult" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="Add" />
&nbsp;<asp:Button ID="btnSubtract" runat="server" OnClick="btnSubtract_Click" Text="Subtract" />
&nbsp;<asp:Button ID="btnMultiply" runat="server" OnClick="btnMultiply_Click" Text="Multiply" />
&nbsp;<asp:Button ID="btnDivide" runat="server" OnClick="btnDivide_Click" Text="Divide" />
&nbsp;<asp:Button ID="btnStoreResult" runat="server" OnClick="btnStoreResult_Click" Text="Store Result" />
&nbsp;<asp:Button ID="btnDisplayResult" runat="server" OnClick="btnDisplayResult_Click" Text="Display Result" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblResult" runat="server"></asp:Label>
</td>
</tr>
</table>

</form>
</body>
</html>

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

Calculator.aspx.cs :

//namespace
using System;
//application namespace
namespace simpleCalculatorUsingASPNet
{
public partial class Calculator : System.Web.UI.Page
{
//declaring array to store result
static double[] resultArray = new double[10];
double result;
static int i = 0;
//addition button click
protected void btnAdd_Click(object sender, EventArgs e)
{
//make addition and display in the textbox
result = (int.Parse(txtFirstNumber.Text) + int.Parse(txtSecondNumber.Text));
txtResult.Text = result.ToString();
}
//subtract button click
protected void btnSubtract_Click(object sender, EventArgs e)
{
//make subtraction and display in the textbox
result = (int.Parse(txtFirstNumber.Text) - int.Parse(txtSecondNumber.Text));
txtResult.Text = result.ToString();
}
//multiply button click
protected void btnMultiply_Click(object sender, EventArgs e)
{
//make multiply and display in the textbox
result = (int.Parse(txtFirstNumber.Text) * int.Parse(txtSecondNumber.Text));
txtResult.Text = result.ToString();
}
//divide button click
protected void btnDivide_Click(object sender, EventArgs e)
{
//checking second number
if(int.Parse(txtSecondNumber.Text)==0)
{
//if second number is zero
txtResult.Text = "Can not divide by zero";
}
else
{
//make division and display in the textbox
result = (int.Parse(txtFirstNumber.Text) / int.Parse(txtSecondNumber.Text));
txtResult.Text = result.ToString();
}
}
//store result button click
protected void btnStoreResult_Click(object sender, EventArgs e)
{
if(i<10)
{
resultArray[i] = int.Parse(txtResult.Text);//stores result in array
i++;//increment value of i
}
}
//display result button click
protected void btnDisplayResult_Click(object sender, EventArgs e)
{
string result = "";//variable to store array element
for (int i = 0; i < resultArray.Length; i++)
{
if(resultArray[i]!=0)
{
//display only when array element is not zero
result = result + resultArray[i] + " ";//concatenate each element with array
}

}
//display result on the label
lblResult.Text = result;
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :Calculator.aspx

Screen 2:Screen showing addition

Screen 3:Screen showing subtraction

Screen 4:Screen showing multiplication

Screen 5:Screen showing division

Screen 6 :Screen when display button is clicked

Screen 7:Screen when second number is zero

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
In c# I need to create a simple payroll management system using visual basic and GUI....
In c# I need to create a simple payroll management system using visual basic and GUI. I also need to connect to SQL database. It needs a log in screen, inside the login screen it needs another screen to enter or edit employee information. It needs somewhere to enter hours worked for that specific employee, and another screen that can access reports.
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
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
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create a question bank. The language is visual studio c++. Description: Question bank computerizes the MCQ...
Create a question bank. The language is visual studio c++. Description: Question bank computerizes the MCQ based exams.It takes input from a file having questions and their answers and presents randomly before the exam takers. Required skill set: OOP, STL(Vector), Arrays and file handling
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT