CSC 171 - Intro to Computer Programming

Draw a flow chart for the problem of graphing the function f(x) = (x - 4) (x - 5) + 1, for a range of values of x given by the user, as described below. Start with a high-level flow chart that uses high-level language (e.g. read and validate inputs, draw graph, etc) , then refine each step with a separate flowchart; you may think of this refinement as focusing on a subproblem (e.g. drawGraph), and decomposing it into further sub-subproblems (e.g. printHeading, drawOneLine). Each subsolution (i.e. solution to a subproblem) will be a candidate for a method; identify what each subsolution (method) will do, and what information it will need and return (if any).

First, read in two integers, representing the range of values of x, i.e. read in the low value and the high value of x. For each value of x, compute y = (x - 4) * (x - 5) + 1, and print y asterisks. For example, if x = 2, then y = 7, so 7 asterisks should be drawn on the same line. If the user enters 2 and 7 as the low and high values of x respectively, then the output should look like this:

Enter the low value of x: 2
Enter the high value of x: 7

x f(x)
--------------------------------------------------
2 |*******
3 |***
4 |*
5 |*
6 |***
7 |*******
We require that the low and high values entered by the user satisfy low >= 0, low < 10, low < high, and that low and high are integers.

After drawing the graph, ask the user if (s)he wants to continue, i.e. draw another graph.

[Back to Lab Exercises]