0% found this document useful (0 votes)
2 views3 pages

11th and 12th Program Web Application Word

The document contains two web application programs. The first program converts decimal numbers to binary and octal, and vice versa, while the second program is a number guessing game where users attempt to guess a randomly generated number. Both applications utilize ASP.NET with user input handled through text boxes and buttons.

Uploaded by

hunter225113220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

11th and 12th Program Web Application Word

The document contains two web application programs. The first program converts decimal numbers to binary and octal, and vice versa, while the second program is a number guessing game where users attempt to guess a randomly generated number. Both applications utilize ASP.NET with user input handled through text boxes and buttons.

Uploaded by

hunter225113220
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

11th Program Web Application

Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _11th_program
{
public partial class WebForm1 : System.Web.UI.Page
{
int decimalValue;
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
if (int.TryParse(TextBox1.Text, out decimalValue))
{
string binaryValue = Convert.ToString(decimalValue, 2);
Label1.Text = "Binary:" + binaryValue;
}
else
{
Label1.Text = "Invalid input for decimal to binary conversion.";
}
}
private bool IsBinary(string input)
{
foreach (char c in input)
{
if (c != '0' && c != '1')
{
return false;
}
}
return true;
}

protected void Button2_Click(object sender, EventArgs e)


{
if (int.TryParse(TextBox1.Text, out decimalValue))
{
string octalValue = Convert.ToString(decimalValue, 8);
Label1.Text = "Octal:" + octalValue;
}
else
{
Label1.Text = "Invalid input for decimal to octal conversion.";
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string input = TextBox1.Text;
if (IsBinary(input))
{
int decimalValue = Convert.ToInt32(input, 2);
Label1.Text = "Decimal:" + decimalValue;
}
else
{
Label1.Text = "Invalid input for binary to decimal conversion.";
}
}
}
}

12th program web application

Source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _12th_ex
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Random rand = new Random();
int targetNumber = rand.Next(1, 101);
int numberOfTries = 0;
Session["targetNumber"] = targetNumber;
Session["numberOfTries"] = numberOfTries;
}
}

protected void Button1_Click(object sender, EventArgs e)


{
int targetNumber = (int)Session["targetNumber"];
int numberOfTries = (int)Session["numberOfTries"];
int userGuess;
if (int.TryParse(TextBox1.Text, out userGuess))
{
numberOfTries++;
Session["numberOfTries"] = numberOfTries;
if (userGuess < targetNumber)
{
Label1.Text = "Try higher!";
}
else if (userGuess > targetNumber)
{
Label1.Text = "Try lower!";
}
else
{
Label1.Text =string.Format("Congratulations! You guessed the number
{0} in {1} tries.",targetNumber, numberOfTries);
TextBox1.Enabled = false;
Button1.Enabled = false;
}
}
else
{
Label1.Text = "Please enter a valid number.";
}

}
}
}

You might also like