CS411 Visual Programming Midterm Cheat Sheet
Core Concepts
1. Event-Driven Programming: Programs respond to events like button clicks, keypresses, etc.
2. Event Loop: Continuously checks for events and handles them.
3. Synchronous vs Asynchronous:
- Sync: Waits for task to finish before moving on.
- Async: Can handle multiple tasks at the same time.
4. Event Types: Raw Event, Derived Event, Event Stream, Stateless Agent.
5. Event-Based vs Request-Based:
- Event-Based: Push, loosely coupled (e.g., GUI).
- Request-Based: Pull, tightly coupled (e.g., Web).
C++ Basics
Simple Input Loop:
#include <iostream>
using namespace std;
int main() {
char a;
do {
a = cin.get();
cout << a;
} while (a != 'x');
return 0;
}
C# Basics & Windows Forms
Hello World (Console):
using System;
class Program {
static void Main() {
Console.WriteLine("Hello world!");
}
}
Hello World (GUI):
using System.Windows.Forms;
class Program {
static void Main() {
MessageBox.Show("Hello world!");
}
}
Events and Delegates (C#)
CS411 Visual Programming Midterm Cheat Sheet
public delegate void MyEventHandler();
public class MyForm : Form {
public event MyEventHandler myEvent;
public MyForm() {
myEvent += new MyEventHandler(MyEventFunction);
myEvent(); // fire event
}
public void MyEventFunction() {
MessageBox.Show("Event Fired!");
}
}
Exception Handling (C#)
try {
File.OpenRead("file.txt");
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
} finally {
Console.WriteLine("Cleanup done");
}
Quick Definitions
- Event: An occurrence like a click or file change.
- Event Producer: Source that generates event.
- Event Consumer: Component that reacts to event.
- Delegate: Reference to a method.
- MessageBox: GUI pop-up alert.
- Polymorphism: Ability to call derived class methods using base class reference.