1. (7.5 marks) If given the following delegate declaration: public delegate void TestCallback(object obj); write code segments to perform the following: A) (2 marks) Design a non-static method that can be contained within an instance/object of the TestCallback delegate type. This method should display values of two data fields contained within the object that is passed to the method. Make-up your own method definition that meets these requirements. B) (1.5 marks) Create an instance of the TestCallback delegate (i.e. a delegate object) and initialize this object to contain an entry point of the method defined in part A) as well as a copy of the object that calls this method. C) (2.5 marks) Create an event field and the corresponding event property of the given TestCallback delegate type. D) (1.5 marks) Write a complete statement that will add the method that you created in question A) to be a handler of the event you created in question C). Make up your own object name that raises the event.
Added by Emilio M.
Close
Step 1
Here's an example: ```csharp public class MyClass { private int field1; private string field2; public void DisplayFields(object obj) { MyClass myObj = (MyClass)obj; Console.WriteLine("Field 1: " + myObj.field1); Show more…
Show all steps
Your feedback will help us improve your experience
Tanvi Garg and 89 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
In C++, Using classes, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries. a. Define a class, addressType, that can store a street address, city, state, and zip code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the data members. b. Define a class extPersonType using the class personType (as defined in Example 1-12, Chapter 1), the class dateType (as designed in Programming Exercise 2 of Chapter 2), and the class addressType. Add a data member to this class to classify the person as a family member, friend, or business associate. Also, add a data member to store the phone number. Add (or override) the functions to print and store the appropriate information. Use constructors to automatically initialize the data members. c. Derive the class addressBookType from the class arrayListType, as defined in this chapter, so that an object of type addressBookType can store objects of type extPersonType. An object of type addressBookType should be able to process a maximum of 500 entries. Add necessary operations to the class addressBookType so that the program should perform the following operations: i. Load the data into the address book from a disk. ii. Search for a person by last name. iii. Print the address, phone number, and date of birth (if it exists) of a given person. iv. Print the names of the people whose birthdays are in a given month or between two given dates. v. Print the names of all the people having the same status, such as family, friend, or business. vi. Print the names of all the people between two last names.
Akash M.
Create an example of an overloaded method show a simple class definition for a class called MyRect, which defines a rectangular shape. The MyRect class must have four instance variables, denoting the upper left and lower right corners of the rectangle: x1, y1, x2, and y2. When a new instance of the MyRect class is initially created, all its instance variables are initialized. Implement a method called buildRect that uses Point objects rather than individual coordinates as its four integer arguments to create the appropriate corners of the resulting rectangle object. You should overload buildRect so that its parameter list takes Point objects. (Note that you will need to import the Point class from the java.awt package to use it in this example.) After implementing the buildRect method, create a print method to print the rectangle's coordinates.
HW_2c_: Based on the following code, fill in the runtime stack. In other words, list the items that are pushed on the stack when each function is called. 1a.) Fill in the runtime stack to show the activation record when the getScore function is called. #include <iostream> using namespace std; int getScore() { int score; cout << "Enter your Score: "; cin >> score; return score; } bool SalcResult(int score) { if (score >= 70) return true; else return false; } void displayResult(int score, bool result) { cout << "Score: " << score << endl; if (result == true) cout << "Credit." << endl; else cout << "No Credit." << endl; } int main() { int score; bool result; score = getScore(); result = SalcResult(score); displayResult(score, result); return 0; } 1b.) Fill in the runtime stack to show the activation record when the SalcResult function is called. 1c.) Fill in the runtime stack to show the activation record when the displayResult function is called.
Sri K.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD