0% found this document useful (0 votes)
8 views7 pages

Wajiha Test

Uploaded by

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

Wajiha Test

Uploaded by

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

//----------------------------------1

//using System;

//class InvalidNameException : Exception


//{
// public InvalidNameException(string message) : base(message) { }
//}

//class User
//{
// public string Name { get; set; }
// public int Age { get; set; }
//}

//class Program
//{
// static void Main()
// {
// try
// {
// Console.Write("Enter Name: ");
// string name = Console.ReadLine();
// if (string.IsNullOrWhiteSpace(name) || ContainsNumbers(name))
// throw new InvalidNameException("Invalid Name: Must not be empty
or contain numbers.");

// Console.Write("Enter Age: ");


// string ageInput = Console.ReadLine();
// if (!int.TryParse(ageInput, out int age))
// throw new FormatException("Age must be a number.");

// if (age < 0 || age > 120)


// throw new ArgumentOutOfRangeException("Age must be between 0 and
120.");

// User user = new User { Name = name, Age = age };


// Console.WriteLine($"User created: Name = {user.Name}, Age =
{user.Age}");
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
// }

// static bool ContainsNumbers(string input)


// {
// foreach (char c in input)
// if (char.IsDigit(c)) return true;
// return false;
// }
//}

//----------------------------------2
//using System;
//using System.Collections.Generic;
//using System.Linq;

//class Student
//{
// public int ID { get; set; }
// public string Name { get; set; }
// public double Grade { get; set; }
//}

//class Program
//{
// static void Main()
// {
// List<Student> students = new List<Student>();

// while (true)
// {
// Console.WriteLine("\n1. Add Student\n2. Remove Student\n3. Find Top
Student\n4. Display All Students\n5. Exit");
// int choice = int.Parse(Console.ReadLine());

// if (choice == 1)
// {
// Student student = new Student();
// Console.Write("Enter ID: ");
// student.ID = int.Parse(Console.ReadLine());
// Console.Write("Enter Name: ");
// student.Name = Console.ReadLine();
// Console.Write("Enter Grade: ");
// student.Grade = double.Parse(Console.ReadLine());
// students.Add(student);
// }
// else if (choice == 2)
// {
// Console.Write("Enter ID to Remove: ");
// int id = int.Parse(Console.ReadLine());
// students.RemoveAll(s => s.ID == id);
// }
// else if (choice == 3)
// {
// if (students.Count > 0)
// {
// Student topStudent = students.OrderByDescending(s =>
s.Grade).First();
// Console.WriteLine($"Top Student: {topStudent.Name}, Grade:
{topStudent.Grade}");
// }
// else
// {
// Console.WriteLine("No students available.");
// }
// }
// else if (choice == 4)
// {
// foreach (var student in students.OrderBy(s => s.Name))
// {
// Console.WriteLine($"ID: {student.ID}, Name: {student.Name},
Grade: {student.Grade}");
// }
// }
// else if (choice == 5)
// {
// break;
// }
// }
// }
//}

//----------------------------------3

//using System;
//using System.Collections.Generic;
//using System.Linq;

//class Program
//{
// static void Main()
// {
// Dictionary<string, int> inventory = new Dictionary<string, int>();

// while (true)
// {
// Console.WriteLine("\n1. Add Item\n2. Update Stock\n3. Check
Availability\n4. Display All Items\n5. Exit");
// int choice = int.Parse(Console.ReadLine());

// if (choice == 1)
// {
// Console.Write("Enter Item Name: ");
// string itemName = Console.ReadLine();
// Console.Write("Enter Stock Count: ");
// int stockCount = int.Parse(Console.ReadLine());
// if (!inventory.ContainsKey(itemName))
// {
// inventory[itemName] = stockCount;
// Console.WriteLine("Item added.");
// }
// else
// {
// Console.WriteLine("Item already exists.");
// }
// }
// else if (choice == 2)
// {
// Console.Write("Enter Item Name: ");
// string itemName = Console.ReadLine();
// if (inventory.ContainsKey(itemName))
// {
// Console.Write("Enter New Stock Count: ");
// inventory[itemName] = int.Parse(Console.ReadLine());
// Console.WriteLine("Stock updated.");
// }
// else
// {
// Console.WriteLine("Item not found.");
// }
// }
// else if (choice == 3)
// {
// Console.Write("Enter Item Name: ");
// string itemName = Console.ReadLine();
// if (inventory.ContainsKey(itemName) && inventory[itemName] > 0)
// {
// Console.WriteLine("Item is available.");
// }
// else
// {
// Console.WriteLine("Item is not available.");
// }
// }
// else if (choice == 4)
// {
// foreach (var item in inventory.OrderBy(i => i.Key))
// {
// Console.WriteLine($"Item: {item.Key}, Stock: {item.Value}");
// }
// }
// else if (choice == 5)
// {
// break;
// }
// }
// }
//}

