1. Create a simple calculator for a Windows application. Name the project as CalculatorApplication and
1. Create a simple calculator for a Windows application. Name the project as CalculatorApplication and
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![Calculator Using Generic Delegate and Event
Objectives:
At the end of the exercise, the students should be able to:
▪ Declare, instantiate, and invoke delegates;
•
Use generic delegate data types in a program; and
▪ Declare events and use event accessors.
Software Requirement:
• Visual Studio IDE 2015 or higher
Procedures:
Instructions:
1. Create a simple calculator for a Windows application. Name the project as CalculatorApplication and
the form as FrmCalculator.
2. Follow the design for the FrmCalculator using the screenshot below. Refer to the table for the
properties for each control.
FrmCalculator
Enter First Number: 35
Enter Second Number: 10
Windows Forms Controls
TextBox
ComboBox
TextBox
Label
Answer: 3.5
Button
Calculate
X
Properties
Name: txtBoxinput1
Font Size: 12
Name: cbOperator
Font Name: Consolas
Font Size: 12
Name: txtBoxinput2
Font Size: 12
Name: IblDisplay Total
Name: btnEqual
Font Name: Consolas
Font Size: 14](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe3d5745e-6cb8-49a3-917c-6d3f29713935%2F5a3a5330-3bf3-44b4-be58-6e54b928d344%2Fryc0luj_processed.png&w=3840&q=75)
Transcribed Image Text:Calculator Using Generic Delegate and Event
Objectives:
At the end of the exercise, the students should be able to:
▪ Declare, instantiate, and invoke delegates;
•
Use generic delegate data types in a program; and
▪ Declare events and use event accessors.
Software Requirement:
• Visual Studio IDE 2015 or higher
Procedures:
Instructions:
1. Create a simple calculator for a Windows application. Name the project as CalculatorApplication and
the form as FrmCalculator.
2. Follow the design for the FrmCalculator using the screenshot below. Refer to the table for the
properties for each control.
FrmCalculator
Enter First Number: 35
Enter Second Number: 10
Windows Forms Controls
TextBox
ComboBox
TextBox
Label
Answer: 3.5
Button
Calculate
X
Properties
Name: txtBoxinput1
Font Size: 12
Name: cbOperator
Font Name: Consolas
Font Size: 12
Name: txtBoxinput2
Font Size: 12
Name: IblDisplay Total
Name: btnEqual
Font Name: Consolas
Font Size: 14
![3. In the ComboBox, add the following arithmetic operators:
Arithmetic Operators
4. Create a class named CalculatorClass and declare a generic delegate named Formula above the
name of the class. See sample code below.
public delegate T Information<T>(T arg1);
5. Inside the class, declare the generic delegate's variable and set its data type to double. See sample
code below.
public Information<string> info;
6. After declaring the variable for the generic delegate, create two (2) methods that retum the sum and
difference based on the following table:
Method Name
GetSum
GetDifference
Double
Double
Data Type
7. Add an event accessor named CalculateEvent with two (2) methods add and remove. Set a message
in the console just to confirm if the delegate is added or removed.
Example: Console.WriteLine("Added the Delegate");
8. In the frmCalculator class, declare the variable for the CalculatorClass named cal. After declaring.
instantiate it inside the constructor of frmCalculator.
9. Set the two (2) variables where the data types are double with a variable named num1 and num2.
10. Double click the button to create the method for button event automatically.
frmCalculator
Enter First Number: 35
Enter Second Number: 10
Answer: 3.5
Calculate
11. Get the value of txtBoxinput1 for num1 and txtBoxinput2 for num2.
Note: You may encounter an error that says, "Cannot implicitly convert type string to double." If this happen
use Convert.ToDouble() to convert the value in the TextBox.
Challenge Exercise:
12. In CalculatorClass, add two (2) return type methods named Get Product for multiplication and
GetQuotient for division.
13. In the frmCalculator class, write a condition that validates the selected arithmetic operator in the
ComboBox. It should call the event and display the answer in a label.
Example:
cal. Calculate Event += new Formulac<double> (cal. Get Sum);
lblDisplay Total. Text = cal.GetSum(num1, num2).ToString();
cal. Calculate Event -= new Formula<double> (cal. Get Sum);
14. Run the program to check the output.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe3d5745e-6cb8-49a3-917c-6d3f29713935%2F5a3a5330-3bf3-44b4-be58-6e54b928d344%2Fnvy00p7_processed.png&w=3840&q=75)
Transcribed Image Text:3. In the ComboBox, add the following arithmetic operators:
Arithmetic Operators
4. Create a class named CalculatorClass and declare a generic delegate named Formula above the
name of the class. See sample code below.
public delegate T Information<T>(T arg1);
5. Inside the class, declare the generic delegate's variable and set its data type to double. See sample
code below.
public Information<string> info;
6. After declaring the variable for the generic delegate, create two (2) methods that retum the sum and
difference based on the following table:
Method Name
GetSum
GetDifference
Double
Double
Data Type
7. Add an event accessor named CalculateEvent with two (2) methods add and remove. Set a message
in the console just to confirm if the delegate is added or removed.
Example: Console.WriteLine("Added the Delegate");
8. In the frmCalculator class, declare the variable for the CalculatorClass named cal. After declaring.
instantiate it inside the constructor of frmCalculator.
9. Set the two (2) variables where the data types are double with a variable named num1 and num2.
10. Double click the button to create the method for button event automatically.
frmCalculator
Enter First Number: 35
Enter Second Number: 10
Answer: 3.5
Calculate
11. Get the value of txtBoxinput1 for num1 and txtBoxinput2 for num2.
Note: You may encounter an error that says, "Cannot implicitly convert type string to double." If this happen
use Convert.ToDouble() to convert the value in the TextBox.
Challenge Exercise:
12. In CalculatorClass, add two (2) return type methods named Get Product for multiplication and
GetQuotient for division.
13. In the frmCalculator class, write a condition that validates the selected arithmetic operator in the
ComboBox. It should call the event and display the answer in a label.
Example:
cal. Calculate Event += new Formulac<double> (cal. Get Sum);
lblDisplay Total. Text = cal.GetSum(num1, num2).ToString();
cal. Calculate Event -= new Formula<double> (cal. Get Sum);
14. Run the program to check the output.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY