{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2ProgramStructureI - Program Structure I Functions and...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 1 http://www.cs.cityu.edu.hk/~helena Program Structure I Program Structure I Functions and Variables Introduction to Functions Example: Marks to Grade Conversion Parameters and Return Statement Flowchart Comments Example: Find Highest Mark Introduction to Variables Use of Local Variables and Global Variables Example: Counter [Please switch off your phone]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 2 http://www.cs.cityu.edu.hk/~helena Introduction to Functions An Example: Marks to Grade Conversion 4 Grades: F: 0-45 C: 46-65 B: 66-80 A: 81-100 65 80 90 C B A The design: The header The table containing marks and grades The marks, grades, and the button are elements of a form , specified by <input..> . Marks are text boxes where the user can type: <input type="text" ../> Grades are read-only text boxes: <input type="text" readonly="true" ../> The button has the name "Convert" (the value attribute). It accepts the onclick event and shows the grades: <input type =" button " value =" Convert " onclick ="…." />
Image of page 2
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 3 http://www.cs.cityu.edu.hk/~helena <HTML> <HEAD><TITLE>CS1301 DEMO</TITLE></HEAD> <BODY> <h2>MARKS TO GRADE CONVERSION</h2> <form name="F1"> <table border="1"> <tr> <td align="center" width="20%">Subject</td> <td align="center" width="20%">Chinese</td> <td align="center" width="20%">English</td> <td align="center" width="20%">Mathematics</td> </tr> <tr> <td align="center">Mark</td> <td align="center"> <input type="text" name="CMark" size="4"/> </td> <td align="center"> <input type="text" name="EMark" size="4"/> </td> <td align="center"> <input type="text" name="MMark" size="4"/> </td> </tr> <tr> <td align="center">Grade</td> <td align="center"> <input type="text" name="CGrade" readonly="true" size="4"/> </td> <td align="center"> <input type="text" name="EGrade" readonly="true" size="4"/> </td> <td align="center"> <input type="text" name="MGrade" readonly="true" size="4"/> </td> </tr> </table> MARKS TO GRADE CONVERSION Version 1: By writing inline JavaScript
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 2. Program Structure I - 4 http://www.cs.cityu.edu.hk/~helena <input type="button" value="Convert" onclick=" if (document.F1.CMark.value>80) document.F1.CGrade.value='A'; else if (document.F1.CMark.value>65) document.F1.CGrade.value='B'; else if (document.F1.CMark.value>45) document.F1.CGrade.value='C'; else document.F1.CGrade.value='F'; if (document.F1.EMark.value>80) document.F1.EGrade.value='A'; else if (document.F1.EMark.value>65) document.F1.EGrade.value='B'; else if (document.F1.EMark.value>45) document.F1.EGrade.value='C'; else document.F1.EGrade.value='F'; if (document.F1.MMark.value>80) document.F1.MGrade.value='A'; else if (document.F1.MMark.value>65) document.F1.MGrade.value='B'; else if (document.F1.MMark.value>45) document.F1.MGrade.value='C'; else document.F1.MGrade.value='F'; " /> </form> </BODY> </HTML> However, such a very long inline JavaScript is difficult to read.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern