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

Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: 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...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select ( integer, string, date ) After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4 And then , I have a 'sort' button Can you please help me with the code behind for sorting them( For integer, string, and date ) Thank you.
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. The charges are based on each 500 miles shipped. Shipping charges are not pro-rated;...
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...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT