21
Page 1 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2 BSc (Hons) Software Engineering BSc (Hons) Computer Science with Network Security & BSc.(Hons) Business Information Systems Cohort: BSE/11/FT, BCNS/11/FT, BIS11/FT Examinations for 2012 2013 / Semester 2 MODULE : Visual Programming MODULE CODE: PROG 2104C Duration : 2 Hours & 30 Minutes Reading Time : 10 Minutes Instructions to Candidates: 1. This question paper consists of three sections: Section A, Section B and Section C. 2. Section A is compulsory . 3. Answer two questions from Section B or two questions for Section C. 4. Questions from section B should be answered using VB.Net only and questions from section C should be answered using C#.Net only. 5. Total marks 100. This question paper contains 7 questions and 21 pages.

BSc (Hons) Software Engineering BSc (Hons) Computer ...Write VB.Net codes to implement the interface which displays a message box when the user clicks on the ‘Build Pizza’ button

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

  • Page 1 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    BSc (Hons) Software Engineering

    BSc (Hons) Computer Science with Network

    Security & BSc.(Hons) Business Information

    Systems

    Cohort: BSE/11/FT, BCNS/11/FT, BIS11/FT

    Examinations for 2012 – 2013 / Semester 2

    MODULE : Visual Programming MODULE CODE: PROG 2104C Duration : 2 Hours & 30 Minutes Reading Time : 10 Minutes

    Instructions to Candidates: 1. This question paper consists of three sections: Section A, Section B and

    Section C.

    2. Section A is compulsory.

    3. Answer two questions from Section B or two questions for Section C.

    4. Questions from section B should be answered using VB.Net only and

    questions from section C should be answered using C#.Net only.

    5. Total marks 100.

    This question paper contains 7 questions and 21 pages.

  • Page 2 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    SECTION A (Compulsory)

    QUESTION 1: (40 MARKS)

    a) The Norman’s design guideline applied to user interface design of computer

    applications consist of six principles.

    i. With the help of examples, and using diagrams where necessary,

    describe the six normal design principles

    (12 marks)

    ii. The two figures below represents specific screen from windows

    applications and have bad user interface design. Identify and describe

    the main user interface problem(s), and also propose a solution for

    each.

    (4 marks)

    Figure 1(a): An Error Message in a Message Box

    Figure 1(b): A Form that captures banking details

  • Page 3 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    b) Windows applications usually provide menus containing commands and

    options, giving the user the ability to perform various tasks related to the

    application. Consider the following menu, and answer the questions which

    follow.

    Figure 1(c): File Menu

    i. Explain how you can use the menu strip control to create the menu in

    figure 1(c) above.

    (3 marks)

    ii. How are you going the assign the shortcut property to each strip item?

    (2 marks)

    iii. Explain how you will assign a click event on the Exit menu strip item.

    (2 marks)

    c) The .NET Framework is a managed, type-safe environment for application

    development and execution. It manages all aspects of program execution and

    consists of two main components: the Common Language Runtime (CLR)

    and the Base Class library (BCL). Briefly describe each component.

    (4 marks)

    d) The namespaces in the .NET base class library are organized hierarchically.

    i. What is the root namespace of the .NET Framework?

    (1 mark)

  • Page 4 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    ii. What is the purpose of the namespace concept in the .NET

    Framework?

    (2 marks)

    e) ADO.NET is the primary data access API for the .NET framework. It provides

    classes necessary to develop database applications based on the

    disconnected data access model.

    i. Explain the disconnected data access model with reference to the two

    main problems linked with the connected access model.

    (2 marks)

    ii. With the help of a diagram, explain the role of the DataSet and the

    Data Provider components in the ADO.NET architecture.

    (5 marks)

    iii. Describe the command object with the help of an example.

    (3 marks)

  • Page 5 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    SECTION B

    (Answer any two questions using VB.NET)

    QUESTION 2: (30 MARKS)

    a) A bank has 4 types of accounts with annual interests rates as follows:

    1. Savings 8%

    2. Savings with cheque book 5%

    3. Current 4%

    4. Fixed deposits 10%

    Write a VB.net program that allows the input of the current balance in textbox,

    txtBalance and input type of account in textbox, txtAccount and displays the total

    interest obtainable in label lblOutput, when the button, btnCalculate is clicked.

    You have to make use of the Select statement. Ensure that the following

    validations occur:

    (Total 10 marks for part (a))

    I. The textboxes should not be left empty.

    II. Balance should be numeric and positive.

    III. Account type should be in the appropriate range.

    Provide appropriate error messages if the above conditions are not met.

  • Page 6 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 2 a) (i)

    Fig 2 a) (ii)

  • Page 7 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 2 a) (iii)

    Fig 2 a) (iv)

    b) The Screenshot below shows part of a Pizza Order application

  • Page 8 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 2 b)

    Write VB.Net codes to implement the interface which displays a message box

    when the user clicks on the ‘Build Pizza’ button.

    (10 marks)

    b) You are provided with the following screenshot of a media player application with

    a progress bar control at the bottom. When the Start button is clicked the

    Progress bar starts, the Play button of the player becomes visible.

    (i) What is the purpose of this control? What are three important parameters of

    the Progress Bar control? (4 marks)

    (ii) Explain fully with the necessary VB.Net codes how you would implement

    this progress bar when the Start Button is clicked. (6 marks)

  • Page 9 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 2 c) (i)

    Fig 2 c) (ii)

    Fig 2 c) (iii)

    (3 marks)

  • Page 10 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Question 3 (30 Marks)

    Below are three screenshots of a small application to display the details of a

    collection of songs. It consists of the Title, artist, format, duration (in minutes and

    seconds), year it was released, and the category. All the details are stored in a

    database named ‘Music_Collection’. The application consists of three forms,

    containing the following controls: buttons, labels, list box and text boxes.

    Depending on the choice of the user (Fig 3.1), it can either retrieve all the records

    from the database and display all of them at one go in a data grid (Fig 3.1) or

    display the record one by one (Fig 3.3).

    The form named ‘Form3’ contains a datagrid to display data from a table name

    Songs in the database mentioned above.The data is loaded only when the ‘Load

    data’ button is pressed. The data in the database can be updated via the ‘Update

    DB’ button (Fig 3.2)

    Fig 3.1

  • Page 11 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 3.2

    Fig 3.3

    You are required to write VB.NET codes for the following functionalities:

    a) To declare class level variables to connect to the database

    (3 marks)

    b) To show all records in the datagrid at one go by clicking the ‘Load data’ button

    – (8 marks)

    c) To display the record one by one in a form called MusicList (Fig 3.3)

    (8 marks)

  • Page 12 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    d) To update the underlying database via the datagrid by clicking the ‘Update

    DB’ button. The code should display a message indicating the number of

    records changed in the database. (9 marks)

    e) To close the application by clicking the ‘Exit’ button

    (2 marks)

    Question 4 (30 Marks)

    Below are six screenshots of a small application to display the details of a collection

    of songs. It consists of the Title, artist, format, duration (in minutes and seconds),

    year it was released, category and a path to an image file representing the picture of

    the artist. All the details are stored in plain text file: MusicCollection_tab_image.txt

    (Fig 4.1). The application consists of three forms, containing the following controls:

    buttons, labels, list box and text boxes. Depending on the choice of the user (Fig

    4.2), it can either retrieve all the records from the text file and display all of them at

    one go in a list box (Fig 4.3) or display the record one by one along with the picture

    which it extracts from the path name(Fig 4.5).

    Write VB.Net codes for the following:

    (i) Appropriate global variables (3 marks)

    (ii) Opening an appropriate stream reader to the text file (2 marks)

    (iii) To read line by line till the end of the text file (2 mark)

    (iv) Break each individual line into corresponding words (fields of the records)

    (2 mark)

    (v) For a clear button to clear all fields (2 marks)

    (vi) For closing the stream reader (1 mark)

    (vii) For the Exit button (1 mark)

    (viii) For a sub procedure called ‘DisplayRecord()’ which will display one record at

    a time like in Fig 4.5 below. (13 marks)

    (ix) For the Last Button (4 marks)

  • Page 13 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 4.1

    Fig 4.2

    Fig 4.3

  • Page 14 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Fig 4.4

    Fig 4.5

    Fig 4.6

  • Page 15 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    SECTION C

    (Answer any two questions using C#.NET)

    QUESTION 5: (30 MARKS)

    You have been given the form below (Figure 5), with part of the implementation

    details. The application demonstrates how to use C# arithmetic operators on integer

    values and also shown in figure 5 are the names of the controls specified between

    brackets, except for the radio buttons which are described below.

    Figure 5: Maths Operator Form Design

    RadioButtons description:

    A groupbox control is used to group 5 different radio buttons, with the following

    names: addition, subtraction, multiplication, division and remainder.

    If the addition radio button is checked, and the user clicks on calculate button, the

    value of the left operand is added to that to the right operand. In all cases, the left

    operator is either added to (+), or subtracted from (-), or multiplied to (*), or divided -

    normal division (/) or remainder/modular division (%) - by the right operator. The

    result of the expression is displayed in the result textbox, and the expression in the

    expression textbox.

  • Page 16 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    Consider the code fragment below, which shows the implementation of calculate

    button click event:

    1. private void calculate_Click(object sender, System.EventArgs e) 2. { 3. int leftHandSide = Int32.Parse(leftHandSideOperand.Text); 4. int rightHandSide = Int32.Parse(rightHandSideOperand.Text); 5. int answer = doCalculation(leftHandSide, rightHandSide); 6. result.Text = answer.ToString(); 7. }

    Code Listing 1: Implementation of calculate_Click

    a) Explain the codes at line 3 and 4 in code listing 1 above.

    (2 marks)

    b) Write complete C# code for the implementation of the ‘doCalculation’ method

    shown in the code listing 1 above. (Provide an implementation for all the

    arithmetic operators on the form, as well as the display of the expression in

    the expression textbox.)

    (12 marks)

    c) Briefly explain what each segment of a Try...Catch...Finally

    (try...catch...finally) block does.

    (3 marks)

    d) If you catch IndexOutOfRangeException and Exception in two different

    handlers, which one will run first, or will both be executed?

    (3 marks)

    e) There are several possible error conditions that can occur in the code

    described in listing 1 above. Describe two possible error conditions, and write

    try-catch blocks to handle each.

    (2 x 5 marks)

  • Page 17 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    QUESTION 6: (30 MARKS)

    a) In the context of database access in C#.NET, explain the following methods:

    i. The Open() method

    ii. The Close() method (2 marks)

    b) Consider the form below ‘Student Application’ in figure 6 below, which accesses

    two tables, namely, Application and Courses, from an MS SQL Server database,

    named university.mdb. The table Application consists of the following fields:

    student_id (int, auto-increment, not null), firstname (text, null), lastname(text,

    null), phone(text, null), address(text, null), dob (text, null), course_A(text, null),

    course_B(text, null), course_C(text, null). The table Courses consists of the

    following fields: course_id(int, auto-increment, not null), course_name(text, null)

    and course description(text, null). Answer the questions which follow. Clearly

    mark any assumptions that you make where necessary.

    Figure 6: Student Application Form

    Button:

    btn_select

    Button:

    btn_returnOne Button:

    btn_returnAll

    ListBox:

    lb_selected

    ListBox:

    lb_available

  • Page 18 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    i. Write the code to load all course names in the listbox ‘lb_available’,

    when the form loads. Use the sql authentication with username set to

    ‘myUni’ and password ‘myUni25’ from the database server named

    ‘DBServer’. Use an appropriate try-catch statement for in your code.

    (8 marks)

    ii. Write the code for the following button click events, which allow the

    applicant to select only three courses from listbox lb_available and add

    them to lb_selected.

    (10 marks)

    private void btn_Select_Click(object sender, EventArgs e) {

    }

    private void btn_ReturnOne_Click(object sender, EventArgs e) {

    }

    private void btn_ReturnAll_Click(object sender, EventArgs e) {

    … }

    iii. Write the code to save the application made, in the table application,

    when the button save is clicked. Note that the selected course names

    are stored in fields: course_A, course_B, course_C. Use an

    appropriate try-catch statement for in your code.

    (10 marks)

  • Page 19 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    QUESTION 7: (30 MARKS)

    a) In the context of a file access in C#.NET, explain the following components:

    i. openFileDialog dialog.

    ii. StreamReader Class.

    (4 marks)

    b) Consider the form, figure 7, ‘Add Student Marks’ below, with annotations for

    all main controls. It records basic student personal details and their marks

    obtained in the module Visual Programming. The lecturer inserts the student’s

    personal details, together with a photo of the student and the marks obtained

    in the module. The total mark for the module is computed from two

    assignments of 50 marks each, which accounts for 40% of the total module

    and the examination has a total of 100 marks and accounts for 60%. Answer

    the questions which follow and clearly mark any assumptions that you make.

    Figure 7: Add Student Marks form

  • Page 20 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    i. Complete the code below, which loads the batches (BSE/11/FT,

    BCNS/10B/FT, BCNS/11/FT) in the combo box cboBatch.

    private void FormAddMarks_Load(object sender, EventArgs e) {

    }

    (3 marks)

    ii. Complete the code below, for the two methods shown below

    btnAddPhoto_Click and openImageFileDialog_FileOk. The first

    method loads an open form dialog, named openImageFileDialog to

    select the picture of the student, and the second method is to display

    the photo after it has been selected.

    private void btnAddPhoto_Click (object sender, EventArgs e) { … }

    private void openImageFileDialog_FileOk(object sender, CancelEventArgs e) { …

    }

    (5 marks)

    iii. Complete the code below, which calculates the total marks for the

    student, combining the both assignments and the examination marks.

    Note that total marks cannot exceed 100%, since both assignments

    accounts for 40% and examination accounts for 60%. Use an

    appropriate try-catch statement.

    private void btnTotal_Click(object sender, EventArgs e)

    { …

    }

    (5 marks)

  • Page 21 of 21 Visual Programming (PROG21043C) SITE/DA 2012-2013 S2

    iv. When the all the details have been inserted and the total marks

    computed, clicking on the save button loads a save dialog named

    saveFileDialog. The lecturer selects the text file to save all the student

    details and clicks on save in the dialog box. Complete the code below,

    so as to load the save dialog box and write all details in text file.

    private void btn_save_Click(object sender, EventArgs e) {

    … }

    (8 marks)

    c) As a future update to the application, the lecturer has asked you to remove

    the calculate button, and find a way to automatically load the total marks in

    the textbox txtTotal. Explain how you will proceed, you may provide an

    algorithm in pseudocode.

    (5 marks)

    ***END OF QUESTION PAPER***