Yash
Yash
5. Write a C# console application to perform the following. Print the string in ascending
order of their size. Ignore similar words print all the words of the same size
Regno:2217060
Date: 15-11-2023
----------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
namespace labprog5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void sortBtn_Click(object sender, EventArgs e)
{
String input; String
temp = ""; input =
TextBox1.Text; String[]
inputarr = input.Split();
for (int i = 0; i < inputarr.Length; i++)
{
for (int j = i + 1; j <= inputarr.Length - 1; j++)
if (inputarr[i].Length > inputarr[j].Length)
{
temp = inputarr[i];
inputarr[i] = inputarr[j];
inputarr[j] = temp;
}
}
for (int i = inputarr.Length - 1; i >= 0; i--)
{
sortLbl.Text = Convert.ToString(inputarr[i]) + " " + sortLbl.Text;
}
}
protected void rmvBtn_Click(object sender, EventArgs e)
{
string input = TextBox1.Text;
input = TextBox1.Text; string[]
inputarr = input.Split();
Array.Sort(inputarr);
string[] output = inputarr.Distinct().ToArray();
string result = "";
foreach (var i in output)
{
if (i.Length > 0) result += i + "<br/>";
}
rmvLbl.Text = result;
}
protected void submitBtn_Click(object sender, EventArgs e)
{
string text = TextBox1.Text;
string output= ""; string[] q =
text.Split(); int input
=Int32.Parse(TextBox2.Text);
foreach (var i in q)
{
if (i.Length == input)
output = output + i + "<br/>";
}
lnLbl.Text = output;
}
}
}
OUTPUT:
----------------------------------------------------------------------------------------------------------------------
7.Write a C# program to create an array of 5 strings containing the first names of your friends.
Count and display the total number of vowels (Uppercase and Lowercase) in all five strings
that you have entered.
Regno:2217060
Date: 15-11-2023
----------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;
namespace labprog7
{
public partial class WebForm1: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCountVowels_Click(object sender, EventArgs e)
{
string[] friendNames = txtNames.Text.Split(',');
int totalVowels = CountTotalVowels(friendNames);
lblResult.Text = $"Total number of vowels in friend names: {totalVowels}";
}
private int CountTotalVowels(string[] names)
{
int count = 0;
foreach (string name in names)
{
count += CountVowels(name);
}
return count;
}
private int CountVowels(string str)
{
int vowelCount = 0;
foreach (char c in str)
{
if ("AEIOUaeiou".IndexOf(c) != -1)
{
vowelCount++;
}
}
return vowelCount;
}
}
}
OUTPUT:
--------------------------------------------------------------------------------------------------------------------
10. Write a C# console application to create Item class with Ino, Iname, Rate, Qty and Amount.
Calculate Amount using an appropriate method. Create an array of 5 Item objects. Display the
details of Item objects in the descending order of Amount.
Regno:2217060
Date: 15-11-2023
----------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq; using
System.Text; using
System.Threading.Tasks;
namespace labprog10
{
class item
{
int no, qty, amount, rate;
string name;
public void getitems()
{
Console.WriteLine("Enter the product Number, Name, Quantity and Rate");
no = Int32.Parse(Console.ReadLine()); name = Console.ReadLine();
qty = Int32.Parse(Console.ReadLine());
rate = Int32.Parse(Console.ReadLine());
}
public int findAmount()
{
return amount = qty * rate;
}
public void showItem()
{
Console.WriteLine(no + "\t" + name + "\t" + qty + "\t" + rate + "\t" + findAmount());
}
static public int findAmount(item[] itm)
{
int amt = 0;
for(int i = 0; i < itm.Length; i++)
{
amt += itm[i].findAmount();
}
return amt;
}
}
internal class program
{
static void Main(string[] args)
{
item[] items = new item[5];
for(int i = 0; i < 5; i++)
{
items[i] = new item();
items[i].getitems();
}
Console.WriteLine("Number \t Name \t Qty \t Rate \t Amount");
Console.WriteLine("====================================================");
for(int i = 0; i < 5; i++)
{
items[i].showItem();
}
Console.WriteLine("====================================================");
Console.WriteLine("Total Amount is:");
Console.WriteLine(item.findAmount(items));
Console.ReadKey();
}
}}
OUTPUT: