0% found this document useful (0 votes)
9 views10 pages

Objective: - Program To Display The Addition Substruction Multiplication and Division of Two Number Using Console Applications

The document contains a series of programming labs focusing on various applications, including basic arithmetic operations, natural number display, case conversion, and database connectivity using C# and ASP.NET. Each lab provides objectives, code snippets, and sample outputs for console and Windows applications. The labs cover a range of topics from simple calculations to user registration forms and SQL database interactions.

Uploaded by

Anket
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)
9 views10 pages

Objective: - Program To Display The Addition Substruction Multiplication and Division of Two Number Using Console Applications

The document contains a series of programming labs focusing on various applications, including basic arithmetic operations, natural number display, case conversion, and database connectivity using C# and ASP.NET. Each lab provides objectives, code snippets, and sample outputs for console and Windows applications. The labs cover a range of topics from simple calculations to user registration forms and SQL database interactions.

Uploaded by

Anket
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/ 10

[LAB-1]

Objective: - Program to display the addition substruction multiplication and division of two
number using console applications.

using System;

namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter the second number: ");


double num2 = Convert.ToDouble(Console.ReadLine());

double sum = num1 + num2;


double difference = num1 - num2;
double product = num1 * num2;
double quotient = num1 / num2;

Console.WriteLine("Addition: " + sum);


Console.WriteLine("Subtraction: " + difference);
Console.WriteLine("Multiplication: " + product);
Console.WriteLine("Division: " + quotient);

Console.ReadKey();
}
}
}

Output: -
Enter the first number: 15
Enter the second number: 5
Addition: 20
Subtraction: 10
Multiplication: 75
Division: 3
[LAB-2]
Objective: - Program to display the first 10 natural numbers and their sum using console
application.

using System;

namespace NaturalNumbers

class Program

static void Main(string[] args)

int sum = 0;

Console.WriteLine("The first 10 natural numbers are:");

for (int i = 1; i <= 10; i++)

Console.WriteLine(i);

sum += i;

Console.WriteLine("The sum of the first 10 natural numbers is: " + sum);

Console.ReadKey();

Output: -
The first 10 natural numbers are:

1 2 3 4 5 6 7 8 9 10

The sum of the first 10 natural numbers is: 55


[LAB-3]
Objective: - Program to display the addition using the windows application.

using System;

using System.Windows.Forms;

namespace AddNumbers

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

// Get values from text boxes

int num1 = int.Parse(textBox1.Text);

int num2 = int.Parse(textBox2.Text);

// Calculate the sum

int sum = num1 + num2;

// Display the sum in the label

label3.Text = $"The sum is: {sum}";

}
[LAB-4]
Objective: - Write a program to convert input string from lower to upper and upper to lower
case.

using System;
namespace CaseConverter
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a string: ");
string input = Console.ReadLine();

string upperCase = "";


string lowerCase = "";

foreach (char c in input)


{
if (char.IsLower(c))
{
upperCase += char.ToUpper(c);
lowerCase += char.ToLower(c);
}
else
{
upperCase += char.ToUpper(c);
lowerCase += char.ToLower(c);
}
}
Console.WriteLine("Upper case: " + upperCase);
Console.WriteLine("Lower case: " + lowerCase);

Console.ReadKey();
}
}
}
Output: -
Enter a string: Abhishek Yadav
Upper case: ABHISHEK YADAV
Lower case: abhishek yadav
[LAB-5]
Objective: - Write a program to simple calculator using windows application.

using System;
using System.Windows.Forms;
namespace Calculation
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double num1 = double.Parse(textBox1.Text);
double num2 = double.Parse(textBox2.Text);
double sum = num1 + num2;
label3.Text = "Result: " + sum.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
double num1 = double.Parse(textBox1.Text);
double num2 = double.Parse(textBox2.Text);
double difference = num1 - num2;
label3.Text = "Result: " + difference.ToString();
}

private void button3_Click(object sender, EventArgs e)


{
double num1 = double.Parse(textBox1.Text);
double num2 = double.Parse(textBox2.Text);
double product = num1 * num2;
label3.Text = "Result: " + product.ToString();
}

private void button4_Click(object sender, EventArgs e)


{
double num1 = double.Parse(textBox1.Text);
double num2 = double.Parse(textBox2.Text);
double quotient = num1 / num2;
label3.Text = "Result: " + quotient.ToString();
}

private void button5_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}
[LAB-6]
Objective: - Write a program working with page using ASP.Net.

<div class="text-center">

<h1 class="display-4">Welcome to our website!</h1>

<p>Learn about Web development refers to the creating, building, and maintaining of
websites.</p>

<h3>Subscribe</h3>

</div>

*Open the Default.aspx.cs file and replace the content with the following code:

(csharp)

using System;

using System.Web.UI;

namespace MyWebApp

public partial class Default : Page

protected void Page_Load(object sender, EventArgs e)

// Code that runs when the page is loaded

}
[LAB-7]
Objective: - Write a program working with forms using ASP.NET

<div class="text-center">

<h1 class="display-4">Welcome</h1>

<h1>User Registration</h1>

<form id="userForm" runat="server" method="post">

<label for="name">Name:</label>

<input type="text" id="name" name="name" runat="server" required /><br /><br />

<label for="email">Email:</label>

<input type="email" id="email" name="email" runat="server" required /><br /><br />

<input type="submit" value="Submit" runat="server" onclick="submitForm(event)" />

</form>

</div>
[LAB-8]
Objective: - Write a program to connectivity with Microsoft sql database

using System;
using System.Data.SqlClient;

namespace SQLConnectivity
{
class Program
{
static void Main(string[] args)
{
string connectionString = "Data Source=YourServerName;Initial
Catalog=YourDatabaseName;User ID=YourUsername;Password=YourPassword;";

try
{
using (SqlConnection connection = new SqlConnection
(connectionString))
{
connection.Open();

Console.WriteLine("Connected to the database.");

// Perform database operations here


// ...

connection.Close();
}
}
catch (SqlException ex)
{
Console.WriteLine("Error: " + ex.Message);
}

Console.ReadKey();
}
}
}
[LAB-9]
Objective: - Write a program to access data source through ADO.NET
using System;
using System.Data.SqlClient;

namespace ADOdotNETExample
{
class Program
{
static void Main(string[] args)
{
string connectionString = "Data Source=YourServerName;Initial
Catalog=YourDatabaseName;User ID=YourUsername;Password=YourPassword;";

try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand("SELECT * FROM


YourTableName", connection);

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())
{
Console.WriteLine(reader[0].ToString() + " " + reader[1].ToString());
}

reader.Close();
}
}
catch (SqlException ex)
{
Console.WriteLine("Error: " + ex.Message);
}

Console.ReadKey();
}
}
}
[LAB-10]
Objective: - Write a program to display the following feedback form

<div class="text-center">

<h1>Feedback Form</h1>

<form id="feedbackForm">

<div class="form-group">

<label for="name">Your Name (Optional):</label>

<input type="text" id="name" name="name">

</div>

<div class="form-group">

<label for="email">Email Address (Optional):</label>

<input type="email" id="email" name="email">

</div>

<div class="form-group">

<label for="feedback">Your Feedback:</label>

<textarea id="feedback" name="feedback" rows="5"></textarea>

</div>

<button type="submit">Submit Feedback</button>

</form>

</div>

You might also like