Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CS 135 – Assignment #8 Revision 1 Purpose: Become familiar with value returning functions, file output, and utilize driver code written by the instructor. Assignment: The Great Gazoo has visited Fred...

1 answer below »

CS 135 – Assignment #8 Revision 1
Purpose: Become familiar with value returning functions, file output, and utilize
driver code written by the instructor.
Assignment:
The Great Gazoo has visited Fred while Fred was sleeping. Gazoo whispers several
equations in Fred's ear. When Fred wakes the next morning, he writes the equations down so he
doesn't forget them. Fred has no idea what they mean, so you help him out and write a program that
plots the equations.
Write a C++ program to calculate the following parametric sets of equations. These equations will be
used to generate a text file with x and y values, space delimited. The text file will be used as input to
gnuplot which will output a png image file. Gnuplot is a graphing utility for Linux that uses an text file
containing points, x and y values, as input, and generates a graphic image, (.png). The files generated
will need to be moved off Sally to be viewed. They may be sent by e-mail or moved by scp to you
computer to be viewed.
A stu
ed out main program is provided to you. AS8Solution.cpp is in the djShare directory on sally
and on the Canvas web site for the class. There is a stub provided for every function that the student is
equired to write. Do not change main. Add your code to the appropriate function stub along with
comments for that stub.
Archimedean Spiral
void archimedean( )
The achimedean function has no parameters. The function should open the file achimedean.txt for
writing and verify that it opened. If the file archimedean.txt does not open, an e
or message should be
displayed and the program should exit by calling exit(0). The user should be prompted and values read
for the spiral count the size. Values are calculated for x and y for all values of t, from 0 to count, by
steps of 0.1. Each pair of values, x and y, are written out to the file, one pair per line, space delimited.
When all values have been written, the file should be closed and the function returns.
Archimedean Spiral Equations
x=size∗t∗cos( t +size)
y=size∗t∗sin( t+ size)
0 < t < (count∗2∗π)
t steps by 0.1
Example of Archimedean.txt for count=5, size=1
(first 8 lines shown)
0 0
XXXXXXXXXX
XXXXXXXXXX
Figure 1:Wikipedia
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
Fish Curve
void fish( )
The fish function has no parameters. The function should open the file fish.txt for writing and verify
that it opened. If the file fish.txt does not open, an e
or message should be displayed and the program
should exit by calling exit(0). The user should be prompted and values for size, rotation, count and plot
offset should be read. Values should be calculated for x and y for all values of t, from 0 to 10 * π by
steps of 0.1 for count iterations. After each iteration, the value of size should be modified by
multiplying by plot offset. The values calculated, x and y, should be written out to the file, space
delimited. When the all values have been written to the file, the file should be closed and the function
eturns.
x=size∗(cos( t )+2.0∗rotation∗cos ( t / 2.0))
y=size∗sin ( t)
0≤t ≤( 10 ∗ π )
t steps by 0.1
After each iteration size is modified
size=size∗plot offset
Example data from fish.txt with size=1, rotation=1, count=5, offset=1.2
(first 8 lines shown)
3 0
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
Mystery
The mystery function, when properly programmed and plotted by gnuplot, will result with a well
known cultural icon. Each formula for x and y should be calculated for each value of t.
Functions( Mystery )
void mystery( )
The mystery function should open the file mystery.txt and verify that it opened. If the file does not
open, the program should exit using exit(0). There are two functions that mystery calls, mysteryX( )
and mysteryY( ). Each function, mysteryX( ) and mysteryY( ), is called for each value of t to generate an
x and y pair, which is written to file mystery.txt. One pair of values per line, space delimited. The
ange of t is from -8.0 to 8.0, in steps of 0.001.
Hint:
• Use a loop to call mysteryX( ) and mysteryY( ) for each value of t.
double mysteryX( double )
Calculates the value of x based on the value of t passed in.
double mysteryY( double )
Calculates the value of y based on the value of t passed in.
Formulas for Mystery Plot
sin-1( ) is the inverse sine function. Use cmath function asin( ) to compute the inverse sine.
double asin (double x);
Example data from mystery.txt
(first 8 lines shown)
4.40092e XXXXXXXXXX
-1.87666e XXXXXXXXXX
-7.50662e XXXXXXXXXX
XXXXXXXXXX09135
XXXXXXXXXX07706
XXXXXXXXXX06275
XXXXXXXXXX04841
XXXXXXXXXX03405
x( t )=|t|
t (
.3|t|+ .2||t|−1|+2.2||t|−2|−2.7||t|−3|−3||t|−5|+3||t|−7|
+5sin(π
4
(||t|−3|−||t|−4|+1))+5
4
(||t|−4|−||t|−5|−1)3
−5.3cos (( π
2
+sin−1(47
53
))(
||t|−7|−||t|−8|−1
2
))+2.8)
y ( t )=32
||t|−1|−32
||t|−2|− 294
||t|−4|+ 294
||t|−5|+ 716 (
||t|−2|−||t|−3|−1)4
+ 4.5 sin( π
4
(||t|−3|−||t|−4|−1))− 3√ 2
5
|||t|−5|−||t|−7||
5
2
+6.4 sin( ( π
2
+sin−1( 47
53
))
(||t|−7|−||t|−8|+1)
2
+sin−1(56
64
))+4.95
(−8≤t≤8)
Ouput File Format
Write the values of both x and y to the ouput file, separeted by a space, one pair per line. No other text
or comments should be written to the file. The output file will be used as the input to the plotting
program, gnuplot.
Files Generated by Driver Code
The driver code calls two functions after the student written functions, fish( ), archimedian( ), and
mystery( ). The first, genPlotScript( ) will create script file for gnuplot. This file tells gnuplot what the
input file should be and gives it information about how the data should be plotted. The next call is to
system( ), which will execute gnuplot with the script generated above. When gnuplot runs, the output
files will be a file of type .png. This file can't be viewed on Sally, and needs to be moved to your PC
for viewing.
Remembe
• Verify that all cin operations are successful. If a cin fails, the I/O stream should be cleared, a
suitable message output to the user, and the user should be reprompted.
• include the li
aries cmath and cstdli
• use the function fabs() for the abs value function,
https:
en.cppreference.com/w/cpp/numeric/math/fabs
• all variables should be type double
https:
en.cppreference.com/w/cpp/numeric/math/fabs
Examples
Archimedean Spiral, count=5, size = 1
Archimedean Spiral, count=10, size = 10
Fish size=1, rotation=1, count=5, offset=1.2
Fish size=2, rotation=4, count=5, offset=1.2
Mystery
??
Answered Same Day Nov 06, 2021

Solution

Ria answered on Nov 23 2021
146 Votes
#include #include #include using namespace std;
const double PI = 3.14159;
int main ()
{
    FILE *fp;
    int count = 5, size = 1;
    double x, y;
    fp = fopen ("archimedean.txt", "w");
    if (fp == NULL)
    {
        cout
"File cannot open.";
        exit (0);
    }
    for (float...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here