ASSIGNMENT
Visual Programming
Submitted to:
Rida Bajwa
Submitted by
Saad Ali Mubarak
222201017
Department of Computer Science,
Word Scramble Game:
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace wordScrable
{
internal class Program
{
public static int a = 0;
public static async Task ges()
{
Task.Run(() =>
{
Task.Delay(5000).Wait();
a = 1;
});
}
public static async Task word()
{
int test = 0;
st:
string[] arr = { "apple", "banana", "cherry", "date", "elderberry",
"fig", "grape", "honeydew", "kiwi", "lemon" };
Random ra = new Random();
int n = ra.Next(0, arr.Length);
Console.WriteLine(RandomizeString(arr[n]));
Console.Write("Enter correct string in 5 sec:");
string check = string.Empty;
await ges();
check = Console.ReadLine();
if (check == arr[n])
{
Console.WriteLine("Correct");
test += 10;
if (a == 1)
{
Console.WriteLine("You Enter late -5");
test -= 5;
}
else
{
Console.WriteLine("Wrong");
if (a == 1)
{
Console.WriteLine("You Enter late -5");
test -= 5;
Console.WriteLine("Do you want do it again enter y");
string ch = Console.ReadLine();
if (ch == "y")
{
Task.Delay(5000).Wait();
a = 0;
goto st;
}
Console.WriteLine($"Total points={test}");
public static string RandomizeString(string input)
{
Random rng = new Random();
return new string(input.OrderBy(c => rng.Next()).ToArray());
}
static void Main(string[] args)
{
word();
Console.ReadKey();
}
}
}
Prime Number Finder:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace primeNumber
{
internal class Program
{
static bool IsPrime(int number)
{
if (number <= 1)
return false;
if (number == 2 || number == 3)
return true;
if (number % 2 == 0 || number % 3 == 0)
return false;
for (int i = 5; i * i <= number; i += 6)
{
if (number % i == 0 || number % (i + 2) == 0)
return false;
}
return true;
}
static void Main(string[] args)
{
Console.WriteLine("Enter Starting :");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Ending :");
int b = Convert.ToInt32(Console.ReadLine());
ArrayList arr = new ArrayList();
Console.WriteLine($"Prime numbers from {a} to {b}:");
for (int i = a; i <= b; i++)
{
if (IsPrime(i))
{
arr.Add(i);
Console.Write(i + " ");
}
}
Console.WriteLine("\nif you want to filter even prime or odd prime Enter y");
string ch = Console.ReadLine();
if (ch == "y")
{
Console.WriteLine("Even or odd(e or o)");
string c = Console.ReadLine();
if (c == "e")
{
foreach(int i in arr)
{
if (i % 2 != 0)
{
Console.Write(i + " ");
}
else
{
arr.Remove(i);
}
}
}
else if (c == "o")
{
foreach (int i in arr)
{
if (i % 2 == 0)
{
Console.Write(i + " ");
}
else
{
arr.Remove(i);
}
}
}
}
Console.WriteLine("Do you want save in file(Enter y)");
string fi = Console.ReadLine();
if (fi == "y")
{
string filePath = "PrimeNumbers.txt";
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.WriteLine("Prime numbers :");
foreach (int i in arr)
{
writer.Write(i + " ");
}
}
}
}
}
}
Password Strength Checker:
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace password
{
internal class Program
{
static void Main(string[] args)
{
At:
Console.WriteLine("Enter Password:");
string pass = Console.ReadLine();
char[] str = pass.ToArray();
bool alp = false;
bool sp = false;
bool num = false;
if (str.Length > 15)
{
Console.WriteLine("Password is too long");
}
else
{
if (str.Length >= 8)
{
foreach (var item in str)
{
if ((int)item >= 65)
{
alp = true;
break;
}
else
{
alp = false;
}
}
foreach (var item in str)
{
if ((int)item <= 64 && ((int)item < 48 || (int)item > 57))
{
sp = true;
break;
}
else
{
sp = false;
}
}
foreach (var item in str)
{
if ((int)item >= 48 && (int)item <= 57)
{
num = true;
break;
}
else
{
num = false;
}
}
}
else
{
Console.WriteLine("Password too short try again");
goto At;
}
if (sp == true && num == true && alp == true)
{
Console.WriteLine("Your password is strong");
}
else if (sp == true || num == true && alp == true)
{
Console.WriteLine("Your password is moderate");
if (sp == false)
{
Console.WriteLine("Try Adding Special Character");
}
if (num == false)
{
Console.WriteLine("Try Adding Number");
}
if (alp == false)
{
Console.WriteLine("Try Adding Alphabets");
}
}
else if (sp == false && num == false || alp == false)
{
Console.WriteLine("Your password is weak");
if (num == true)
{
Console.WriteLine("Try adding Special character and alphabets");
}
if (sp == true)
{
Console.WriteLine("Try adding alphabets and number");
}
if (alp == true)
{
Console.WriteLine("Try adding Special character and number");
}
}
}
}
}
}
Number Guessing Game:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace randomGuess
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Enter Difficulty:");
string d = Console.ReadLine();
Random random = new Random();
int guess=0;
int num = random.Next(1, 101);
if (d == "hard")
{
guess = 5;
}
else if (d == "easy")
{
guess = 15;
}
else if (d == "medium")
{
guess = 10;
}
Console.WriteLine($"Your total guess are {guess}");
while(guess > 0)
{
Console.WriteLine($"Total guess remaining = {guess}");
Console.Write("Enter Your Guess :");
int g = Convert.ToInt32(Console.ReadLine());
if (g == num)
{
Console.WriteLine("Correct");
Console.WriteLine($"Your Score = {guess}");
break;
}
else if(g>num)
{
Console.WriteLine("Think lower");
}
else if(g<num)
{
Console.WriteLine("Think Higher");
}
guess--;
}
if (guess == 0)
{
Console.WriteLine("GameOver!");
}
}
}
}
University Resource Management System:
using System;
using System.Collections;
using System.Collections.Generic;
namespace UniversityResourceManagement
{
// Course class to store course details
public class Course
{
public string CourseCode { get; set; }
public string CourseTitle { get; set; }
public int Credits { get; set; }
}
// Library Book class for book details
public class Book
{
public int BookID { get; set; }
public string Title { get; set; }
public string Author { get; set; }
}
class Program
{
// ArrayList for storing courses
private static ArrayList Courses = new ArrayList();
// Dictionary for storing library books
private static Dictionary<int, string> LibraryBooks = new Dictionary<int, string>();
// Dictionary for storing students' borrowed books (Stack)
private static Dictionary<string, Stack<string>> BorrowedBooks = new
Dictionary<string, Stack<string>>();
// Dictionary for storing enrolled students per course
private static Dictionary<string, List<string>> EnrolledStudents = new
Dictionary<string, List<string>>();
// Dictionary for faculty schedules (Queue)
private static Dictionary<string, Queue<string>> FacultySchedules = new
Dictionary<string, Queue<string>>();
static void Main()
{
// Initialize courses
InitializeCourses();
DisplayCourses();
// Enroll students in courses
EnrollStudentsInCourses();
DisplayEnrolledStudents();
// Initialize library books
InitializeLibraryBooks();
DisplayLibraryBooks();
// Faculty schedule
InitializeFacultySchedules();
DisplayFacultySchedules();
// Report summaries
DisplaySummary();
}
// Initialize and display courses
static void InitializeCourses()
{
Courses.Add(new Course { CourseCode = "CS101", CourseTitle = "Intro to CS",
Credits = 3 });
Courses.Add(new Course { CourseCode = "MATH201", CourseTitle = "Calculus",
Credits = 4 });
Courses.Add(new Course { CourseCode = "PHY101", CourseTitle = "Physics",
Credits = 3 });
Courses.Add(new Course { CourseCode = "HIST100", CourseTitle = "World
History", Credits = 2 });
Courses.Add(new Course { CourseCode = "ENG102", CourseTitle = "English
Literature", Credits = 3 });
}
static void DisplayCourses()
{
Console.WriteLine("Courses offered:");
foreach (Course course in Courses)
{
Console.WriteLine($"Code: {course.CourseCode}, Title: {course.CourseTitle},
Credits: {course.Credits}");
}
}
// Enroll students in courses
static void EnrollStudentsInCourses()
{
foreach (Course course in Courses)
{
var studentList = new List<string> { "Alice", "Bob", "Charlie", "David", "Eve" };
EnrolledStudents[course.CourseCode] = studentList;
}
}
static void DisplayEnrolledStudents()
{
Console.WriteLine("\nEnrolled students in each course:");
foreach (var entry in EnrolledStudents)
{
Console.WriteLine($"Course {entry.Key}: {string.Join(", ", entry.Value)}");
}
}
// Initialize library books
static void InitializeLibraryBooks()
{
LibraryBooks.Add(1001, "Introduction to Algorithms");
LibraryBooks.Add(1002, "Design Patterns");
LibraryBooks.Add(1003, "Operating System Concepts");
LibraryBooks.Add(1004, "Data Structures and Algorithms");
LibraryBooks.Add(1005, "Computer Networks");
}
static void DisplayLibraryBooks()
{
Console.WriteLine("\nLibrary books:");
foreach (var book in LibraryBooks)
{
Console.WriteLine($"BookID: {book.Key}, Title: {book.Value}");
}
}
// Borrow book by student
static void BorrowBook(string student, int bookID)
{
if (LibraryBooks.ContainsKey(bookID))
{
if (!BorrowedBooks.ContainsKey(student))
{
BorrowedBooks[student] = new Stack<string>();
}
if (BorrowedBooks[student].Count < 3)
{
var bookTitle = LibraryBooks[bookID];
BorrowedBooks[student].Push(bookTitle);
LibraryBooks.Remove(bookID);
Console.WriteLine($"{student} borrowed '{bookTitle}'");
}
else
{
Console.WriteLine($"{student} cannot borrow more than 3 books.");
}
}
else
{
Console.WriteLine($"BookID {bookID} is not available in the library.");
}
}
static void ReturnBook(string student)
{
if (BorrowedBooks.ContainsKey(student) && BorrowedBooks[student].Count >
0)
{
var returnedBook = BorrowedBooks[student].Pop();
Console.WriteLine($"{student} returned '{returnedBook}'");
}
else
{
Console.WriteLine($"{student} has no books to return.");
}
}
// Initialize and display faculty schedules
static void InitializeFacultySchedules()
{
var timeSlots = new Queue<string>(new[] { "10:00 AM - Class", "11:00 AM -
Office Hours", "12:00 PM - Class", "2:00 PM - Lab", "4:00 PM - Meeting" });
FacultySchedules["Dr. Smith"] = new Queue<string>(timeSlots);
FacultySchedules["Prof. Johnson"] = new Queue<string>(timeSlots);
}
static void DisplayFacultySchedules()
{
Console.WriteLine("\nFaculty schedules:");
foreach (var schedule in FacultySchedules)
{
Console.WriteLine($"{schedule.Key}: Next session - {schedule.Value.Peek()}");
}
}
static void ProcessNextSession(string faculty)
{
if (FacultySchedules.ContainsKey(faculty) && FacultySchedules[faculty].Count >
0)
{
Console.WriteLine($"{faculty} completed
'{FacultySchedules[faculty].Dequeue()}'");
if (FacultySchedules[faculty].Count > 0)
{
Console.WriteLine($"Next session for {faculty}:
{FacultySchedules[faculty].Peek()}");
}
else
{
Console.WriteLine($"{faculty} is free for the day.");
}
}
}
// Display overall summary
static void DisplaySummary()
{
Console.WriteLine("\n--- University Resource Summary ---");
// Courses and students
DisplayCourses();
DisplayEnrolledStudents();
// Library book availability
DisplayLibraryBooks();
// Faculty schedules
DisplayFacultySchedules();
}
}
}