Arab Academy For Science and Technology & Maritime Transport
College of Engineering & Technology
Computer Engineering Department
EXAMINATION PAPER – Week 7
Course Title: Introduction to Programming
Course Code: CC114
Date: Thurs. May, 7-2015Lecturer: Dr. Manal Helal
Time allowed: 60 minsStart Time: 11:00 a.m.
Student's name: / Reg.#:Question # / Marks
Available / Actual
Visual Controls / 5
Variables & Data Types / 5
Algorithms / 5
Conditional Statements / 5
Total / 20
Lecturer / Name: Dr. Manal Helal
Signature:
Date:
ALL MCQ are worth 1 mark each.
MPC6/1-1
Visual Controls[5 points]
1. Theto ______allows you to set object properties visually, without writing code
a)Toolboxb)Properties window
c)Solution Explorer d)Form
e) None of the above.
2.The text on a Button’s face can be set using the ______property.
a)Captionb)Label
c)Named)Texte) None of the above.
3. Use the ______to align controls that you place on the Form.
a) Format propertyb) Toolbox c) Align property
d) TextAlign propertye) Format menu
4. The variable name to refer to a Textbox control in your code can be set using the ______property.
a) Captionb) Labelc) Name
d) Texte) None of the above.
5) The ______is used to set the name of the Form object.
a) Toolbox Windowb) Solution Explorer c) TextAlign property
d) Name property
Variables & Data Types[5 points]
6) In Visual Basic, all ______must be declared, or announced to the compiler via program code
a)keywordsb)modifiers
c)built-in data typesd)variables
e) Both c. and d.
7) What is the value returned by the following Val function call?
Val("-345 six 7")
a)-34567b) 34567
c)345d)-345e) 0
8) If your program requires numeric data with values that don’t contain fractions, which data types you can use for variable declaration:
a) Integerb) doublec) byte
d) decimale) All of the Above
9) Trace the following code to write the value stored in the g variable:
[2 points]
Dim a, b, c, d, e, g AsDouble
a = 8.0
b = 3.0
c = 4.0
d = 2.0
e = 1.0
g = a - b + c / d * e
Algorithms[5 points]
10) Given a triangle as shown in figure, Pythagorean Theorem states that the side BC2 = AB2 + AC2. Write code to take the length of AB, and AC from the user and the length of BC. [2.5 points]
11) Area of a Parallelogramis defined to be the product of base and the height. The following snippet of code calculates the area of a parallelogram. There are 3 syntax errors. Identify and fix the errors.
[2.5 points]
Dimbase, height, areaAsInteger
base = Val(baseTextBox)
height = heightTextBox
area = base * height
areaTextBox = area
Conditional Statements[5 points]
12) Discuss when to use nested If statements, or ElseIF, or Select Case statements. [2 points]
13) Trace the following code to find out what will be displayed in resTextBox. [1 points]
Dim number AsInteger = 7
SelectCase number
Case 1 To 5
resTextBox.Text = "Between 1 and 5, inclusive"
CaseIs <= 8
resTextBox.Text = "Between 6 and 8, inclusive"
Case 9 To 10
resTextBox.Text = "Equal to 9 or 10"
Case Else
resTextBox.Text = "Not between 1 and 10, inclusive"
End Select
14) Given an interface as shown in the figure, write code to decide if the user likes all three hobbies, which 2 combinations of them, which 1 of them, or none. Display the result in a Message Box as shown.
Hint: use Boolean checked property to test if a checkbox is selected or not.
[2 points]
Answers:
1) b. 2) d. 3) e. 4) c 5) d 6) d 7) d, 8) a, c, 9) g = 7
10)any correct code including:
Dim AB, AC, BC As Single
AB = Val(Txt_AB.Text)
AC = Val(Txt_AC.Text)
BC = Val(Txt_BC.Text)
If AB > 0 And AC > 0 Then
BC = Sqr(AB ^ 2 + AC ^ 2)
Txt_BC.Text = Round(BC, 2)
ElseIf AB > 0 And BC > 0 Then
AC = Sqr(BC ^ 2 - AB ^ 2)
Txt_AC.Text = Round(AC, 2)
ElseIf AC > 0 And BC > 0 Then
AB = Sqr(BC ^ 2 - AC ^ 2)
Txt_AB.Text = Round(AB, 2)
End If
11) Syntax Errors:
1) base = Val(baseTextBox.Text)
2) height = Val(heightTextBox.Text)
3) areaTextBox.Text = area.toString
12) If statements are used to decide whether to run the code one time or not based on an evaluation of a condition. Else statements are optional, and only one is allowed per If statement. Elseif provides an alternative condition to test when the preceding if (or Elseif) condition is evaluated to false. Nested If statements provide further decisions when an outer If statement condition (or ElseIf or Else) is evaluated to true. Select case statements are used when you are testing values or ranges of values to only one variable or expression.
13) Between 6 and 8, inclusive
14)
If Check1.CheckedAnd Check2.CheckedAnd Check3.CheckedThen
MsgBox ("You like Reading, Computer and Sports")
ElseIf Check1.CheckedAnd Check2.CheckedThen
MsgBox ("You like Reading and Computer")
ElseIf Check1.CheckedAnd Check3.CheckedThen
MsgBox ("You like Reading and Sports")
ElseIf Check2.CheckedAnd Check3.CheckedThen
MsgBox ("You like Computer and Sports")
ElseIf Check1.CheckedAnd Check3.CheckedThen
MsgBox ("You like Reading and Sports")
ElseIf Check1.CheckedThen
MsgBox ("You like Reading only")
ElseIfCheck2.CheckedThen
MsgBox ("You like computer only")
ElseIf Check3.CheckedThen
MsgBox ("You like Sports only")
Else
MsgBox ("You have no hobby")
End If
1