Logo
Question DetailsNormal
$ 30.00
Chapter 5 Written Questions (For-Loops & Strings) answers A+ 100% Satisfaction Guaranteed!
Question posted by
request

Chapter 5 Written Questions (For-Loops & Strings)
1. Answer questions (a) through (c) based on code below.
Dim num As Integer Dim sum As Integer For num = 1 To 3 sum = sum + num Next num
Me.outLabel.Text = sum

a) How many times does the body of the loop execute?
b) What is the output (value assigned to Text property of outLabel)?
c) What is the final value of num?
2. Answer questions (a) through (c) based on code below.
Dim num As Integer
Dim sum As Integer
For num = 1 To 5 Step 2
sum = sum + num
Next
Me.outLabel.Text = sum

a) How many times does the body of the loop execute?
b) What is the output (value assigned to Text property of outLabel)?
c) What is the final value of num?
3. Answer questions (a) through (c) based on code below.
Dim num As Integer
Dim sum As Integer
For num = 1 To 3 Step -1
sum = sum + num
Next
Me.outLabel.Text = sum

a) How many times does the body of the loop execute?
b) What is the output (value assigned to Text property of outLabel)?
c) What is the final value of num?

4. Answer questions (a) through (c) based on code below.
Dim num As Integer
Dim sum As Integer
For num = 3 To 1 Step -1
sum = sum + num
Next
Me.outLabel.Text = sum

a) How many times does the body of the loop execute?
b) What is the output (value assigned to Text property of outLabel)?
c) What is the final value of num?
5. Most of the variable types we have used like Integer and Double are referred to as primitive data types. Is
the String type also primitive? If not, what is it? No. JavaScript automatically converts primitives to
String objects, so that it's possible to use String object methods for primitive strings. In contexts
where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will
automatically wrap the string primitive and call the method or perform the property lookup.
6. What operator (character) is used to combine strings? Show the character and list its name. the

concatenation operator //

7. Write the assignment statement that concatenates two strings named firstNameString and lastNames with
a space between the two. Assign the results to fullNameString.

string firstname, lastname, fullname;
cout << "First name: ";
getline (cin, firstname);
cout << "Last name: ";
getline (cin, lastname);
fullname = lastname + ", " + firstname;
cout << "Fullname: " << fullname << endl;
8. Consider the statement: str1 = "Code Wars" What value is assigned to the variables in the
statements?
a) newl = str1.ToLower
b) new2 = str1. Substring (0, 4)
c) new3 = (str1.ToUpper).Substring(3, 4)
d) posl = str1.IndexOf("d")
e) pos2 = str1.IndexOf("WARS")
9. Determine if each of the following is true or false. (1 point each)
a) The counter in a For...Next statement is always incremented or decremented by 1.
b) The String data type is a primitive data type.
c) A string can be changed by methods of the String class.

d) vbTab is a variable that allows the programmer to control the spaces in a string.
e) The Unicode value for an uppercase letter is the same for the corresponding lowercase letter.
f) A wildcard character is a ?, * or #, which matches an unknown character or group of characters.

Exercises
Average Sequence Sum (
Use a for-next loop to average the sum of every seventh number from 3 to a final value the
user enters into a texbox (3 + 10 + 17 ...). You will need a counter variable and an
accumulator variable. Make sure you validate input to ensure entry is numeric, and that the
user enters a valid number above 3.

Exercise 12 Count Vowels pg 159
Create a CountVowel Application that counts the number of vowels in a word or phrase.
The application interface should look similar to:
Hint: Use the Chars() property of the String class within the body of a loop to access the
individual letters of the string. The counter variable of your loop will be the index of the
Chars() property. Example:
currentChar = inputString.Chars(count)
Then test currentChar in an If statements to see if it is equal to "A", "E", "I", "O", or "U". If so,
increment a vowel counter.
def main():
vowels = ['a','e','i','o','u']
numberOfVowels = 
phrase = raw_input("Input a word/phrase:")
print "Number of Vowels:"
for i in range(len(vowels)):
numberOfVowels.append(phrase.c...‡ + phrase.count(vowels[i].upper()))
main()
---edit--don't know why that line shortened...it was the following all on one line:
numberOfVowels.append(
phrase.count(vowels[i].lower() ) +
phrase.count(vowels[i].upper() ) )

1. Explain the similarities and differences between parameters and arguments.

2. Write a line of code that:
a) calls a procedure named Contains() that has two value parameters named fullString and PartString and a
reference parameter named foundBoolean. (2 points)
b) contains the Sub procedure heading (first line) for the Call statement in part (a).
3. List the contents of the message box output in the order of execution for the following code.
Private Sub Button1_Click() 
Dim intNum1 As Integer
Dim intNum2 As Integer
intNum1 = 1
intNum2 = 2
Call Proc1(intNum1, intNum2)
MessageBox.Show("In Button Event Procedure:" & intNum1 ", " & intNum2)
End Sub
Private Sub Proc1(ByVal intA As Integer, ByVal intB As Integer)
intA = intA + 2
intB = intB + 5
MessageBox.Show("In Proc1: " & intA & ", " & intB )
End Sub

4. List the contents of the message box output in the order of execution for the following code.
Private Sub Button1_Click() 
Dim intNum1 As Integer
Dim intNum2 As Integer
intNum1 = 1
intNum2 = 2
Call Proc1(intNum1, intNum2)
MessageBox.Show("In Button Event Procedure: " & intNum1 ", " & intNum2)
End Sub
Private Sub Proc1(ByRef intA As Integer, ByVal intB As Integer)
intA = intA + 2
intB = intB + 5
MessageBox.Show("In Proc1: " & intA & ", " & intB )
End Sub

5. Determine if each of the following is true or false.
a) A Sub procedure must always be declared with parameters.
b) A procedure can call another procedure.
c) Arguments passed by value must be in the form of a constant.
d) A ByRef parameter only exists for the duration of a procedure.
e) A ByRef parameter uses the same memory location as the argument it is
passed.
f) A control object, such as a textbox or label, can be passed to a
procedure as an argument.
g) The parameters sender and e are optional in an event handler procedure.
h) A Click event procedure can be coded to handle multiple events for more than one control object.
i) Only the Button control has a Tag property.
j) A Call statement must be used in order to execute any type of procedure.

Exercises
String Sort (not in text)
Create a program that obtains two strings within text boxes entered by a user and stores
them to variables. Send the two variables as arguments to a Sub Procedure called
SortStrings() that compares the strings and orders them so the first variable always contains
the "lower" string. After the Sub completes, from the event-procedure that called the
SortStrings() procedure, display the two variables in a label on the form in the correct order.
The event-procedure should do input, calling of SortString(), and output, and the
SortStrings() Sub Procedure should do the sorting, but not the input or output.
Submit a listing of the code and a working form that displays input and output.
Exercises
Phone Bill Exercise
Create a PhoneBill application that determines a phone bill by propting the user for calling
options (call waiting, call forwarding, and caller ID). The monthly basic service charge is
25.00 and each additional calling option is $3.50. The application interface should look
similar to the following after selecting options and clicking Calculate:
Perform the problem as described, but assign costs to options as follows:
Call Waiting: $2.50
Call Forwarding: $3.00
Caller ID: $5.00
Do not use a button. Have the Total label update whenever the user clicks one of the check
boxes. This is not a looping problem, but stresses accumulator variable concepts. The

accumulator variable will need to be declared module-level. You may use either the
CheckChanged event or the Click event of each CheckBox control to test if each CheckBox
is checked or not checked.
The CheckChanged or Clik event occurs regardless of whether the CheckBox goes from
checked to unchecked, or from unchecked to checked. When the CheckBox is checked, the
associated charge is added to the total. When unchecked, the associated charge is to be
deducted from the total.
Average Sequence Sum
Use a do-while loop to average the sum of every seventh number from 3 to a final value the
user enters into a texbox (3 + 10 + 17 ...). You will need a counter variable and an
accumulator variable.
Make sure you validate input to ensure entry is numeric, and that the user enters a
valid number above 3.

Available Solution
$ 30.00
Chapter 5 Written Questions (For-Loops & Strings) answers A+ 100% Satisfaction Guaranteed!
  • This solution has not purchased yet.
  • Submitted On 30 Aug, 2015 04:29:30
Solution posted by
solution
1 a.3 b.6 c.4 2. a.3 b.9 c.7 3. a.1 b.0 c.1 4. a.3 b.6 c.0 5. No…. It automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strin...
Buy now to view full solution.
attachment
Attachment
closebutton

$ 629.35