0% found this document useful (0 votes)
2 views8 pages

Even Driven501

This document is a preliminary examination for Event Driven Programming for the academic year 2024-2025. It includes sections for identification of key concepts, tracing code for errors, and programming tasks related to C#. The exam tests knowledge on delegates, event handling, collections, and basic programming constructs in C#.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Even Driven501

This document is a preliminary examination for Event Driven Programming for the academic year 2024-2025. It includes sections for identification of key concepts, tracing code for errors, and programming tasks related to C#. The exam tests knowledge on delegates, event handling, collections, and basic programming constructs in C#.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1st Term S.Y.

2024 – 2025
Preliminary Examination
Event Driven Programming

Name: _____________________________ Date: ________ Score: ______

General Instructions: Read and follow the instructions. Cheating


will be automatically zero. Erasures are considered wrong.

I. Identification
Instructions: Read the sentence carefully. Fill each blank
with correct answers. Write the answer on the blank provided.
_____________ 1. These can reference a method that returns and
takes parameters of different types.
_____________ 2. It is a member of a class that is a fired
whenever a specific action takes place.
_____________ 3. What operators that allow adding an event to
the class.
_____________ 4. To register a new subscription to an event.
_____________ 5. This class stores key or values pairs where
the key represents the value in the collection.
_____________ 6. This method returns the key to the specific
index.
_____________ 7. It is an interface that allows you to
determine the number of elements in a collection and copy them
in a simple array type.
_____________ 8. What is the syntax for the format of creating
a List<T> collection?
_____________ 9. It is part of properties of the SortedList
that can used to gets and sets the value associated with a
specific key.
_____________ 10. It is an interface that allows you to loop
through elements in a collection.
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

_____________ 11. What is the syntax for adding an event?


_____________ 12. The methods that are invoked when an event
occurs are known as _____.
_____________ 13. It used the keyword for declaring a delegate
on a class.
_____________ 14. It is also a reference type data that holds
a reference method.
_____________ 15. It is used to remove all the items in the
SortedList.

II. Tracing
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

Instructions: Read the program carefully. Trace and underline


the incorrect methods or syntax of the given program.
1.
using System;
using System.Collections.Generic;

namespace PrelimExamination {
public delegate void TaskProcessor(string task);

public class Program


{
public static void main(string[] args)
{
Queue<string> taskQueue = new Queue<>();

taskQueue.Enqueue("Task 1: Clean the house"):


taskqueue.Enqueue("Task 2: Wash the car");
taskQueue.enqueue("Task 3: Do the laundry");

TaskProcessor processor = ProcessTask;

console.writeLine("Processing tasks from the queue:");


while (taskQueue.Count > 0)
{
String currentTask = taskQueue.dequeue():
Processor(currentTask);
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

}
}
public static void ProcessTask(string task)
{
Console.WriteLine(Task + " - Completed");
}
}
}

2.
using System;
using System.Collections.Generic;

namespace Preliminary_Examination {

public delegate void RequestHandler(string customerName,


string request);

public class Program


{
public static void Main(String[] args)
{
Queue<(string customerName, string request)>
requestQueue = new queue<(string, string)>();
requestQueue.enqueue(("John", "Password reset"));
RequestQueue.Enqueue(("Alice", "Billing inquiry"));
requestQueue.Enqueue(("Bob", "Technical support"));
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

RequestHandler requestHandler = HandleRequest:


Console.WriteLine("Processing customer requests:");

while (requestQueue.count > 0)


{
var currentRequest = requestQueue.dequeue();
requestHandler(currentRequest.CustomerName,
currentRequest.request);
}
}
public static void HandleRequest(string customerName,
string request);
{
Console.WriteLine($"Customer: {customerName}, Request:
{request} - Processed");
}
}
}
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

3.
using System;
using System.Collections.Generic; // Required for SortedList

namespace PrelimExaminations {
public class Program
{
public static void Main(string[] args)
{
SortedList<string, int> studentScores = new
SortedList<string, int>();

studentScores.Add("Alice", 85):
studentScores.add("Bob", 90);
studentScores.Add("Charlie", 88);
StudentScores.Add("Dave", 92);
studentScores.Add("Eve", 79);

Console.WriteLine("Students and their scores (sorted


by name):");
foreach (KeyValuePair<string, int> student in
studentScores);
{
Console.WriteLine("Student: " + student.Key + ",
Score: " + student.value);
}
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

string searchStudents = "Charlie";


if (studentScores.ContainsKey(searchStudent))
{
Console.writeLine($"\n{searchStudent}'s score:
{studentScores[searchStudent]}");
}
else
{
Console.WriteLine($"\nStudent {searchStudent} not
found.");
}
studentScores.Remove("Eve");

Console.WriteLine("\nUpdated list after removing


'Eve':");
foreach (KeyValuepair<string, int> student in
studentScores);
{
Console.WriteLine("Student: " + student.key + ",
Score: " + student.Value);
}
}
}
}
1st Term S.Y. 2024 – 2025
Preliminary Examination
Event Driven Programming

III. Programming
Instructions: Create a C# Program to the given statement.
1. Create a for loop to display all the added objects in the
SortedList Grades of the students using GetKey.
2. Create a program that defines a delegate for performing
basic arithmethic operations on two numbers.
3. Create a delegate named DelIntVal that contains two
parameters of int data type name getNum1 and getNum2.

You might also like