//----------------------------------4

//using System;
//using System.Collections.Generic;
//using System.Linq;

//class Product
//{
// public int ID { get; set; }
// public string Name { get; set; }
// public double Price { get; set; }
// public string Category { get; set; }
//}

//class Program
//{
// static void Main()
// {

// List<Product> products = new List<Product>


// {
// new Product { ID = 1, Name = "PC", Price = 1500, Category = "Tech" },
// new Product { ID = 2, Name = "mobile", Price = 20, Category =
"Tech" },
// new Product { ID = 3, Name = "storybook", Price = 24, Category =
"copy" },
// new Product { ID = 4, Name = "wire", Price = 23, Category = "Tech" },
// new Product { ID = 5, Name = "book", Price = 3, Category = "copy" }
// };

// Console.WriteLine("Products under $50:");


// var productsUnder50 = products.Where(p => p.Price < 50);
// foreach (var product in productsUnder50)
// {
// Console.WriteLine($"Name: {product.Name}, Price: {product.Price}");
// }

// Console.WriteLine("\nProducts grouped by Category:");


// var groupedProducts = products.GroupBy(p => p.Category);
// foreach (var group in groupedProducts)
// {
// Console.WriteLine($"\nCategory: {group.Key}");
// foreach (var product in group)
// {
// Console.WriteLine($" Name: {product.Name}, Price:
{product.Price}");
// }
// }

// Console.Write("\nEnter a category to count products: ");


// string categoryToCount = Console.ReadLine();
// int productCount = products.Count(p => p.Category.Equals(categoryToCount,
StringComparison.OrdinalIgnoreCase));
// Console.WriteLine($"Number of products in category '{categoryToCount}':
{productCount}");
// }
//}

//----------------------------------5

//using System;

//class Program
//{
// delegate int MathOperation(int x, int y);

// static int Add(int x, int y) => x + y;


// static int Subtract(int x, int y) => x - y;
// static int Multiply(int x, int y) => x * y;
// static int Divide(int x, int y)
// {
// if (y == 0) throw new DivideByZeroException("Cannot divide by zero.");
// return x / y;
// }

// static void Main()


// {
// MathOperation operation;

// Console.WriteLine("Enter two numbers:");


// int num1 = int.Parse(Console.ReadLine());
// int num2 = int.Parse(Console.ReadLine());

// try
// {
// operation = Add;
// Console.WriteLine($"Addition: {operation(num1, num2)}");

// operation = Subtract;
// Console.WriteLine($"Subtraction: {operation(num1, num2)}");

// operation = Multiply;
// Console.WriteLine($"Multiplication: {operation(num1, num2)}");

// operation = Divide;
// Console.WriteLine($"Division: {operation(num1, num2)}");
// }
// catch (DivideByZeroException ex)
// {
// Console.WriteLine(ex.Message);
// }
// }
//}

//----------------------------------6

//using System;
//using System.Collections.Generic;
//using System.Linq;

//class Program
//{
// delegate void BookAction(string title);

// static void Main()


// {
// List<string> books = new List<string> { "Wajiha", "1233", "abcd", "3333",
"7878" };

// Dictionary<string, bool> bookAvailability = new Dictionary<string, bool>


// {
// { "Wajiha", true },
// { "1233", true },
// { "abcd", true },
// { "3333", true },
// { "7878", true }
// };

// BookAction issueBook = title =>


// {
// if (!bookAvailability.ContainsKey(title)) Console.WriteLine("Error:
Book does not exist.");
// else if (!bookAvailability[title]) Console.WriteLine("Error: Book is
already issued.");
// else
// {
// bookAvailability[title] = false;
// Console.WriteLine($"Book '{title}' has been issued.");
// }
// };

// BookAction returnBook = title =>


// {
// if (!bookAvailability.ContainsKey(title)) Console.WriteLine("Error:
Book does not exist.");
// else if (bookAvailability[title]) Console.WriteLine("Error: Book was
not issued.");
// else
// {
// bookAvailability[title] = true;
// Console.WriteLine($"Book '{title}' has been returned.");
// }
// };

// Console.WriteLine("Enter a keyword to search for books:");


// string keyword = Console.ReadLine();
// var filteredBooks = books.Where(b => b.Contains(keyword,
StringComparison.OrdinalIgnoreCase)).ToList();
// foreach (var book in filteredBooks) Console.WriteLine(book);

// int availableBooksCount = bookAvailability.Count(b => b.Value);


// Console.WriteLine($"Number of available books: {availableBooksCount}");

// Console.WriteLine("Enter a book title to issue:");


// string bookToIssue = Console.ReadLine();
// issueBook(bookToIssue);

// Console.WriteLine("Enter a book title to return:");


// string bookToReturn = Console.ReadLine();
// returnBook(bookToReturn);
// }
//}

You might also like