Document Sample
STUDY QUESTIONS Powered By Docstoc
					Study Q1                                     1

                         STUDY QUESTIONS

                     PRACTICE PROGRAMS TO WRITE

These are for practice only. (A) The exam program(s) may be different from any of these.
(B) The exam program(s) will incorporate features from more than one of these practice

    1. Response.Write

Write a program to accomplish the following:
   Place values in the following variables: (no input form is needed; just say age =10
       First name of person
       Date of birth.
   Based on the data provided, the program must output something similar to:

    Dear (first name of person):
    Based on your date of birth, your age is -----years. You say you are ---- years
    old. This is very suspicious. (if the age does not match) or This is consistent.
    (if the age matches).


    Chino Rao.

    2. Input Forms

Create an input form (the input form ONLY) to accept the following data from a user,
and sent to a program called “accept_input.asp”.

Last name
First name
Social security number (not to exceed 9 characters)
Would you like to apply for a credit card (radio buttons, default value = yes)
Are you a student? (check box)
Credit cards that you already have? (use select tags)
Password that you would like to use
Cofirm password that you would like to use
A submit button
Study Q1                                       2

    3. Flow Control

           a) Users are required to provide four inputs:
              i) their weight in pounds
              j) their height in inches
              k) the sports they play: basketball, football, none
              l) their GPA.

Based on these, they will be told which scholarships they are eligible for, if any. Include
a response.write statement to say which scholarships a student is eligible for. There are 3
types of scholarships available: academic, basketball, football. The following rules are

Students with a GPA=>3.5 are eligible for an academic scholarship.
If a student is <6 feet tall then he/she is not eligible for a basketball scholarship
If a student weighs less than 150 pounds or more than 400 pounds, he/she is not eligible
for a football scholarship.
Students must have a GPA of at least 2.0 to get a football scholarship.
Students must have a GPA of at least 2.5 to get a basketball scholarship.

Use if-then statements to apply these rules.

            b) Use SELECT CASE to do the following:
Students applying to UTSA are providing their high school GPAs. The criteria for
admission to the different colleges are given below. Write messages to the students
indicating their admission status in each of the schools.

There are 3 interests possible: business, arts and science.
For business, GPA >3.0 is accept, <=2.0 is reject, otherwise, put on hold.
For arts, GPA >2.6 is accept, <=2.0 is reject, otherwise hold.
For science, GPA 3.2 is accept, <=2.5 is reject and rest hold.

           c) Write a program using DO loops to create the following pattern, based on
              the number of lines specified by the user. (input form not required). You
              should also be able to do it with FOR-NEXT loops.

Study Q1                                      3

    4. Functions and Validation of Input
          a) Users have been asked to enter the social security number in the format
             999-99-9999. Write a function to validate that the user has input the DDN
          b) Users have been asked to enter their birth date in the format
             MM/DD/YYYY. Write the code to validate that the date has been entered
             in this format.

    5. Include Files

Write the functions in 4(a) and 4(b) as separate files. Write the include statement to use
those functions in any program.


    1. Response.write (clearly indicate blank spaces and line returns)

strX = “somnambulism”
strY = “Say what?!”

Response.write right (strY, 4) & Left (strX, 5) & “ …..” & “Please explain.” & “<br>”

Response.write Len(strX) + Len (strY) & “<br>”

Response.write instr(4, strX, “m”) & “<br>”

Response.write instr (6, StrX, “z”) & “<br>”

Response.write instr (strX, b)

    2. This program is called INPUT.HTML.

What is the output of these commands?

<title> This is the title </title>
Study Q1                                     4

<form method=post action= “continue.asp”>

Enter Last Name: <Input Type = text Name = Lname Value = “chino” size =20> <br>

Would you like to receive email? YES: <input Type=radio Name = Email> <input
type = radio Name=email> NO <br>

Please enter your password: <input type = password name=pw value = 23erft54x> <br>

<Select name = preference multiple size=3>
  <option value = ecom>
  <option value = mktg>
  <option value = mgmt>
  <option value = biol>
  <option value = math>


<input type = “submit” value = “CLICK HERE TO SUBMIT”>



Assume that the values input into the program above (INPUT.HTML) were:
Name = “Smith.” Password = “blooper”, and the preferences selected are biol and math.
Also the user clicked on the radio button for NO.

What will the output of the following program?

<title> This is the output</title>
</head> <body>

StrOne = “welcome”

Response.write “Hi, my name is “ & request.form (“lname”) & “.”

Response.write “ Regarding email, I would like to “ & request.form (“email”) & “. “

Response.write “Please don’t tell anyone, but my password is “ & request.form(“pw”) &
Study Q1                                   5

Response.write “Lastly, my preference for a major is “ & request.form (“preference”) &



What will the output of this code be if StrX = “betty botter”

strX= “betty botter”
iCount = 0

Do while p < len(strX) + 1
If icount < 8 then
        Response.write instr(strX, “b”)
End if
Icount = icount + 1

What is the output for the following for the three cases: (a) I=6 and J=1, (b) J=3 and
I=1, and (c) J=5 and I=5?



if I < J then
do while I < J
     for k = I to J
    reponse.write "I"
reponse.write "<br>"
I = I -1
Do while J < I
   For k = J to I
   Response.write "J"
Study Q1                                      6

Response.write "<br>"
J = J-1
End if

5. What is the output for (i), (ii) chino@aol, (iii)


if instr(strMail, “@”) = 0 then
  response.write “email address must contain @” & “<br>”
End if

If instr(strMail, “.”) = 0 then
  Response.write “email address must contain .” & “<br>”
End if

If instr(strMail, “@”) > instr(strMail, “.”) then
  Response.write “@ must come before .”
End if

If (right(strX, 3)) = “com” or (right(strX, 3) = “edu”) or (right(strX, 3)= “net”) then
  Response.write “domain is Ok”
  Response.write “domain should com or edu or net”
End if


What is the output if zipcode is (a) 45678 (b) xy34 (c) 345678k and (d) xyzer

function zip_valid (strX)
 LenX = len (strX)
 If (LenX = 5) then
    If isnumeric(strX) then
      Zip_valid = “Julia roberts”
Study Q1                                       7

     Zip_valid = “Robert Redford”
   End if
 If LenX < 5, then
    Zip_valid = “Sarita Rai”
   Zip_valid = “Mehdi Hassan”
 End if
End if
End function


strMsg = zip_valid(zipcode)

Response.write “The code word is “ & strMsg


                                        DEBUG CODE

Debug the following code – The errors may be logic errors or syntax errors.


     a) programmer wishes to find the sum of two numbers:
           response.write “45” + “87”

     b) programmer wishes to find the sum of two numbers:

           response.write 45 & 87

     c) programmer wants to write a paragraph:

           strXYZ = Smith
           intABC = 456
Study Q1                                           8

           Response.write strXYZ “has” intABC “books in his library.”

                                            Input forms

    a) Programmer does not want the user to enter more than 9 characters.
                      <input type=text name=SSN maxvalue = 9 value=999999999>

    b) Programmer wants to user to input (a) gender, i.e., male or female, and (b)
       whether the user wants to join the club. Programmer is using radio buttons for

    Select Gender: <input = radio name=radio1 > MALE <input =radio name = radio2> FEMALE

    Join Club? <input=radio name=radio1> YES <input = radio name = radio2> NO

    c) Using the SELECT tag, programmer wishes to display 3 out of 6 options to the
       user. User should be able to choose more than one option.

                   <Select name = preference length=6 number=3 >
                       <option value=ecommerce>
                       <option value=marketing>
                       <option value=management>
                       <option value=accounting>
                       <option value=math>
                       <option value=science>

    d) Programmer wishes to offer the user a choice to submit the data entered in a form
       or clear the entries.

           <input type=submit value= “PRESS TO SUBMIT”>
           <input type=clear value= “PRESS HERE TO CLEAR”>


    e) Programmer wishes to offer the user choice to either subscribe or not:

           Would you like to subscribe: <input type=checkbox name=chkSubs> YES <input
           type=checkbox name=chkSubs> NO

                                          Request Object

You are provided the code for an input form (INPUT.HTML). IT HAS NO ERROR.
Identify the errors (logical or syntactical) in the following sets of code.

Study Q1                                      9

       <title> input.html </title>

       <form method = post action = getdata.asp>
       ENTER FIRST NAME: <input type=text name=strName >
       ENTER YOUR AGE: <input type=number name=intAge>
       ENTER YOUR DATE OF BIRTH: <input type=date name= “dtmDOB”>
       <input type = submit value = “PRESS HERE TO ENTER DATA”>


GETDATA.ASP: In this program,
       I)       the programmer wishes to capture the values input by the user for
                First Name, Age and Date of Birth.
       II)      Then the programmer wishes to create an input form displaying the
                data input by the user.

    <title> input.html </title>

    StrName = request.from (“fname”)
    IntAge = request.form (“age”)
    DtmDOB = request.querystring (date_of_birth)


    <form method=get action=getdata.asp>

      ENTER FIRST NAME: <input type=text name=strName >
      ENTER YOUR AGE: <input type=number name=intAge>
      ENTER YOUR DATE OF BIRTH: <input type=date name= “dtmDOB”>
      <input type = submit value = “PRESS HERE TO CONFIRM DATA”>



                                      If then /CASE

Prgorammer wants to respond with grade of A+ if intgrade > 97; A if >92 ,but <97, else

    If intgrade > 89 then
       Select Case (intgrade >x)
         Case cbool (intgrade >97)
            “That is an A+”
         Case cbool (intgrade > 89)
Study Q1                                         10

           “That is an A-“
       Case Else (intgrade > 92 and intgrade < 97)
         “That is an A.”
     “You did not make an A.”
    End if


    Select Case strGrade
      Case if strGrade = A then
           Response.write “Wow, that is good!”
      Case if strGrade = B then
           Response.write “That‟s not bad either.”
      Case if strGrade = C then
          Response.write “Acceptable, but could be better”
      Case if strGrade = “something else” then
          Response.write “You have to repeat the course.”

    Select End


Do While, Do Until, For Next

Programmer accepts any number between 1 and 9 from the user. Programmer wishes to
display a total of six single-digit numbers using one of these rules. Starting with the
user’s number, the programmer writes the six numbers incrementing by 1. If the value
reaches 10, then he reverses the sequence and decrements the numbers till six digits are
written out.

Example: if user says 2, then programmer responds 2 3 4 5 6 7 8.
         If user says 6, then programmers responds 6 7 8 9 8 7.
    intStart = request.form(“starting_number”)
    intCount = 0

    For i = instart to instart +6 step 1
     Response.write instart & “<br>”
     ICount=icount + 1
     If Icount>6 then
        Exit for
    End if
    If instart >8 then
       Do while icount <7
         Instart = instart – 1
         Response.write instart & “<br>”
         Icount = Icount + 1
Study Q1                                                 11

    End if

                                            Left Right Mid Instr

Programmer wishes to test if the first three characters of test_characters or the last three
characters of test_characters contains the letter x.

           strTest = request.form (“Test_characters”)

           If Instr (left(strTest, 3, x)) or Instr(right(strTest, 3, x)) = 0 then
             Response.write “Test characters do not contain x”
              Response.write “Test characters do contain x.”
           End if.


Programmer allows the user to enter his/her birth date and that of a friend. Wants to write
a FUNCTION which does the following. If both were born before a given date (Nov 20,
1980), else they are incompatible.

    dtmUserBdate = request.form(“Bdate1”)
    dtmFriendBdate = request.form(“Bdate2”)

    response.write fnTest (Bdates)

    Function (bdate1, bdate2)
     If (cdate (11/20/80) > dtmUserBdate) and (cdate(11/20/80) > dtmFriendBdate) then
       Fntest = “Compatible.”
     Fntest= “Not compatible.”
    End if

                                                 Include files

Programmer wishes to include the file “footer.txt” in a program. Demo.asp.

Study Q1                                              12

                    response.write “this is form the include file footer.Txt”


           Response.write “this is a test program showing how include files work”

           <!-- #include file = “Footer.txt”--!>

Shared By: