PROGRAMMING WITH .NET FRAMEWORK

PROGRAMMING WITH .NET FRAMEWORK

INSTRUCTIONS: Answer QUESTION ONE and ANY OTHER TWO.

QUESTION ONE (30 MARKS)

  1. Briefly describe the following terms as used in VB.net giving declaration and examples

(5 marks)

  1. Implicit declaration
  • Implicit declaration is a variable with no type. It’s not declared as a string, integer, double, or anything e.g. Dim x
  1. Method

 

  • The methods can be thought of a behaviour
  • The methods can be defined as required to behave meaning do some task.
  • Methods perform actions

 

  • Property
  • Properties can be seen as the characters of the objects
  • Properties can be set with valid values bounding to the limits
  • Properties represent data,
  1. Explicit declaration
  • Explicit is a variable with type e.g. Dim x as integer
  1. Module
  • A complete Visual Basic application is typically contained in a single project. Within a project, code is placed in separate code files called modules, and within each module, the Visual Basic code is further separated into self contained and re-usable procedures
  1. Elucidate four responsibilities of the Common Language Runtime          (4 Marks)
  • Responsible for managing the execution of all applications developed using the .NET library. The runtime works as an agent that manages code at execution time, providing core services such as memory management, thread management, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code
  1. Describe the role of ReDim keyword as used in dynamic arrays with a code snippet.

(4 Marks)

  • ReDim keyword is exclusively used for arrays and it is used to change the size of one or more dimensions of an array that has been already declared. ReDim can free up or add elements to an array whenever required.

Example:

  • Dim intArray(7, 7) As Integer
  • ReDim Preserve intArray(7, 8)
  • ReDim intArray(7, 7)
  1. Differentiate between Option Strict and Option Explicit (2 Marks)
  • .Net generally allows implicit conversion of any data types. In order to avoid data loss during data type conversion, Option Strict keyword is used and it ensures compile time notification of these types of conversions.
  • Option Explicit is the keyword used in a file to explicitly declare all variables using declare keywords like Dim, Private, Public or Protected. If undeclared variable name persists, an error occurs at compile time.
  1. Mention 4 features of programming in Vb.Net (4marks)

 

  1. Data Access in ADO.NET relies on DataSet and Data Provider as components, distinguish them.                                                                                                            (4 Marks)

 

 

  • DataSet

The dataset is a disconnected, in-memory representation of data. It can be

considered as a local copy of the relevant portions of the database. The DataSet is

persisted in memory and the data in it can be manipulated and updated independent

of the database. When the use of this DataSet is finished, changes can be made back

to the central database for updating. The data in DataSet can be loaded from any

valid data source like Microsoft SQL server database, an Oracle database or from a

Microsoft Access database.

  • Data Provider

The Data Provider is responsible for providing and maintaining the connection to the

database. A DataProvider is a set of related components that work together to

provide data in an efficient and performance driven manner.

The .NET Framework currently comes with two DataProviders: the SQL Data Provider

which is designed only to work with Microsoft’s SQL Server 7.0 or later and the

OleDb DataProvider which allows us to connect to other types of databases like

Access and Oracle. Each DataProvider consists of the following component classes:

The Connection object which provides a connection to the database

The Command object which is used to execute a command

The DataReader object which provides a forward-only, read only, connected

recordset

The DataAdapter object which populates a disconnected DataSet with data and

performs update

 

  1. Explain the for…Next loop and include a syntax (4 Marks)
  • The FOR NEXT Loop , execute the loop body (the source code within For ..Next code block) to a fixed number of times.
  • Syntax:

For var=[startValue] To [endValue] [Step]

   [loopBody]

Next [var]

Example:

 

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object,

      ByVal e As System.EventArgs) Handles Button1.Click

        Dim var As Integer

        Dim startVal As Integer

        Dim endVal As Integer

        startVal = 1

        endVal = 5

        For var = startVal To endVal

            MsgBox(“Message Box Shows ” &   var &   ” Times “)

        Next var

    End Sub

End Class

  1. Outline any three techniques of error trapping in visual basic.Net                (3 marks)
  • On Error Goto label
    • Where label is the section of code that is designed by the programmer to handle the error committed by the user. Once the program detects an error, the program will jump to the label section for error handling.
  • On Error Resume Next
    • With the old On Error…Resume [Next] trapping was that you could get into an infinite loop with the trap if your code continuousely generated the same error. For example, if you have an open connection when an error occurs, then the connection is closed, you may encounter an error from that connection being closed that you did not realise until it’s too late.
  • On Error Goto 0
    • Disables enabled error handler in the current procedure and resets it to Nothing.
  • Try…Catch
    Try Statement that consists of a Try block, Catch block, and a Finally block. The Try block must be followed by either a Catch block or a Finally block. The Finally block is optional but is useful in returning resources to the system in the event of, for example, you opened a file to read in the try block before the error occurred.

Syntax:

Try

statements

Catch exception_variable as Exception

statements to deal with exceptions

End Try

QUESTION TWO (20 MARKS)

  1. Briefly write short notes on CLR, CTS and CLS as used in vb.net.             (6 Marks)
  2. CLR

 

  • CLR = Common Language Runtime. The CLR is a set of standard resources that (in theory) any .NET program can take advantage of, regardless of programming language. CTS
  1. CTS
  • CTS = Common Type System. This is the range of types that the .NET runtime understands, and therefore that .NET applications can use. However note that not all .NET languages will support all the types in the CTS. The CTS is a superset of the CLS. 
  • CLS
  • CLS = Common Language Specification. This is a subset of the CTS which all .NET languages are expected to support. The idea is that any program which uses CLS-compliant types can interoperate with any .NET program written in any language.

  1. Describe three types of code modules supported by visual Basic.Net         (6 mark)

Form Modules, 

  • A simple application may contain a single Form, and the code resides in that Form module itself.

Standard Modules

  • As the application grows, additional Forms are added and there may be a common code to be executed in several Forms. To avoid the duplication of code, a separate module containing a procedure is created that implements the common code. This is a standard Module.

Class Modules.

  • Class module (.CLS filename extension) are the foundation of the object oriented programming in Visual Basic. New objects can be created by writing code in class modules. Each module can contain: Declarations:  May include constant, type, variable and DLL procedure declarations. Procedures:  A sub function, or property procedure that contain pieces of code that can be executed as a unit.
  1. Write a Visual Basic.Net application that computes the surface area of a cylinder. The radius and height of the cylinder should be provided by the user via input boxes and the area is communicated to user via a message box. Use the formula: Area=2 πrh +2 πr2. (8 Marks)

Public Class SurfaceAreaCalculator

    Public Function calcSurfaceArea(ByVal r As Double, ByVal h As Double)

        Const Pi As Double = 3.14159265

        ‘ r = radius, h = height

        Return 2 * (Pi * r ^ 2) + (2 * Pi * r) * h

 

    End Function

 

End Class

 

 

Public Class WebForm1

    Inherits System.Web.UI.Page

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ‘Put user code to initialize the page here

        If not IsPostBack Then

            Session(“SurfaceAreaClass”) = New SurfaceAreaCalculator

        End If

    End Sub

 

    Private Sub butcalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butcalculate.Click

        Dim SurfaceArea as SerfaceAreaCalculator = Session(“SurfaceAreaClass”)

        Me.txtanswer.Text = SurfaceArea.calcSurfaceArea(Put something in here)

QUESTION THREE (20 MARKS)

  1. JIT is termed as Just in Time compiler which is used as a part of runtime execution environment. Explain the three types of JIT.         (6 Marks)

 

  • Pre-JIT – Compiles at the time of deployment of an application
  • Econo-JIT – Compiles called methods at runtime
  • Normal JIT – Compiles called methods at runtime and they get compiled first time when called 
  1. A program is required to process and award students grades for students in a class according to the following summary table.
Marks% Comment
70 – 100 Excellent
60 – 69 Good
40 – 59 Average
Below 40 Below Average

Write a VB.Net program that prompts the user for the student’s marks and outputs the appropriate grade using switch selection statement. The default option should print an error message “Invalid Marks, Try Again”                                                           (8 marks)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click

‘Examination Marks

Dim mark As Single

mark = mrk.Text

Select Case mark

Case 0 to 49

Label1.Text = “Below Average ”

Case 40 to 59

Label2.Text = “Average”

Case 60 to 69

Label3.Text= “Good”

Case 70 to 100

Label4.Text = ” Excellence ”

Case Else

Label5.Text= ” Invalid Marks, Try Again ”

End Select

End Sub

  1. List and clearly describe 3 looping techniques used in Visual Basic              (4marks)

Decision structures

  1. if else:

Syntax:

If condition1 Then

statements executed if condition1 is True

ElseIfcondition2Then

statements executed if condition2 is True

[Additional ElseIf conditions and statements can be placed here]

Else

statements executed if none of the conditions is True

End If

  1. switch

The syntax:

Select Case variable

    Case value1

statements executed if value1 matches variable

    Case value2

statements executed if value2 matches variable

    Case value3

statements executed if value3 matches variable

    …

    Case Else

statements executed if no match is found

End Select

Repetition structures :

  1. Do Loop ….While condition

The syntax:

Do while condition

block of statements to be executed

Loop

  1. Do ….Until condition Loop

 

 

  • For….Next Loop

The syntax:

For variable = start To end

statements to be repeated

Next [variable]

  1. Do…. While condition

The syntax:

Do while condition

block of statements to be executed

Loop

 

  1. Expound the importance of simulation and modelling in programming (2marks)
  • Advancements in computing power, availability of PC-based modeling and simulation, and efficient computational methodology are allowing leading-edge of prescriptive simulation modeling such as optimization to pursue investigations in systems analysis, design, and control processes that were previously beyond reach of the modelers and decision makers.

QUESTION FOUR (20 MARKS)

  1. What to you understand by the term data type as used in Vb.Net? Distinguish between numeric and non-numeric data types with examples (5 marks)
  • Data type used to define the type of data and storage size of variables
  • Numeric data types are types of data that consist of numbers, which you can compute them mathematically with various standard operators such as add, minus, multiply e.g. Byte, integer, long, single, double, decimal, currency.
  • Nonnumeric data types are data that cannot be manipulated mathematically using standard arithmetic operators. The non-numeric data comprises text or string data types, the Date data types, the Boolean data types that store only two values (true or false), Object data type and Variant data type

 

  1. Analyse any five components that make up the visual studio Integrated Development environment                                                                                                 (10 Marks)
  • The tool box
  • The solution explorer
  • Properties window
  • Project properties window
  • The standard tool bar
  • The error list window
  • Object browser
  • Team exploreretc
  • Toolbox
  • The Toolbox is a palette of developer objects, or controls, that are placed on forms or web pages, and then code is added to allow the user to interact with them. An example would be TextBox, Button and ListBox controls. With these three controls added to a Windows Form object the developer could write code that would take text, input by the application user, and add it to the ListBox when the button is clicked.
  • Solution Explorer
  • This is a section that is used to view and modify the contents of the project. A Visual Studio Windows Application Project will generally have a Form object with a code page, references to System components and possibly other modules with special code that is used by the application.
  • Properties Windows
  • The properties windows shows all the control (like TextBox) properties to be changed at design time. Most of these properties can be also changed with code at run time, but basically most properties change the way the control is displayed on your application.
  • Code / Design view
  • This is where the magic takes place. Forms are designed graphically. In other words, the developer has a form on the screen that can be sized and modified to look the way it will be displayed to the application users. Controls are added to the form from the Toolbox, the color and caption can be changed along with many other items.
  • Object Browser
  • By pressing F2 or selecting it into the View menu, it’s possible to explore all the available objects of the libraries (types, functions…).

NB:(State any 5 and explain award 2 marks each)

  1. Explain the term operator and list any 4 type showing their examples.             (5marks)

Operator is an expression used to manipulate other expressions and values

  • Arithmetic Operators
  • Comparison Operators
  • Logical/Bitwise Operators
  • Bit Shift Operators
  • Assignment Operators
  • Miscellaneous Operators
(Visited 353 times, 1 visits today)
Share this:

Written by