Advertisement
gitlez

Untitled

May 9th, 2011
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Page Layout</title>
  4. <!--
  5. The number of lines that can be printed on a paper depends on the paper size,
  6. the point size of each character in a line, whether lines are double-spaced or
  7. single-spaced, the top and bottom margin, and the left and right margins of the
  8. paper. Assume that all characters are of the same point size, and all lines are either
  9. single-spaced or double-spaced. Note that 1 inch=72 points. Moreover, assume that the
  10. lines are printed along the width of the paper. For example, if the length of the paper
  11. is 11 inches and width is 8.5 inches, then the maximum length of a line is 8.5 inches.
  12. Write a program that calculates the number of characters in a line and the number of lines
  13. that can be printed on a paper based on the following input from the user:
  14. a. The lenght and width, in inches of the paper
  15. b. The top, bottom, left and right margins
  16. c. The point size of a line
  17. d. If the lines are double-spaced, then double the point size of each character
  18. -->
  19. <script type="text/javascript">
  20. function elid(id){
  21. return document.getElementById(id);
  22. }
  23. function formFloat(id){
  24. var input = elid(id).value;
  25. var num = parseFloat(input);
  26. if(input != num){
  27. alert(id.substr(0,1).toUpperCase() + id.substr(1) + ' needs to be a number');
  28. errors++;
  29. return false;
  30. }else{
  31. return num;
  32. }
  33. }
  34. function Calculate(){
  35. errors = 0;
  36. var width = formFloat('width');
  37. var length = formFloat('length');
  38. var top = formFloat('top');
  39. var bottom = formFloat('bottom');
  40. var left = formFloat('left');
  41. var right = formFloat('right');
  42. var font = formFloat('font');
  43. var spacing = formFloat('spacing');
  44.  
  45. if(errors === 0){
  46. var hMar = left + right;
  47. var vMar = top + bottom;
  48. var hSpace = width - hMar;
  49. var vSpace = length - vMar;
  50. var charsPerLine = Math.floor(hSpace / (font/72));
  51. var linesPerPage = Math.floor(vSpace / ((font/72) * spacing));
  52. var charsPerPage = charsPerLine * linesPerPage;
  53. }else{
  54. var charsPerLine = linesPerPage = charsPerPage = 'Errors In The Input';
  55. }
  56. elid("cline").value = charsPerLine;
  57. elid("lpage").value = linesPerPage;
  58. elid("cpage").value = charsPerPage;
  59. }
  60. var errors = 0;
  61. </script>
  62. </head>
  63. <body>
  64. <form id='frm'>
  65. <table border="0">
  66. <tr>
  67. <th colspan="2"> Paper Size (inches)</th>
  68. </tr>
  69. <tr>
  70. <td> Width</td>
  71. <td><input type="text" id="width"></td>
  72. </tr>
  73. <tr>
  74. <td> Length</td>
  75. <td> <input type="text" id="length"></td>
  76. </tr>
  77. <tr>
  78. <th colspan=2> Margins (inches) </th>
  79. </tr>
  80. <tr>
  81. <td> Top </td>
  82. <td> <input type="text" id="top"></td>
  83. </tr>
  84. <tr>
  85. <td> Bottom </td>
  86. <td> <input type="text" id="bottom"></td>
  87. </tr>
  88. <tr>
  89. <td> Left </td>
  90. <td> <input type="text" id="left"></td>
  91. </tr>
  92. <tr>
  93. <td> Right </td>
  94. <td> <input type="text" id="right"></td>
  95. </tr>
  96. <tr>
  97. <th colspan=2> Formatting </th>
  98. </tr>
  99. <tr>
  100. <td> Font Size (pt) </td>
  101. <td> <input type="text" id="font"></td>
  102. </tr>
  103. <tr>
  104. <td> Line Spacing </td>
  105. <td>
  106. <select id="spacing">
  107. <option value="1" selected> Single </option>
  108. <option value="2"> Double </option>
  109. </select>
  110. </td>
  111. </tr>
  112. <tr>
  113. <td colspan=2><center> <input type="button" value="Calculate" onclick="Javascript: Calculate();"> </center> </td>
  114. </tr>
  115. </table>
  116. <br><br>
  117. <table border="0">
  118. <tr>
  119. <td> No. of Characters in a Line </td>
  120. <td> <input type="text" id="cline"> </td>
  121. </tr>
  122. <tr>
  123. <td> No. of Lines on a Page </td>
  124. <td> <input type="text" id="lpage"> </td>
  125. </tr>
  126. <tr>
  127. <td> Characters per Page</td>
  128. <td> <input type="text" id="cpage"> </td>
  129. </tr>
  130. </table>
  131. </form>
  132. </body>
  133. <html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement