Question

In: Computer Science

Using the combination of HTML and PHP, implement a web page where the users can upload...

Using the combination of HTML and PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 1000 numbers, such as:

71636269561882670428252483600823257530420752963450
85861560789112949495459501737958331952853208805511
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
96983520312774506326239578318016984801869478851843
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
05886116467109405077541002256983155200055935729725
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
62229893423380308135336276614282806444486645238749
73167176531330624919225119674426574742355349194934
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776

Your code should contain a PHP function that, accepting the string of 1000 numbers in input, is able to:

1) Find the 5 adjacent numbers that multiplied together give the largest product.

2) Given the product from above, computes the sum of the factorial of each term of such product

Example, if the product is 5046, computes 5! + 0! + 4! + 6!

NOTE:

  • If the file doesn't contain 1000 numbers or contains some characters in between, it should be discarded and the application should inform the user that the file is not format correctly.
  • Add a tester function to check the behavior of your PHP function.
  • Follow the guidelines discussed and showed in class to avoid losing points.

Solutions

Expert Solution

//HTML file

<html> <body> <form action="prog.php" method="post">
File name: <input type="text" fname="fname" /> <input type="submit" /> </form> </body> </html>

// Prog.php file

<?php

$c = fopen("fname", "r") or die("Can not open File! Try again");
echo fread($c,filesize("input.txt"));
fclose($c);
  
$inptlen= strlen($c[0]);

if( $inptlen > "999") // checking for the length is 1000 or less that that
{

for($i= 0; $i<$inptlen ; $i++)
{
$asc = ord($c[$i]); // checks whether any character is present or not based on ascii
if ($asc>="48" && $asc<= "57") //as the 0-9 ascii lies from 48-57 , we are checking for that
{
$numb[$i]= (int)$c[$i];
}
else
{
echo "\nWrong !!! file format \n";
}

}
for ($j =0; $j<$inptlen-5;$j++)
{
$mul[$j] = $numb[$j]*$numb[$j+1]*$numb[$j+2]*$numb[$j+3]*$numb[$j+4]; // the multiplication of 5 consecutive values
  }
$highest= (string)max($mul); // highest value from the multiplications
$nochar=strlen($highest); // converting number in to digits using string maping
for($k=0;$k<$nochar;$k++) // factorization of digits
{
$fact= 1;
for($g=(int)$highest[$k]; $g>=1; $g--)   
{
if($g=="0")
{
$fact=1;
}
else
{
$fact = $fact * $g;
}
}
$factresult[$k]=$fact;
}
$s=0;
for($b=0;$b<$nochar;$b++)
{
$s=$s+$factresult[$b]; //sum of factorials
}
echo "Final Result is :";
echo $s;
}
else
{
echo "Wrong !!! file format \n";
}

?>

Test Function:

Please save the following content in three different text files:

1. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of positive output.

8793626956188267042825248360082325753042075296345085861560789112949495459501737958331952853208805511657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688196983520312774506326239578318016984801869478851843125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311305886116467109405077541002256983155200055935729725164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776

2. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of negative output for the size of the no of values.

56188267042825248360082325753042075296345085861560789112949495459501737958331952853208805511657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688196983520312774506326239578318016984801869478851843125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311305886116467109405077541002256983155200055935729725164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888

3. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of negative output as there is a character present.

87936269561882670428252483600823257530420752963450858615607891129494954595017379583319528532088055116572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881969835203127745063262395783180169848018694788518431254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113058861164671094p507754100225698315520005593572972516427171479924442928230863465674813919123162824586178664583591a45665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403@509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776


Related Solutions

Using a combination of HTML/PHP, implement a web page where the users can upload a text...
Using a combination of HTML/PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 400 numbers, such as: 71636269561882670428 85861560789112949495 65727333001053367881 52584907711670556013 53697817977846174064 83972241375657056057 82166370484403199890 96983520312774506326 12540698747158523863 66896648950445244523 05886116467109405077 16427171479924442928 17866458359124566529 24219022671055626321 07198403850962455444 84580156166097919133 62229893423380308135 73167176531330624919 30358907296290491560 70172427121883998797 Your code should contain a PHP function that, accepting the string of 400 numbers in input, is able to find the greatest product of four adjacent numbers in all the...
Create a web page using PHP that allows the users to create an account (a username...
Create a web page using PHP that allows the users to create an account (a username and a password). There should be a login page that allows users to create an account by entering their preferred username and password. The same page should also let users login if they already have an account. If a user is logged in successfully , they should be able to enter a comment and also read the comments entered by others previously.
Create a web page using PHP and HTML that contains a list of movie names available...
Create a web page using PHP and HTML that contains a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required. 2) The rental price for each movie ranges between $1.99 to $7.99. • Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental...
please write Django web app with simple html page, that you can upload the image and...
please write Django web app with simple html page, that you can upload the image and display image and display path of the image on the PC.
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML...
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML tags to design your webpage: <h1>...</h1>,<h3>...</h3>, <h6>...</h6>, <p>...</p>, <b>...</b>, <i>...</i>, <a>...</a>, <img...>, <table>... </table>, <div>...</div>, <form>...</form>, <input type="text">, and <input type= "submit"> Use an external css to change the default style of your webpage. You must use at least one element selector, one id selector, and one class selector Using text input and submit button, allow the user to change the background color of...
write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
1. An HTML document that’s generated by a web application is a ________________________ web page. 2....
1. An HTML document that’s generated by a web application is a ________________________ web page. 2. An easy way to log the progress of an application in Chrome’s Console panel is to insert __________________ methods at critical points in the code. 3. The childNodes property of a DOM object returns a/an ______________________ of the child nodes for that object. 4. The ___________________ method of an array can be used to concatenate the elements of the array into a single string.​...
Develop a one-page website using HTML tags and element to implement the following. THIS IS HEADING...
Develop a one-page website using HTML tags and element to implement the following. THIS IS HEADING 1 THIS IS HEADING 2 THIS IS HEADING 3 THIS IS HEADING 4 THIS IS HEADING 5 THIS IS HEADING 6 THIS IS A PARAGRAPH. THIS IS A PARAGRAPH. THIS IS A PARAGRAPH THIS IS ANOTHER PARAGRAPH. THIS IS ANOTHER PARAGRAPH. THIS IS ANOTHER PARAGRAPH THIS IS A LINE BREAK THIS IS A LINE BREAK THIS IS A LINE BREAK THIS IS AN ORDERED...
Make a modest or simple Web page using Python flask. The basic components of HTML should...
Make a modest or simple Web page using Python flask. The basic components of HTML should be included. The Web page should have at least 3 Headings(<h1>), paragraph (<p>), comments (<!-- -->), ordered list, unordered list, three links to website, and should display time & date. Example: <html>     <head>         <title>Page Title</title>     </head> <body>     ..new page content.. </body> </html>
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT