Assgnment21 466
Assgnment21 466
Assgnment21 466
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter the size of the square:");
int size = int.Parse(Console.ReadLine());
int area = size * size;
Console.WriteLine("The area of the square is: " + area);
}
}
=========================================================================
================
2.Create a console application that finds number of digits and alphabets
in a given string
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Enter a string:");
string input = Console.ReadLine();
int digitCount = 0;
int alphabetCount = 0;
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the input string");
string inputString =Console.ReadLine();
string increasedString = IncreaseCharacters(inputString);
string toggledString = ToggleCase(increasedString);
Console.WriteLine("After toggling case: " + toggledString);
}
static string IncreaseCharacters(string str)
{
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
chars[i]++;
}
return new string(chars);
}
static string ToggleCase(string str)
{
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] >= 65 && chars[i] <= 90)
{
chars[i] = (char)(chars[i] + 32);
}
else
{
chars[i] = (char)(chars[i] - 32);
}
}
return new string(chars);
}
}
=========================================================================
==============
4. Various string operations
using System;
class Program
{
static void Main()
{
Console.WriteLine("Enter a string:");
string input = Console.ReadLine();
using System;
class Program
{
static void Main()
{
num1 = int.Parse(Console.ReadLine());
num2 = int.Parse(Console.ReadLine());
//3 Swapping
int temp = num1;
num1 = num2;
num2 = temp;
Console.WriteLine("After swapping ");
Console.WriteLine("num1: " + num1);
Console.WriteLine("num2: " + num2);
}
}
=========================================================================
============================
CONTROL STATEMENTS:
1.Write a program which asks the user for his login and password. Both
must be strings. After 3 wrong attempts, the user will be rejected.
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
string correctLogin = "user";
string correctPassword = "password";
int attempts = 0;
Console.WriteLine("Welcome to the login system!");
while (attempts < 3)
{
Console.Write("Enter your login: ");
string login = Console.ReadLine();
Console.Write("Enter your password: ");
string password = Console.ReadLine();
if (login == correctLogin && password == correctPassword)
{
Console.WriteLine("Login successful!");
break; // Exit the loop if login is successful
}
else
{
attempts++;
Console.WriteLine($"Invalid login or password. Attempts
left: {3 - attempts}");
}
}
if (attempts >= 3)
{
Console.WriteLine("Login attempts exceeded. Access denied.");
}
}
}
=========================================================================
=============================================
using System;
class Program
{
static void Main()
{
string num1Str = Console.ReadLine();
string num2Str = Console.ReadLine();
if (position == -1)
{
Console.WriteLine("2nd number is not found ");
}
else
{
switch (position)
{
case 1:
Console.WriteLine("unit's place.");
break;
case 2:
Console.WriteLine("ten's place");
break;
case 3:
Console.WriteLine(" hundred's place ");
break;
case 4:
Console.WriteLine("thousand's place");
break;
default:
Console.WriteLine("beyond thousand's place");
break;
}
}
}
}
=========================================================================
=======================================================
ARRAYS:
1 NO OF ELEMETNS
using System;
class Program
{
static void Main()
{
int[] array = { 1, 2, 3, 4, 5, 6, 7 };
int count = 0;
try
{
while (true)
{
int element = array[count];
count++;
}
}
catch (IndexOutOfRangeException)
{
}
Console.WriteLine($"Number of elements in the array: {count}");
}
}
=========================================================================
==========================================================
2. Operations on arrays:
using System;
class Program
{
static void Main()
{
const int size = 10;
int[] array = new int[size];
Console.WriteLine("Enter 10 integers:");
PrintDescending(array);
FindMinMax(array);
CalculateSum(array);
}
Array.Sort(sortedArray);
Array.Reverse(sortedArray);
1. Employee info
using System;
class Program
{
static void Main()
{
Employee employee = new Employee("CVR Employee", 96996M);
employee.CalculateNetPay();
employee.Display();
}
}
=========================================================================
=============================
2. Stock class
using System;
class Program
{
static void Main()
{
try
{
Stock stock = new Stock("CVR Stockk", "AAPL", 150.00,
155.00);
stock.Display();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
=========================================================================
=======================
3. Random Helper
using System;
class Program
{
static void Main()
{
using System;
class Person
{
private string FirstName;
private string LastName;
private string EmailAddress;
private DateTime DateOfBirth;
class Program
{
static void Main()
{
using System;
class Shape
{
class Program
{
static void Main()
{
Shape shape = new Shape();
1 using System;
using System.IO;
class Program
{
static void Main()
{
try
{
Console.WriteLine("Enter content:");
string content = Console.ReadLine();
Console.WriteLine("file created");