Define a function called display_expression

Assignment Help Computer Engineering
Reference no: EM133368949

Write PHP program to generate randomly an algebraic expression. If you forgot what an algebraic expression is, this is an example of an algebraic expression: 6x -5 + 7x - 3x2 . You can read more about the algebraic expressions at Wikipedia.

The main idea is to generate randomly an algebraic exprssion with mutiple terms, then a student will simplify that expression. For example, a student can simplify 6x -5 + 7x - 3x2 to -3x2 + 13x - 5

1. Create php file and call it lib.php. In this file, define two functions:

display_html_head: this function has 1 input parameter which is the title of the HTML file. The function

does not return any value. In this function, use HEREdoc to print doctype, <html>, <head>, <title>, and <body> of a HTML file. Note that when you call this function, you must pass the title of the document that you want to display inside <title> and </title> tags

display_html_foot: this function does not have any input parameter and it does not return any value. Using a HEREdoc, print end tags for </body> and </html>

2. Create another php file, as your main php code, and use require to add lib.php to this main code.

3. Define a global variable called degree. This variable stores the degree of the algebraic expression that we are going to generate (the greatest exponent in an algebraic expression is the degree of that expression. For example, degree of x+3 is 1 and the degree of x2 + 3x - 1 is 2). We want to write a program that by changing the value of this variable, the program automatically generates an expression of that degree. Therefore, the final program will

be fully parametric based on the degree parameter.

4. Define another global variable called num_of_terms. This variable stores the number of the terms that we want

to generate in the expression. Num_of_terms depends on the degree of the expression. We use the following formula:

num_of_terms = 2 * degree + 3

It means that if the degree is 1, we will generate 5 terms (e.g. 9x-1+x-5x+1). If the degree is 2, we generate

7 terms (e.g. x+14x2-6+x2-2x-8x2-4)

5. Define a function called generate_expression. This function has only 1 input parameter, degree, and it returns a

two-dimensional array called terms: in the first row of this 2D array we store coefficients and in the second row we store exponents.
For example: for the following randomly generated expression, the 2d-array below is filled in this function:

x + 14x2 - 6 + x2 - 2x - 8x2 - 4

In this function use rand() pre-defined function of PHP to generate a random number for coefficients and exponents of the terms. Coefficient can be between -20 and 20 excluding 0 (a coefficient cannot be zero). Exponents can be from 0 to degree value. For example, if the degree is 2, exponents can be from 0 to 2 (i.e., 0, 1, and 2).

6. Define a function called meets_requirements. This function checks if the generated expression meets some requirements. This function has 2 input parameters, 2D-array terms, and degree, and it returns a Boolean value. To make the generated expression interesting for practice of the student, we require that there must be at least 2 terms from each degree in our expression. For example, the expression 2x + 3 - 1 + 5 - 2 does not meet the requirement because there is 1 term of degree 1 (2x) and there are 4 terms of degree 0 (3, -1, 5, and -2). But 2x + 3 - 1 + 5x - 2 meets the requirement because there are at least two terms of degree 1, (2x and 5x) and three terms of degree 0 (3, -1, and -2). Note that your function must work for all degrees. It means if the current value of the global variable degree is 3, the generated expression meets requirements if there are at least 2 terms of degree 3, at least 2 terms of degree 2, at least 2 terms of degree 1 and at least 2 terms of degree 0. For example, 2x3-5x+3-7x2+x-4x3-6+3x2+5 meets requirements, and your function must return true for this expression.

7. Define a function called print_expression. This function receives the 2D array of terms as input and prints the formatted expression on the HTML file. This function does not return any value. Some point to implement in your print_expression function:

a. If the first term is positive, we do not put a plus sign before it. For example, we do not print +3 - 5x + 7 instead we print 3 - 5x + 7, however if the first term is negative, we display minus sign: -6x + 6 - 2x

b. When a coefficient is one, it is omitted (e.g. 1x2 is written x2).

c. When the exponent (power) is one, it is omitted (e.g., x1 is written x)

d. When the exponent is zero, the result is always 1 (e.g., 3x0 is written 3, since x0 is always 1).

e. You can use <sup> HTML tag for displaying an exponent.

f. You can use abs predefined function for finding absolute value of a coefficient.

8. Define a function called display_expression. This function has one parameter, degree, and it does not return any value. The task of this function is to generate an expression and then verify if it meets the requirements. If it meets, display it, else repeat until an expression that meets the requirement is generated. In this function, you call generate_expression, meets_requirements, and print_expression inside a loop.

9. On top of your code, after the global variables, call display_html_head, display_expression, and display_html_foot functions. The details of how to call these functions with passing values to them is left to you.

10. IMPORANT: you must write your program such that by changing ONLY THE VALUE of degree global variable, your program generates a random expression of that degree. (You must not change any other part of your code.)

Reference no: EM133368949

Questions Cloud

Critically discuss how big data and data science can assist : critically discuss how "Big Data" and "Data Science" can assist in reducing the congestion at the port.
West african interior to north african coast : AD 300 Trade from the West African Interior to the North African Coast
Non-retraction controversy to the filipino nation : What was the effect of Rizal's retraction or non-retraction controversy to the Filipino nation? Discuss.
How will the shareholders be affected : How will the shareholders be affected? How will this affect the future ability of the two firms to raise funds?
Define a function called display_expression : Define a function called display_expression. This function has one parameter, degree, and it does not return any value. The task of this function
How long has tom worked for jackson enterprise : Tom originally started to work for Jackson enterprise at an annual salary of $36500 today Tom earns $68200 Tom calculated that his average annual pay raises
Concluded from archaeological ruin : Because many early African societies did not leave behind written records, much of what we know about these societies must be concluded from archaeological ruin
Describe thoughts on the rise of infectious diseases : Describe your thoughts on the rise of infectious diseases and the threat of more frequent pandemics. What might we do to prevent these diseases?
How much do you need to contribute this year to afford : You will withdraw your retirement spending at the end of each year. So your first retirement withdrawal will be at the end of year 31. Assume you will live for

Reviews

Write a Review

Computer Engineering Questions & Answers

  Complete the truth table for the given sequential circuit

Construct a truth table and find the minimized Boolean function to implement the logic telling the director when to hire. Draw a circuit diagram for the Boolean function. Complete the truth table for the following sequential circuit

  Evan expects to sell around 100 courses each month

evan moskowitz has formed an internet training company called teach-u-comp to sell computer programming courses online.

  Write a java gui application which can take a date

Write a Java GUI application, which can take a date (no earlier than 1900) from a user and show its corresponding day of the week.

  What are the levels of physical security

With 200-400 words,atleast 2 references and also in apa format. What are levels of physical security and how do they differ in the amount of security needed?

  CC41-3 Data Mining Assignment

CC41-3 Data Mining Assignment Help and Solution, Level 6 - Majan University College Assessment Writing Service - Faculty of Information Technology

  Write a relational algebra expression

Write a relational algebra expression that will output first name and last name of computer science major male students.

  How the data is analyzed and used with structured data

Write a 1 to 2-page paper. In the paper review the concept of unstructured data, outline the areas where this data can come from, evaluate the process.

  Knowledge of agency level enterprise operating systems

information of advanced Relational Database management Systems (RDMS) operating over a wide-area network. (note: Please explain RDMS operating over a WAN.)

  Define what are three authentication techniques

What forms of authentication can be implemented for a web application? What are three authentication techniques

  How do you convert contents of file shortlist to uppercase

How do you remove repeated lines from an unsorted file where repeated lines are contiguous. How do you convert the contents of the file shortlist to uppercase?

  Sum of array elements

Provided an array of ints named x and an int variable named total which has already been described, write down some code which places sum of all the elements of the array x into total.

  Abc institute of research has sensitive information that

abc institute of research has sensitive information that needs to be protected from its rivals. the institute has

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd