C# Record (3)
C# Record (3)
May – 2022
NAME :
REG. NO :
SEMESTER : IV
PAGE
S.NO DATE PARTICULARS SIGN
NO
1 28-02-2022 Palindrome
2 03-03-2022 Command Line Arguments
3 07-03-2022 Simple Calculator
Aim:
To perform the palindrome program using c sharp.net application.
Algorithm:
Step1: Open the new text document.
Step5: This program contains the formula to the reverse (rev) function as
D=n%10
Rev=rev*10+d
N=n/10
Step7: Open the visual studio comment prompt to run the program.
1.PALINDROME
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace palindrome
{
internalclassProgram
{
staticvoid Main(string[] args)
{
int n, r, rev = 0, m;
Console.Write("Enter the number : ");
n = int.Parse(Console.ReadLine());
m = n;
while(n>0)
{
r = n % 10;
rev = (rev * 10) + r;
n = n / 10;
}
if (rev == m)
Console.WriteLine("The given number is Palindrom.");
else
Console.WriteLine("The given number is not Palindrom.");
Console.ReadLine();
}
}
}
Output:
Result:
The expected output verified and executed successfully.
using System;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
string s,revs="";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length-1; i >=0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0}
and reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was
{0} and reverse string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
2.COMMANDLINE ARGUMENT
Aim:
Algorithm:
Step3: Type the program and create a class name as program name.
Step4: Assign the arguments as a parameters inside and outside of the program.
Step5: Save the program with the extensions of .cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceArgumentWithString
{
classProgram
{
staticvoid Main(string[] args)
{
Console.Write("welcome");
Console.Write(" " + args[0]);
}
}
}
Output:
B) Argument with Number
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespaceArgumentWithNumbers
{
internalclassProgram
{
staticvoid Main(string[] args)
{
double a, b;
if(args.Length == 0)
{
Console.WriteLine("No arguments found!.");
}
else
{
a= double.Parse(args[0]);
b= double.Parse(args[1]);
double sum = 0, div = 0, mul = 0, sub = 0;
sum = a + b;
Console.WriteLine("the sum of {0} and {1} is : {2}", a, b, sum);
div = a / b;
Console.WriteLine("the divsion of {0} and {1} is : {2}", a, b, div);
mul = a * b;
Console.WriteLine("the multiplication of {0} and {1} is : {2}", a, b, mul);
sub = a - b;
Console.WriteLine("the subtraton of {0} and {1} is : {2}", a, b, sub);
Console.ReadLine();
}
}
}
}
Output:
Result:
The expected output verified and executed successfully.
3. SIMPLE CALCULATOR
Aim:
To perform the simple calculator using c sharp.net application.
Algorithms:
Step1: Create a new folder in a “d” drive and open the new text document in the folder.
Step2:Type the program in the new notepad file and save the file “simcalc”
Step3: Use the switch case to determine various operations in the program.
Step4: The operators are mainly used to perform the operations, Addition,subtraction,
multiplication and division.
Step6: Open the visual studio comment prompt to compile and run the program.
Step7: Compile the program & given the program name .cs
Step8: Run the program by giving the program name and stop the program.
3. SIMPLE CALCULATOR
using System;
class simcalc
double a,b,rpt=1;
int choice;
while(rpt!=0)
Console.WriteLine("1.addition");
Console.WriteLine("2.subtraction");
Console.WriteLine("3.multiplication");
Console.WriteLine("4.division");
Console.WriteLine("5.exit");
choice=int.Parse(Console.ReadLine());
switch(choice)
case 1:
b=double.Parse(Console.ReadLine());
Console.WriteLine("Result of addition:"+(a+b));
break;
case 2:
a=double.Parse(Console.ReadLine());
b=double.Parse(Console.ReadLine());
Console.WriteLine("Result of subtraction:"+(a-b));
break;
case 3:
a=double.Parse(Console.ReadLine());
b=double.Parse(Console.ReadLine());
Console.WriteLine("Result of multiplication:"+(a*b));
break;
case 4:
a=double.Parse(Console.ReadLine());
b=double.Parse(Console.ReadLine());
if(b==0)
}
else
Console.WriteLine("resultof division:"+(a/b));
break;
case 5:
rpt=0;
break;
default:
Console.WriteLine("invalid selection");
break;
}
Output:
Result:
The expected output verified and executed successfully.
4. STRING FUNCTION
Aim:
To perform the using string handling function program using c sharp.net application.
Algorithms:
Step1:Start the program.
Step6:using the strop and strlow functions to displays the string in capital letters and small letters.
Step7: using the some handlings functions like string length, string concatenation, string lower case,
string trim, string reverse and string comparisons are used in this program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace strops
class Program
Console.WriteLine("str1:" + str1);
Console.WriteLine("str2:" + str2);
Console.WriteLine("str3:" + str3);
strLow = str1.ToLower(System.Globalization.CultureInfo.CurrentCulture);
strUp = str1.ToUpper(System.Globalization.CultureInfo.CurrentCulture);
Console.WriteLine("split a string:");
Console.WriteLine(strarr[i]);
Console.WriteLine("substr:" + substr);
Array.Reverse(inputarray);
Console.WriteLine("strrev:" + output);
Console.WriteLine();
Console.WriteLine(str1[i]);
if (str1 == str2)
Console.WriteLine("str1==str2");
else
Console.WriteLine("str1=str2");
if (str1 == str3)
Console.WriteLine("str1==str3");
else
Console.WriteLine("str1==str3");
if (result == 0)
else
Console.WriteLine();
Console.WriteLine();
Console.ReadKey();
}
Output:
Result:
The expected output verified and executed successfully.
5. SECOND LARGEST NUMBER
Aim:
To find the second largest number using c sharp.net application.
Algorithms:
Step1: Start the program.
Step2: Open the new text document and type the program in the text document.
Step4: Initialize the variable a, i, high, sechigh, temp in the main function
Step5: Using the int parse keyword use can get the integer.
Step6: Using the for loop condition to determine the length of the array.
Step7: Using the if-else statement to pick the second highest number in the given array.
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespaceSecondLargestnum
{
internalclassProgram
{
staticvoid Main(string[] args)
{
int a, i, high, sechigh, temp;
Console.WriteLine("Enter the array legth:");
a=int.Parse(Console.ReadLine());
int[] arr=newint[a];
Console.WriteLine("Enter the array element one by one:");
for(i=0;i<a;i++)
arr[i]=int.Parse(Console.ReadLine());
Console.WriteLine("Array elements are:");
for(i=0;i<arr.Length;i++)
Console.WriteLine(arr[i]+" ");
Console.WriteLine();
Console.WriteLine();
high = sechigh = arr[0];
for(i=0;i<arr.Length;i++)
{
temp = arr[i];
if(temp>high)
{
sechigh = high;
high= temp;
}
elseif(temp>sechigh&&temp!=high)
{
sechigh = temp;
}
}
Console.WriteLine("The Second largest number is: " + sechigh);
Console.ReadLine();
}
}
Output:
Result:
The expected output verified and executed successfully.
6. JAGGED ARRAY
Aim:
To perform the jagged array program using c sharp.net application.
Algorithms:
Step1: Start the program
Step2: Open the new text document and type the program in the text document.
Step5: Using the for loop condition, Initialize the i variable and assign the zero value and made
increment process until the condition (i<3) has reached false
Step6:Using the for loop condition the position will be placed as like a matrix
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program_myjagger
class Program
for(int i=0;i<myjag.Length;i++)
myjag[i]=new int[i+3];
for(int i=0;i<3;i++)
for(int j=0;j<myjag[i].Length;j++)
myjag[i][j]=int.Parse(Console.ReadLine());
}
int sum=0;
for(int i=0;i<3;i++)
for(int j=0;j<myjag[i].Length;j++)
sum+=myjag[i][j];
Console.WriteLine("sum="+sum);
Console.Read();
}
Output:
Result:
The expected output verified and executed successfully.
7. SIMPLE CALCULATOR (WINDOWS FORM APPLICATION)
Aim:
To perform the c# windows application with simple calculator operations.
Algorithm:
Step 1: Open the visual studio 2010 and select the file menunewprojectwindows c#
windows form applications.
Step2: Design the form as per the calculator display.Using the tools windows.Select the
button,textboxand label to click and drag the button in the approximate position.
Step3:Type the code for approximate buttons before that change the caption of the buttons before that
change the caption of the button as per the calculator design so in every button we need to type as per
approximate code
Eg:button 1
Eg:button +
Intans=Textbox1.text+int.Parse(Textbox1.text);
Textbox1.text=ans;
Intans,num;
Ans=num+float.Parse(Textbox.text);
Textbox1.text=ans.ToString();
Textbox1.text=” “;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace calculator
int count;
public Form1()
InitializeComponent();
textBox1.Text = textBox1.Text + 5;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 1;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 3;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 9;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 2;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 4;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 6;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 7;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 8;
textBox1.ForeColor = Color.Black;
textBox1.Text = textBox1.Text + 0;
textBox1.ForeColor = Color.Black;
{
textBox1.Text = textBox1.Text + ".";
compute();
num = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
num = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
{
num = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
num = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
switch (count)
case 1:
textBox1.Text = ans.ToString();
break;
case 2:
textBox1.Text = ans.ToString();
break;
case 3:
textBox1.Text = ans.ToString();
break;
case 4:
textBox1.Text = ans.ToString();
break;
case 5:
textBox1.Text = ans.ToString();
break;
textBox1.Clear();
MessageBox.Show("claculator closed");
this.Close();
}}
}
OUTPUT:
Result:
The expected output verified and executed successfully.
8.WEB BROWSER
Aim:
To perform the c# Web browser application in c# windows form.
Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.
Step3:Add tool strip menu,menustrip and web browser tool in the first form.
webBrowser1.Navigate(toolStripTextBox1.Text);
webBrowser1.Refresh();
webBrowser1.Goback();
webBrowser1.GoForward();
webBrowser1.print();
Application.Exit();
webBrowser1.stop();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace web_browser1
public Form1()
InitializeComponent();
Application.Exit();
webBrowser1.Refresh();
}
webBrowser1.Stop();
webBrowser1.GoBack();
webBrowser1.GoForward();
webBrowser1.Print();
webBrowser1.Navigate(textBox1.Text);
}
Output:
Result:
The expected output verified and executed successfully.
9. NOTEPAD APPLICATION
Aim:
To perform the c# Notepad application with sum menu operations.
Algorithm:
Step 1: Open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.
String path;
Path=string.Empty();
Textbox.clear();
Application.Exit();
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
using System.IO;
usingSystem.Windows.Forms;
namespacenoteBad
{
publicpartialclassForm1 : Form
{
string path;
publicForm1()
{
InitializeComponent();
}
}
}
Output:
Result:
The expected output verified and executed successfully.
10. Wordpad application
Aim:
To perform the c# Wordpad application in c# windows form.
Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.
richTextBox1.Clear();
openFileDialog1.ShowDialog();
System.IO.StreamReaderofd = new System.IO.StreamReader(openFileDialog1.FileName);
richTextBox1.Text = ofd.ReadToEnd();
ofd.Close();
if (string.IsNullOrEmpty(Path))
using (SaveFileDialogsfd = new SaveFileDialog() { Filter = "TextDocument|*.txt", ValidateNames =
true })
if (sfd.ShowDialog() == DialogResult.OK)
using (System.IO.StreamWritersw = new System.IO.StreamWriter(sfd.FileName))
sw.WriteLine(richTextBox1.Text);
Application.Exit();
10.WORDPAD APPLICATION
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
using System.IO;
usingSystem.Windows.Forms;
namespacewordbad
{
publicpartialclassForm1 : Form
{
string path;
publicForm1()
{
InitializeComponent();
}
richTextBox1.Cut();
}
privatevoidselectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectAll();
}
}
}
Output:
Result:
The expected output verified and executed successfully.
11.DATABASE CONNECTIVITY
Aim:
Algorithm:
Step 1:open the visual studio 2010 and select the file menunewprojectwindows c# windows
form applicationsfile nameok.
Step 5 :Create a object for sqlcommand and get the values from the user.
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Data.SqlClient;
usingSystem.Windows.Forms;
namespace WindowsFormsApp1
{
publicpartialclassForm1 : Form
{
SqlConnection conn=newSqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Dell\Documents\crtdatab.mdf;Integrated
Security=True;Connect Timeout=30");
SqlCommandcmd;
SqlDataAdapter adapter;
DataSet ds=newDataSet();
publicForm1()
{
InitializeComponent();
}
Output:
Result:
The expected output verified and executed successfully.
12.ASP.NET APPLICATION
Aim:
To perform the Asp.net application in c# windows form.
Algorithm:
Step 1:Open the visual studio 2010 and select the file menunew websitewindows c# Asp.Net
empty filefile nameok.
Step 5 :Create a object for OleDbConnection , OleDbCommandand get the values from the
user.
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Data.OleDb;
usingSystem.Configuration;
Result:
The expected output verified and executed successfully.