Question

In: Computer Science

When writing code in any language, it is always a good idea to work in a...

When writing code in any language, it is always a good idea to work in a modular fashion. In this approach you will write a small piece of code (usually a small logical module), and test to ensure it works. If it does, you will add more code, and test it again. This way, if the program were to crash after you last addition, you will know where to look for bugs. Debugging a few lines of code is much easier than typing pages of code and then trying to debug that. Please use this approach while working at your programming assignments.

In this assignment you will write a small program that demonstrates that you can manipulate a string. You can hardcode a string of your choice in your code, that is, create a variable and assign it a string "Mary had a little chicken". Then you will use string functions to manipulate it. Keep in mind that to test your program I will enter my own string into your code. So, your program has to work for all possible strings and produce correct output.

First, echo the string on the screen, and then print it backwards using a string function. Figure out how to count the total number of letters in the string using functions provided in the chapter, and the number of vowels and consonants. For this exercise, please treat letter "y" as a vowel. Your output should look exactly like this:

Original string:   Mary had a little chicken
Reversed string: nekcihc elttil a dah yraM
Total letters: 21
Vowels: 8
Consonants: 13

Save your script as mystringyourlastname.php and submit to BB via submission portal before the deadline. Be sure to thoroughly test your code on xampp server with Internet Explorer and/or Firefox. I will be using xampp to test your submission. Test your assignment with various input strings to ensure it operates correctly. I will check different strings to make sure you have done error checking.

Please plan to have enough time for testing and debugging. I will nor be debugging your code for you. Please keep in mind that I ALWAYS read you code, so do not forget to format it nicely and use comments, as points will be deducted for such violations. Program that does not work will receive ZERO credit, as it is pointless to produce a program that does not work. Partial credit for depend on the existing functionality, per rubric below.

Solutions

Expert Solution

PHP CODE


<?php
        $inputString = "Mary had a little chicken";
        echo "Original string: ", $inputString;//Displaying string
        echo "<br>";
        echo "Reversed string: ", strrev($inputString);//String is reversed and displayed
        $vowelCount = 0;
        $constCount = 0;
        $inputString = strtolower($inputString);  //Converting all characters in string into lowercase
        for($i = 0; $i < strlen($inputString); $i++) 
        {       //Check whether it is vowel letter or 'y'
                if( $inputString[$i] == 'a' || $inputString[$i] == 'e' || $inputString[$i] == 'i' || $inputString[$i] == 'o' || $inputString[$i] == 'u' || $inputString[$i] == 'y') 
                {   
                        $vowelCount++;//Increments vowel count  
                }
                //Check consonants
                else if($inputString[$i] >= 'a' && $inputString[$i] <= 'z') 
                {  
                        $constCount++; //Increments consonant count 
                }  
        }  
echo "<br>";
echo "Total letters: ";
echo $vowelCount + $constCount;//display total character count

echo "<br>";
echo "Vowels: ";
echo $vowelCount;//display vowel count

echo "<br>";
echo "Consonants: ";
echo $constCount;//dispaly consonant count
?> 

PHP CODE SCREENSHOT

; ech" src= "https://media.cheggcdn.com/coop/b69/b698238a-caa6-4d80-b176-730890bd0646/1603466008057_2020-10-2319.png" style="height:766px;" />OUTPUT SCREENSHOT


Related Solutions

When it comes to language within various cultures what is a good point or idea that...
When it comes to language within various cultures what is a good point or idea that you have on Verbal Codes?
Is market segmentation always a good idea? Under which conditions, if any, might segmentation be unnecessary...
Is market segmentation always a good idea? Under which conditions, if any, might segmentation be unnecessary or unwise? need help to make a discussion for the class of marketing in healthcare.
Why does this code not work even when typing in the correct product code? It always...
Why does this code not work even when typing in the correct product code? It always gives me the error message even though im typing one of the 3 correct product codes. String[] product_code= new String[3]; String[] product_name= new String[3]; // String[] product_description = new String[3]; int[] quantity = new int[3]; double[] price = new double[3]; double[] itemTotal = new double[3]; double subTotal = 0, salesTax, total;    //getting all the needed inputs for(int i = 0; i < 3;...
It is always a good idea to understand the "size" of units. The objects listed below...
It is always a good idea to understand the "size" of units. The objects listed below are resting on a hard surface. Categorize each object according to the pressure it exerts on the surface when placed on their side with the largest area, which is the bottom. Assume that the bottom of each object is flat and that the pressure refers to that above atmospheric pressure (that is, gauge pressure). Use common sense estimates, make your own measurements and/or do...
When is it a good idea to use flash chromatography?
When is it a good idea to use flash chromatography?
Is offering GED classes or English as a second language classes to parent a good idea?
Is offering GED classes or English as a second language classes to parent a good idea?
Python. 1.Why is it a good idea to write and test the code for laying out...
Python. 1.Why is it a good idea to write and test the code for laying out a window's components before you add the methods that perform computations in response to events? 2.Explain why you would not use a text field to perform input and output of numbers. 3.Write a line of code that adds a FloatField to a window, at position (1, 1) in the grid, with an initial value of 0.0, a width of 15, and a precision of...
What should a good investor always remember when they are trading?
What should a good investor always remember when they are trading?
In your opinion and work experience, why is writing and/or speaking using vague language a major...
In your opinion and work experience, why is writing and/or speaking using vague language a major reason readers and listeners misunderstand business messages, including instructions on what to do on the job?
a. When would it be a good idea to outsource your manufacturing to a foreign Country?...
a. When would it be a good idea to outsource your manufacturing to a foreign Country? b. When would it be an absolutely bad time to outsource your manufacturing to a foreign Country. What I am looking for here is what situations at a company might cause you to consider going offshore? Provide some concrete examples to strengthen the questions (500-800 words)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT