Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 (15 pts.). Write an HTML document prob2.html that loads a JavaScript file prob2.js. The JavaScript program should prompt the user for a string that

2 (15 pts.). Write an HTML document prob2.html that loads a JavaScript file prob2.js. The JavaScript program should prompt the user for a string that contains three values separated by any amount of whitespace. There may also be any amount of whitespace (including, in this case, none) before the first value and after the last. The first value on a line should be in a floatingpoint format (explained in detail below), the second value should be a signed or unsigned decimal integer (see below), and the third value should be one of the single letters x, y, or z. You write a regular expression intended to match an entire line (so it begins with ^ and ends with $). Keep running sums of the floating-point numbers represented by the first values and of the integers represented by the second values in a line. Also, maintain a string onto which the third values are concatenated. If one or more of the values in a line are improperly formatted, output that line preceded by the string "No match with "; in this case, the entire line is ignored (making no contribution to the accumulated values). The format for the integer value is simple: either (1) an optional sign followed by a string of digits beginning with a digit other than 0 or (2) the string consisting only of 0. The format for floating-point values is very versatile. There is an optional initial sign. Then, before the decimal point (if there is one), there is either the character 0 or a string of digits beginning with a digit other than 0. There are two possibilities for the remainder. One possibility is a decimal point followed by one or more digits. The other possibility is an optional decimal point and one or more digits, then E or e, and then a string of one or more digits optionally preceded by a sign. The following are examples of valid floating-point representations. 12.34 -3.5 32.2E2 4.23e-10 62E+2 0.0 The following are examples of representations that fail to meet this format. 12.E2 (There is no digit after the decimal point.) 062.42 (The initial 0 is invalid.) The following is the strings that you can use to test your program, which you can download from the assignment site. 12.34 -79 x -3.5 23 y 32.2E2 2 z 4.23e-10 +45 x 62E+2 -4 y 0.0 0 z 12.E2 -125 x 062.42 12987 y 3.45 12.5 z -45.2 06 x COMP 322 Internet Systems Fall 2014 Assignment 4 3 43.6 72 yz -2.63 -10 X The last six lines are invalid. The first two of these six contain the invalid floating-point forms just mentioned. The next two lines contain invalid integer representations (as the second values): 12.5 (not an integer) and 06 (invalid initial 0). The third values in the last two lines are invalid: yz (only single letters are allowed) and X (must be lower case). The following is the output of the program clicking Cancel when prompted for a new string. No match with 12.E2 -125 x No match with 062.42 12987 y No match with 3.45 12.5 z No match with -45.2 06 x No match with 43.6 72 yz No match with -2.63 -10 X 9428.84 -13 xyzxyz To extract the values from the lines, in your regular expression, you will have to do grouping to capture sub-expressions (surrounding sub-expressions to be remembered with parentheses). When you need parentheses for grouping but not capturing, use non-capturing groups, which, recall, are of the form (?:).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions