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...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:     create label, textbox and button     the textbox will capture the SQL statement     the button will process the statement and display the results 2. Add necessary data access pages to your project. 3. Display the data in Gridview
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.
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. 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...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT