CS411 – Visual Programming: Midterm Important Subjective (102 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS411 Course Page · CS411 MCQ Pack (319 MCQs)
-
What are the types of constructors in C#?
Topic: C# Language Basics & OOP
A constructor is a special method of the class that is automatically invoked when an instance of the class is created. In C#, constructors can be divided into 5 types: 1. Default Constructor 2. Parameterized Constructor 3. Copy Constructor 4. Static Constructor 5. Private Constructor
-
What is the return type of a destructor in C#? Also state the rule in C++.
Topic: C# Language Basics & OOP
Destructors do not have any return type, not even void. A destructor has no return type and has exactly the same name as the class name (including the same case). In C++: a destructor does not return a value (or void), and it cannot be declared as const, volatile, or static.
-
What are the different types of properties available in C#?
Topic: C# Language Basics & OOP
There are the following 4 types of properties: 1. Read-Write Property 2. Read-Only Property 3. Static Property 4. Indexer Property
-
What is an anonymous type in C#? Declare and use an anonymous type in C#.
Topic: C# Language Basics & OOP
An anonymous type is a type without any name that can contain public read-only properties only. It cannot contain other members, such as fields, methods, events, etc. You create an anonymous type using the new operator with an object initializer syntax. Code: using System; public class Program { public static void Main() { var student = new { Id = 190202640, FirstName = "JUNAID", LastName = "Malik" }; Console.WriteLine(student.Id); Console.WriteLine(student.FirstName); Console.WriteLine(student.LastName); } }
-
Write a C# program that creates a two-dimensional array of 3 rows and 2 columns and prints all of its elements.
Topic: C# Language Basics & OOP
using System; public class Program { public static void Main() { int[,] arr2d = new int[3,2]{ {1, 2}, {3, 4}, {5, 6} }; Console.WriteLine(arr2d[0, 0]); Console.WriteLine(arr2d[0, 1]); Console.WriteLine(arr2d[1, 0]); Console.WriteLine(arr2d[1, 1]); Console.WriteLine(arr2d[2, 0]); Console.WriteLine(arr2d[2, 1]); } }
-
Write the C# code to take any string as input from the user and then write that string to a file named "Student.txt".
Topic: C# Language Basics & OOP
using System; class Program { static void Main() { while (true) // Loop indefinitely { Console.WriteLine("Enter input:"); // Prompt string line = Console.ReadLine(); // Get string from user if (line == "exit") // Check string { break; } // Write the string to a file. System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\student.txt"); file.WriteLine(line); file.Close(); } } }
-
Suppose we have created a Button in C#. Set its minimum width = 75 and margin = 10 in C# code.
Topic: C# Language Basics & OOP
We have three methods: 1. First drag the button. 2. Then go to the Properties and increase or decrease the size of the button. 3. Same as above, but in programming code: private void CreateButton() { // Create a Button object Button Button = new Button(); // Set Button properties Button.Height = 10; Button.Width = 75; }
-
What is the meaning of the word abstraction?
Topic: C# Language Basics & OOP
Abstraction is a process to hide the internal details and show only the functionality.
-
What is infinite recursion?
Topic: C# Language Basics & OOP
Infinite recursion is a special case of an infinite loop that is caused by recursion. A recursive function will only run out of stack space if n is less than 1 or n is too large; error checking would remove the first case.
-
Write down the features of C#.
Topic: C# Language Basics & OOP
Features of C#: • Simple, modern and easy to learn general-purpose programming language. • Object-oriented: it supports encapsulation, inheritance and polymorphism. • Type-safe: type safety helps avoid runtime errors. • Automatic garbage collection (memory management) through the CLR. • Component-oriented: properties, indexers, delegates and events are built into the language. • Compiles to MSIL (Microsoft Intermediate Language) and runs on the CLR, so it is platform independent within the .NET environment. • Rich class library support from the .NET Framework. • Structured exception handling, versioning support and interoperability with other .NET languages.
-
What is an attached property in WPF?
Topic: WPF & XAML Basics
An attached property is an Extensible Application Markup Language (XAML) concept. Attached properties enable extra property/value pairs to be set on any XAML element, even though the element doesn't define those extra properties in its object model. The extra properties are globally accessible.
-
For what purpose is XAML used in WF and WCF?
Topic: WPF & XAML Basics
XAML is primarily used to describe interfaces in WPF and Silverlight. It is also used to express activities and configurations in Workflow Foundation (WF) and Windows Communication Foundation (WCF). It is a common language for programmers and other experts, e.g. UI design experts. Field-specific development tools can be made; field experts are graphic designers, and they can use a design tool such as Expression Blend. Other than coordinating with designers, XAML is good for: a concise way to represent UI or hierarchies of objects; it encourages separation of front-end and back-end; tool support with copy and paste; and it is used by all WPF tools.
-
What is the purpose of using XAML extensions?
Topic: WPF & XAML Basics
XAML is the language to build user interfaces for Windows and mobile applications that use Windows Presentation Foundation (WPF), UWP, and Xamarin Forms. The purpose of XAML is simple: to create user interfaces using a markup language that looks like XML.
-
WPF combines the best attributes of some systems. Write the names of three of them.
Topic: WPF & XAML Basics
WPF aims to combine the best attributes of systems such as: • DirectX (3D and hardware acceleration) • Windows Forms (developer productivity) • Adobe Flash (powerful animation support) • HTML (declarative markup)
-
Write two differences between WPF and DirectX.
Topic: WPF & XAML Basics
WPF is made for designers to create vector-based applications using XML and managed code. It uses DirectX as the rendering engine under the covers. DirectX is a set of APIs that abstracts access to modern graphics rendering hardware, as well as other technologies such as sound or input devices. WPF is not designed for any significant game programming, other than, say, a simple card game. DirectX is designed with the intention of allowing you to create a 3D user interface into your game.
-
Why does C# let us develop device resolution independent graphics?
Topic: WPF & XAML Basics
C# enables us to develop device-independent graphics so that the same application/GUI has the same aspect ratio and appearance on all kinds of displays, e.g. Windows Phone, Windows PC, etc.
-
Which term is used to refer to an object that derives from "UIElement" or "FrameworkElement"? From which classes are WPF elements derived?
Topic: WPF & XAML Basics
UIElement is the base class for all 2D visual objects (System.Windows.UIElement). FrameworkElement is the base class that adds support for styles, data binding, resources, etc. (System.Windows.FrameworkElement). WPF classes are in the System.Windows namespace, and WPF is used to build Windows client applications that run on the Windows operating system.
-
Why are most WPF classes inherently thread-unsafe?
Topic: WPF & XAML Basics
Most WPF classes derive from DispatcherObject and are therefore inherently thread-unsafe. The DispatcherObject is the base class meant for any object that wishes to be accessed only on the thread that created it; the Dispatcher refers to WPF's version of a Win32-like message loop.
-
Write the syntax of a CDATA section in XAML.
Topic: WPF & XAML Basics
<x:Code> <![CDATA[ void button_Click(object sender, RoutedEventArgs e) { this.Close(); } ]]> </x:Code>
-
What is the difference between x:ClassModifier and x:FieldModifier?
Topic: WPF & XAML Basics
x:ClassModifier sets the visibility of the generated class; by default it is public. x:FieldModifier sets the field visibility of a named XAML element; by default it is internal.
-
How are the x:Asynchronous and x:Synchronous attributes used in XAML 2006?
Topic: WPF & XAML Basics
x:Asynchronous controls the size of the asynchronous XAML loading chunk. x:Synchronous is used as 'x:SynchronousMode="Async"' on the root element of the XAML file.
-
Why is XML used?
Topic: WPF & XAML Basics
XML is used to exchange data. It is a stricter version of HTML.
-
What are the methods of XML documents?
Topic: WPF & XAML Basics
It has two methods: 1. XmlDocument 2. XmlReader (For more details, see handout page 49.)
-
Consider the following code snippet and write the output: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<uni name=\"Virtual\"> university Node</uni>"); Console.WriteLine(xmlDoc.DocumentElement.Name); Console.WriteLine(xmlDoc.DocumentElement.InnerText); Console.ReadLine();
Topic: WPF & XAML Basics
Element Name: Virtual Inner Text: University Node
-
Write the syntax of an attached property in XML (XAML).
Topic: WPF & XAML Basics
An attached property is set on an element in attribute syntax in the form DefiningType.PropertyName="Value", where DefiningType is the class that defines the attached property. Examples: <Button Grid.Row="1" Grid.Column="2" Content="OK"/> <Button DockPanel.Dock="Top" Content="Top"/> The same can be done in code, e.g. Grid.SetRow(button, 1); and DockPanel.SetDock(button, Dock.Top);
-
How do you represent XML code in C#? (Convert XML code into C#.)
Topic: WPF & XAML Basics
Using the System.Xml namespace, XML is handled in C# through classes such as XmlDocument: XmlDocument doc = new XmlDocument(); doc.LoadXml("<uni name=\"Virtual\">University Node</uni>"); Console.WriteLine(doc.DocumentElement.Name); With LINQ to XML (System.Xml.Linq) the same XML can be built as: XElement root = new XElement("uni", new XAttribute("name", "Virtual"), "University Node");
-
Write the XAML code for the following C# code: StackPanel stackPanel = new StackPanel(); Button button = new Button(); button.Width = 50; button.Height = 70; button.HorizontalAlignment = HorizontalAlignment.Right; stackPanel.Children.Add(button);
Topic: WPF & XAML Basics
<StackPanel> <Button Width="50" Height="70" HorizontalAlignment="Right"/> </StackPanel>
-
What is the difference between Margin and Padding?
Topic: Layout, Panels, Transforms & Animation
Margin and Padding are two very similar properties that are also related to an element's size. All Framework Elements have a Margin property, and all Controls (plus Border) have a Padding property. Their only difference is that Margin controls how much extra space gets placed around the outside edges of the element, whereas Padding controls how much extra space gets placed around the inside edges of the element. Both Margin and Padding are of type System.Windows.Thickness, a class that can represent one, two, or four double values. Margin permits negative values; Padding does not.
-
Which option is to be used to fill the DockPanel? As we know there is no Fill value for "DockPanel", then how is the remaining space filled in the DockPanel? (Marks: 2)
Topic: Layout, Panels, Transforms & Animation
DockPanel allows easy docking of elements to an entire side. The Dock attached property has Left, Right, Top and Bottom values. There is no "Fill" dock value; the last child fills the remaining space by default, unless LastChildFill = false. We can also do this by setting Background = "Red".
-
Which panel's functionality is actually a superset of StackPanel functionality?
Topic: Layout, Panels, Transforms & Animation
DockPanel is a superset of StackPanel. The Dock attached property has Left, Right, Top and Bottom values. (StackPanel is popular, simple and useful; it stacks elements sequentially, and its Orientation can be horizontal or vertical, which is the default.)
-
How many types of children can an object element have? Name them.
Topic: Layout, Panels, Transforms & Animation
An object element can have three types of children: 1. A value for a content property 2. Collection items 3. A value that can be type-converted to the object element
-
WPF panels are derived from which class?
Topic: Layout, Panels, Transforms & Animation
Panels are parents supporting layout of multiple children. They derive from the abstract System.Windows.Controls.Panel class.
-
What are the default values of MaxHeight, MinHeight, MaxWidth and MinWidth?
Topic: Layout, Panels, Transforms & Animation
Max Height = 1, because the height of an element does not include padding, borders, or margins Min Height = 0 Max Width = Positive Infinity Min Width = AUTO (Note: answer reproduced as printed in the source file. In WPF, the actual defaults are MaxHeight = MaxWidth = PositiveInfinity and MinHeight = MinWidth = 0.)
-
When content overflow arises in a built-in panel, how can it be fixed?
Topic: Layout, Panels, Transforms & Animation
Content overflow is when parents and children can't agree on the use of available space. Content overflow can be dealt with by: Clipping, Scrolling, Scaling, Wrapping and Trimming.
-
Why is the Grid panel the best choice for most complex layout scenarios?
Topic: Layout, Panels, Transforms & Animation
The Grid is a layout panel that arranges its child controls in a tabular structure of rows and columns. Its functionality is similar to the HTML table but more flexible. A cell can contain multiple controls; they can span over multiple cells and even overlap each other.
-
When two or more independent grids need to be synchronized, then how can we synchronize them?
Topic: Layout, Panels, Transforms & Animation
We can synchronize two or more independent grids by using SharedSizeGroup.
-
Write the XML (XAML) code for a Grid with a GridSplitter having 3 columns.
Topic: Layout, Panels, Transforms & Animation
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Label Grid.Column="0" Background="Red" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">1</Label> <GridSplitter Grid.Column="0" Width="5"/> <Label Grid.Column="1" Background="Orange" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">2</Label> <Label Grid.Column="2" Background="Yellow" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">3</Label> </Grid>
-
Name the properties supported by the ScaleTransform, and write the default value of each of them.
Topic: Layout, Panels, Transforms & Animation
ScaleTransform enlarges or shrinks an element horizontally, vertically, or in both directions. This transform has four straightforward double properties: • ScaleX — Multiplier for the element's width (default value = 1) • ScaleY — Multiplier for the element's height (default value = 1) • CenterX — Origin for horizontal scaling (default value = 0) • CenterY — Origin for vertical scaling (default value = 0) Example: <Button.RenderTransform> <ScaleTransform ScaleX="2" ScaleY="2"/> </Button.RenderTransform>
-
How does MatrixTransform work like TranslateTransform? Give an example.
Topic: Layout, Panels, Transforms & Animation
TranslateTransform has X — amount to move horizontally (default value = 0), and Y — amount to move vertically (default value = 0). It has no effect as a layout transform. MatrixTransform has a single Matrix property (of type System.Windows.Media.Matrix), representing a 3x3 affine transformation matrix, through which translation (and any other transform) can be expressed.
-
Which transforms do all FrameworkElements have?
Topic: Layout, Panels, Transforms & Animation
All FrameworkElements have two transforms: • LayoutTransform • RenderTransform
-
What is the purpose of WPF 2D transform classes?
Topic: Layout, Panels, Transforms & Animation
To rotate, scale, move (translate), and skew FrameworkElement objects.
-
Name the five built-in 2D transforms which are supported by the "System.Windows.Media" namespace, with their default values.
Topic: Layout, Panels, Transforms & Animation
• TranslateTransform — X, Y (default value = 0) • SkewTransform — AngleX, AngleY, CenterX & CenterY (default value = 0) • ScaleTransform — ScaleX, ScaleY = 1; CenterX, CenterY = 0 • RotateTransform — Angle, CenterX, CenterY = 0 • MatrixTransform — a single Matrix property
-
What do we achieve from ZIndex code?
Topic: Layout, Panels, Transforms & Animation
ZIndex is an integer with a default value of 0 that you can set to any number (positive or negative). Elements with larger ZIndex values are rendered on top of elements with smaller ZIndex values, so the element with the smallest value is in the back, and the element with the largest value is in the front.
-
Which properties are read-only in WPF?
Topic: Layout, Panels, Transforms & Animation
Read-only properties: • DesiredSize • RenderSize • ActualHeight • ActualWidth They are useful to act programmatically on the final size.
-
Why should one care about the "Logical Tree"? Explain with one example. Also describe the logical tree of the code. (Marks: 3)
Topic: Layout, Panels, Transforms & Animation
The logical tree exists even if there is no XAML. Properties, events and resources are tied to logical trees. Properties are propagated down the tree and events can be routed up or down the tree, so one should care about it because it controls how property values and events flow through the application. Example: a property value set on a parent element in the logical tree (such as a Window) is propagated down to its child elements. The logical tree is a simplification of what's actually going on when rendered. The visual tree can be thought of as an extension of the logical tree, though some things can be dropped as well. The visual tree exposes visual implementation details, e.g. a ListBox is a border, two scrollbars and more. Only things from Visual or Visual3D appear in a visual tree. Avoid depending on the visual tree in your code.
-
Using DockPanel in WPF, which attribute will be used if we don't want our center to be filled, and what will be its value?
Topic: Layout, Panels, Transforms & Animation
We can prevent and turn off the last child element from filling the remaining space using the attribute LastChildFill, giving it the value False. Syntax: <DockPanel LastChildFill="False">
-
Write the XAML code to create a DockPanel having four buttons with dock settings i.e. Top, Bottom, Right and Left.
Topic: Layout, Panels, Transforms & Animation
<DockPanel> <Button DockPanel.Dock="Top">Top</Button> <Button DockPanel.Dock="Bottom">Bottom</Button> <Button DockPanel.Dock="Right">Right</Button> <Button DockPanel.Dock="Left">Left</Button> </DockPanel>
-
Write the XAML code to create a Button in a Canvas with attributes Left = 0, Right = 0, Top = 0 and Bottom = 0.
Topic: Layout, Panels, Transforms & Animation
<Canvas> <Button Canvas.Left="0" Canvas.Right="0" Canvas.Top="0" Canvas.Bottom="0">Demo</Button> </Canvas>
-
Write the XAML code to create a panel having four buttons with dock settings i.e. Top, Center, Bottom and Stretch.
Topic: Layout, Panels, Transforms & Animation
Docking only provides Top, Bottom, Left and Right; the center is filled by the last child and Stretch is the default alignment of a control. This is written as: <DockPanel LastChildFill="True"> <Button DockPanel.Dock="Top">Top</Button> <Button DockPanel.Dock="Bottom">Bottom</Button> <Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch">Stretch</Button> <Button>Center</Button> </DockPanel>
-
Write the XAML code to create a panel having four buttons with dock settings i.e. Left and Top, except one button which overrides it. A TextBlock doesn't stretch like a control.
Topic: Layout, Panels, Transforms & Animation
<DockPanel> <Button DockPanel.Dock="Left">Left</Button> <Button DockPanel.Dock="Top">Top</Button> <Button DockPanel.Dock="Top">Top</Button> <Button>Override</Button> </DockPanel> The last button overrides the dock settings and fills the remaining space. A TextBlock placed in the remaining space does not stretch like a control; it takes only the size of its content unless its alignment is explicitly set to Stretch.
-
What is the biggest feature of a dependency property? (Marks: 2)
Topic: Dependency Properties & Property System
Its built-in ability to provide change notification.
-
What are delegates? What are the uses of delegates?
Topic: Events, Delegates & Event-Driven Programming
A delegate is a reference to a method. It is like function pointers in some other languages. A delegate is a type that represents references to methods with a particular parameter list and return type; when you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type, and you can invoke (or call) the method through the delegate instance. Uses: Delegates are used to define callback methods and implement event handling, and they are declared using the "delegate" keyword. You can declare a delegate that can appear on its own or even nested inside a class. Delegates allow you to develop libraries and classes that are easily extensible.
-
Explain delegates: how do you declare and call a delegate?
Topic: Events, Delegates & Event-Driven Programming
Declare a delegate: A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance. // this is the delegate declaration public delegate int Comparer(object obj1, object obj2); Call a delegate: Delegates can be invoked like a normal function or with the Invoke() method. Multiple methods can be assigned to the delegate using "+" or "+=" operator and removed using "-" or "-=" operator; this is called a multicast delegate. If a multicast delegate returns a value, then it returns the value from the last assigned target method.
-
What is the purpose of event-driven architecture?
Topic: Events, Delegates & Event-Driven Programming
An event-driven architecture uses events to trigger and communicate between decoupled services, and it is common in modern applications built with microservices. An event is a change in state, or an update, like an item being placed in a shopping cart on an e-commerce website. Event-driven architecture (EDA) is a software design pattern that enables an organization to detect "events" or important business moments.
-
What are the main benefits of event-driven architecture?
Topic: Events, Delegates & Event-Driven Programming
• Pure competitive advantage • Create operational efficiencies • More robust information • Better scalability and fault tolerance • Increased versatility • Casting functionality
-
Explain routed events.
Topic: Events, Delegates & Event-Driven Programming
Routed events are like dependency properties on top of .NET properties; similarly, routed events are a layer on top of .NET events. They can travel up or down a visual or logical tree. This helps apps remain oblivious to the visual tree. E.g. Button exposes Click based on MouseLeftButtonDown and KeyDown, but actually the button chrome or TextBlock visual child fires it; the event travels up the tree and the Button eventually sees it. Or, like in a previous example, a rectangle on top of a button: arbitrary complex content, but Click is still raised. Otherwise it would require custom code on the inner content or consumers. The concept is very similar to the dependency property concept.
-
Name the three (3) routing strategies that can be chosen by each routed event when it is registered. (Marks: 3)
Topic: Events, Delegates & Event-Driven Programming
• Tunneling: The event is first raised on the root, then on each element down the tree until the source element is reached (or until the event is marked as handled). • Bubbling: The event is first raised on the source element, then on each element up the tree until the root is reached (or until the event is marked as handled). • Direct: The event is only raised on the source element. Only the source element is given the chance to invoke handlers in response.
-
Name the three parameters of handlers for routed events.
Topic: Events, Delegates & Event-Driven Programming
Two are known — the third is unknown: 1. Sender — Type: System.Object — the source of the event. 2. E — Type: System.EventArgs — an object that contains no event data.
-
What happens when an event is moved up (in the tree)?
Topic: Events, Delegates & Event-Driven Programming
This is bubbling: the event is first raised on the source element, then on each element up the tree until the root is reached (or until the event is marked as handled).
-
Why are events used in pairs? Explain with an example.
Topic: Events, Delegates & Event-Driven Programming
In VPL, a program is created by assembling pairs of one event and one or more action blocks. For example, a pair composed of a button event and a motors action tells the robot to move when a button is touched on the robot.
-
What is a keyboard event?
Topic: Events, Delegates & Event-Driven Programming
KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard. The event type (keydown, keypress, or keyup) identifies what kind of keyboard activity occurred. Keyboard events include keyup, keydown and preview versions of them. KeyEventArgs contains Key, ImeProcessedKey, DeadCharProcessedKey, SystemKey, IsUp, IsDown, IsToggled, KeyStates, IsRepeat, and KeyboardDevice. System.Windows.Input.Keyboard and its PrimaryDevice property are accessible everywhere.
-
Name any three types of mouse events that WPF supports.
Topic: Events, Delegates & Event-Driven Programming
• MouseDown — it occurs when a mouse button is pressed. • MouseEnter — it occurs when the mouse pointer enters the control. • MouseHover — it occurs when the mouse pointer hovers over the control. • MouseLeave — it occurs when the mouse pointer leaves the control.
-
Differentiate between an event consumer and an event producer.
Topic: Events, Delegates & Event-Driven Programming
Event consumer: An event consumer is an entity at the edge of an event processing system that receives events from the system. Event producer: An event producer is an entity at the edge of an event processing system that introduces events into the system.
-
Differentiate between a raw (stateless) event and a derived event.
Topic: Events, Delegates & Event-Driven Programming
Raw event: A raw event is an event that is introduced into an event processing system by an event producer. Derived event: A derived event is an event that is generated as a result of event processing that takes place inside an event processing system.
-
Differentiate between a homogeneous event stream and a heterogeneous event stream.
Topic: Events, Delegates & Event-Driven Programming
A stream in which all the events must be of the same type is called a homogeneous event stream, while a stream in which the events may be of different types is referred to as a heterogeneous event stream.
-
What are the types of event agents?
Topic: Events, Delegates & Event-Driven Programming
Event agents are of three main types: 1. Simple event processing agents — react to a single event, e.g. by filtering or routing it. 2. Event stream processing agents — process a stream of events over time, e.g. counting or averaging events within a time window. 3. Complex event processing agents — detect patterns and relationships among multiple events and generate a derived (complex) event.
-
Why do you use "iostream"? Write its syntax. Also state what #include <iostream> means in C++.
Topic: Windows Programming (Win32, GDI & C++)
iostream provides basic input and output services for C++ programs. iostream uses the objects cin, cout, cerr, and clog for sending data to and from the standard streams input, output, error (unbuffered), and error (log / buffered) respectively. Syntax: #include <iostream.h> iostream stands for standard input-output stream. It is the header file which contains all the functions of the program like cout, cin, etc., and #include tells the preprocessor to include this header file in the program.
-
What is debugging, and what are its two ways?
Topic: Windows Programming (Win32, GDI & C++)
Debugging is the process of finding errors during application execution. It does not mean syntax errors, with which the application cannot be compiled, but logic errors. Logic errors can only be noticed during application execution. Ways of debugging: • Evaluate an expression with or without side effect • Enable and Disable Just My Code • Edit and Continue in XAML • Use OzCode
-
Why are breakpoints used?
Topic: Windows Programming (Win32, GDI & C++)
Breakpoints allow stopping the program during execution (at a chosen point, so that the program state can be inspected while debugging).
-
What will be the easiest way if someone wants to know whether a certain string is a number or not? Elaborate your answer with an example.
Topic: Windows Programming (Win32, GDI & C++)
Use the IsNumeric(String s) method. This method is used to find if the string is numeric or not.
-
How can I use the CopyTo method of the Windows Forms controls collection to copy controls into an array?
Topic: Windows Programming (Win32, GDI & C++)
The CopyTo method will take the current controls collection and copy all the controls into an array. In order to use it, you must specify the array and the starting point. For instance, the following code copies the controls to the MyArrayOfControls array starting at the first element.
-
How does Windows keep track of the files (modules)?
Topic: Windows Programming (Win32, GDI & C++)
The system requires instance handles to keep track of all modules. The system assigns a handle to each copy of a running executable or DLL.
-
Can you write a class without specifying a namespace? Which namespace does it belong to by default?
Topic: Windows Programming (Win32, GDI & C++)
Yes, you can, and then the class belongs to the global namespace, which has no name. For commercial products, naturally, you wouldn't want the global namespace.
-
Define instance handle. Briefly explain.
Topic: Windows Programming (Win32, GDI & C++)
An instance handle identifies an instance of a module (application instance handle). The system assigns a handle to each copy of a running executable or DLL, and the application uses this member (instance handle) to identify itself and to load its resources.
-
"In the GDI environment there are two working spaces." Name these two working spaces.
Topic: Windows Programming (Win32, GDI & C++)
In the GDI environment there are two working spaces: 1. Logical 2. Physical
-
What are macros and what are their types? Explain with an example.
Topic: Windows Programming (Win32, GDI & C++)
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros: 1. Object-like macros — they resemble data objects when used. 2. Function-like macros — they resemble function calls. To define a macro that takes arguments, you use the #define command with a list of parameters in parentheses after the name of the macro. The parameters may be any valid C identifiers separated by commas at the top level (that is, commas that aren't within parentheses) and, optionally, by white-space characters. The left parenthesis must follow the macro name immediately, with no space in between. Example: here is a macro that computes the maximum of two numeric values: #define min(X, Y) ((X) > (Y) ? (X) : (Y))
-
What is a process?
Topic: Windows Programming (Win32, GDI & C++)
A process is a series of actions or steps taken to achieve an end; it is a collection of interrelated work tasks initiated in response to an event that achieves a specific result for the customer of the process.
-
Explain pointer to constant and constant pointer.
Topic: Windows Programming (Win32, GDI & C++)
Constant pointer to variable data: char * const ptr = buff; // constant pointer to variable data *ptr = 'a'; // allowed — the data can be changed ptr = buff2; // ERROR — the pointer itself is constant Since we have declared ptr as a "constant pointer to variable data", we can change the contents of the place where ptr is pointing, i.e. the data, but being a constant, the ptr value (the address it contains) cannot be modified. Variable pointer to constant data: const char * ptr = buff; // variable pointer to constant data *ptr = 'a'; // ERROR — the data is constant ptr = buff2; // allowed — the pointer can be changed
-
What are the types of assertions? Name them.
Topic: Windows Programming (Win32, GDI & C++)
There are three types of assertion: 1. Preconditions — specify conditions at the start of a function. 2. Postconditions — specify conditions at the end of a function. 3. Invariants — specify conditions over a defined region of a program.
-
Define client area.
Topic: Windows Programming (Win32, GDI & C++)
The client area is the part of a window where the application displays output, such as text or graphics. For example, a desktop publishing application displays the current page of a document in the client area. The application must provide a function, called a window procedure, to process input to the window and display output in the client area.
-
Describe WinMain in detail.
Topic: Windows Programming (Win32, GDI & C++)
WinMain is the starting point in every Win32 GUI program. WinMain has four parameters: 1. The first is the instance handle of the current application. 2. The second parameter is also an instance handle of this application, which is used for the previous instance of the same application that is already running. It is used only in 16-bit editions of Windows (Windows 3.1); 32-bit editions do not support this parameter — it is here just for compatibility. 3. The third parameter is a command line argument of string type, defined as char *. 4. The fourth parameter is the window style (how the window is to be shown initially).
-
Write a note on the message queues of each application.
Topic: Windows Programming (Win32, GDI & C++)
An application must remove and process messages posted to the message queues of its threads.
-
Differentiate between a desktop window and an application window.
Topic: Windows Programming (Win32, GDI & C++)
Desktop Window: When you start the system, it automatically creates the desktop window. The desktop window is a system-defined window. It uses a bitmap to paint the background of the screen. A system configuration application, such as a Control Panel item, changes the desktop wallpaper by using the SystemParametersInfo function. Application Window: When you start an application, the system also associates a taskbar button with the application. The taskbar button contains the program icon and title. Most applications also create other windows, either directly or indirectly, to perform tasks related to the main window. An application window includes elements such as a title bar, a menu bar, the window menu (formerly known as the system menu), etc.
-
Show the implementation of the _cdecl calling convention with respect to: (1) argument passing order, (2) stack maintenance responsibility, (3) name decoration convention.
Topic: Windows Programming (Win32, GDI & C++)
The _cdecl calling convention is described with respect to these three points: 1. Argument passing order. 2. Stack maintenance responsibility. 3. Name decoration convention.
-
Write a note on the _cdecl calling convention.
Topic: Windows Programming (Win32, GDI & C++)
The cdecl is the default calling convention for C programs. In this calling convention, the stack is cleaned up by the caller. The cdecl calling convention creates larger executables than stdcall, because it requires each function call to include stack cleanup code.
-
What is the difference between the stdcall and cdecl calling conventions?
Topic: Windows Programming (Win32, GDI & C++)
cdecl and stdcall just tell the compiler whether the called function or the calling function cleans up the stack. In the stdcall calling convention, the called function cleans up the stack when it is about to return, so if it is called in a bunch of different places, all of those calls do not need extra code to clean up the stack after the function call. In the cdecl calling convention, it is the caller function that is responsible for cleaning the stack, so every function call must also include extra code to clean up the stack after the function call.
-
"A window may have more than one window inside it." Explain this line.
Topic: Windows Programming (Win32, GDI & C++)
A window may further contain more windows inside it. For example, let's take a calculator: a calculator contains more windows in the form of buttons, radio buttons and check boxes. • Every window has its parent and zero or more siblings. • A top-level window has the desktop as its parent.
-
What is the function of WM_PAINT in a window class?
Topic: Windows Programming (Win32, GDI & C++)
The DispatchMessage function dispatches a message to a window procedure when the application obtains a WM_PAINT message from the message queue by using the GetMessage or PeekMessage functions.
-
What are the kernel tasks?
Topic: Windows Programming (Win32, GDI & C++)
The kernel is the main module of the operating system. It provides system services for managing threads, memory, and resources. The kernel has to perform very important responsibilities, e.g.: 1. Process Management 2. File Management 3. Memory Management (system and virtual memory)
-
Explain the erase window (background erase) function.
Topic: Windows Programming (Win32, GDI & C++)
Erase window uses the GetClipBox function to retrieve the logical coordinates of the area to erase and passes these coordinates to the FillRect function. Applications that process these messages can use similar techniques. The system supplies a window device context with the WM_ICONERASEBKGND message regardless of whether the corresponding window has a private device context.
-
Explain the working of the clipboard.
Topic: Windows Programming (Win32, GDI & C++)
In Windows, data is shareable among applications. We can use it for copying the data from one file to the other in the same format, e.g. from Notepad to MS Word. All the text or image data you have previously copied can now be pasted in another application.
-
What is a stack?
Topic: Windows Programming (Win32, GDI & C++)
In computer science, a stack is an area of memory that holds all local variables and parameters used by any function, and remembers the order in which functions are called so that function returns occur correctly.
-
What is the extern storage class?
Topic: Windows Programming (Win32, GDI & C++)
Extern defines a global variable that is visible to all object modules. When you use 'extern', the variable cannot be initialized, as all it does is to point the variable name at a storage location that has been previously defined.
-
An application can set up for itself any logical coordinate system using an API. Write down any two.
Topic: Windows Programming (Win32, GDI & C++)
Logical coordinate systems (mapping modes) are set with the SetMapMode API. Any two of them are: 1. MM_TEXT — each logical unit is mapped to one device pixel; x increases to the right and y increases downwards. 2. MM_ISOTROPIC — logical units are mapped to arbitrary units with equally scaled axes, so one unit in x equals one unit in y (used for drawing that must keep its aspect ratio). Other mapping modes include MM_LOMETRIC, MM_HIMETRIC, MM_LOENGLISH, MM_HIENGLISH, MM_TWIPS and MM_ANISOTROPIC.
-
Differentiate between superclassing and subclassing.
Topic: Windows Programming (Win32, GDI & C++)
Superclassing: Superclassing defines a class that adds new functionality to a predefined window class, e.g. Button or ListBox controls. Superclassing involves creating a new class that uses the window procedure of an existing class for basic functionality. Subclassing: Subclassing is allowed only within a process. Win32 processes have separate address spaces, so an application cannot subclass a window or class that belongs to another process.
-
Why are the entries in the parent process table and the child process table the same?
Topic: Windows Programming (Win32, GDI & C++)
It means that the handle value that identifies a kernel object is identical in both the parent and the child processes.
-
What is bytecode in Java?
Topic: Mixed / Other Important Questions
Java bytecode is the instruction set for the Java Virtual Machine. It acts similar to an assembler, which is an alias representation of C++ code. As soon as a Java program is compiled, Java bytecode is generated. In more apt terms, Java bytecode is the machine code in the form of a .class file.
-
Can BAML be decompiled back into XAML? Explain with a valid reason.
Topic: WPF & XAML Basics
Yes, BAML can be converted back into XAML. BAML (Binary Application Markup Language) is just a compressed, binary representation of XAML, and a BAML reader is available, so the binary markup can be read and decompiled back into the original XAML form.
-
Which provides multi-touch support, WPF3 or WPF4?
Topic: WPF & XAML Basics
WPF 4.0 includes multi-touch support. WPF 3 did not provide multi-touch; support for multi-touch input was added in WPF 4.
-
Name the three types of row-definition and column-definition sizing that are supported by the WPF "Grid" panel.
Topic: Layout, Panels, Transforms & Animation
1. Absolute sizing: size is fixed in device-independent pixels; the row/column does not grow or shrink. 2. Auto sizing: the row/column sizes itself to fit its content. 3. Proportional (Star) sizing: the row/column grows or shrinks proportionally to take its share of the remaining space.
-
How can we know which cells are directly affected by the resizing of GridSplitters?
Topic: Layout, Panels, Transforms & Animation
It depends on the GridSplitter's alignment values. By default, HorizontalAlignment is Right and VerticalAlignment is Stretch. When all rows/columns are proportionally sized, resizing changes the coefficients (proportions) accordingly. When absolute sizing is used, only the top or left cells change; the remaining cells are pushed down or right.
-
Write code to delete a non-empty cell.
Topic: Mixed / Other Important Questions
The contents of a non-empty cell can be deleted by setting its value to an empty string: { cell.Value = string.Empty }