Study Q1: Creating Programs and Input Forms, Study notes of Information Technology

Instructions for writing programs in asp to accomplish various tasks, such as assigning values to variables, creating input forms, and using flow control structures. It also covers topics like functions, include files, and error handling.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-hxt
koofers-user-hxt 🇺🇸

8 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Study Q1 1
STUDY QUESTIONS
PRACTICE PROGRAMS TO WRITE
NOTE:
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
programs.
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
etc:)
First name of person
Age
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).
Sincerely,
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
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Study Q1: Creating Programs and Input Forms and more Study notes Information Technology in PDF only on Docsity!

STUDY QUESTIONS

PRACTICE PROGRAMS TO WRITE

NOTE:

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 programs.

1. Response.Write Write a program to accomplish the following: Place values in the following variables: (no input form is needed; just say age = etc:) First name of person Age 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). Sincerely, 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

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 applied. 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.

Enter Last Name: Would you like to receive email? YES: NO Please enter your password:

THANK YOU.

3. REQUEST OBJECT 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?

This is the output

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”) & “”

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

4. What will the output of this code be if StrX = “betty botter” <% strX= “betty botter” p = 1 iCount = 0 Do while p < len(strX) + 1 If icount < 8 then Response.write instr(strX, “b”) End if Icount = icount + 1 P = P + 1 Loop %> 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? <% I= J= if I < J then do while I < J for k = I to J reponse.write "I" next reponse.write "" I = I - Loop Else Do while J < I For k = J to I

Else Zip_valid = “Robert Redford” End if Else If LenX < 5, then Zip_valid = “Sarita Rai” Else 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. Response.Write 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

Response.write strXYZ “has” intABC “books in his library.” %> Input forms a) Programmer does not want the user to enter more than 9 characters.

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 both. Select Gender: MALE FEMALE Join Club? YES 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.

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

e) Programmer wishes to offer the user choice to either subscribe or not: Would you like to subscribe: YES 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.

“That is an A-“ Case Else (intgrade > 92 and intgrade < 97) “That is an A.” Else “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 & “” ICount=icount + 1 If Icount>6 then Exit for End if If instart >8 then Do while icount < Instart = instart – 1 Response.write instart & “” Icount = Icount + 1 Loop

End if Next %> 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” Else Response.write “Test characters do contain x.” End if. %> Function 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.” Else Fntest= “Not compatible.” End if %> Include files Programmer wishes to include the file “footer.txt” in a program. Demo.asp. footer.txt