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 »
can i get help pls


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 stubbed 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 required 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 error 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 0.0453596 0.0891207 0.0724716 0.186408 figure 1:wikipedia 0.0802496 0.289067 0.0679869 0.39418 0.0353686 0.498747 -0.0175197 0.599744 -0.0901911 0.694165 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 error 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 returns. 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 2.9925 0.0998334 2.97007 0.198669 2.93288 0.29552 2.88119 0.389418 2.81541 0.479426 2.73601 0.564642 2.64359 0.644218 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 range 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-12 -9.13406 -1.87666e-05 -9.11984 -7.50662e-05 -9.10561 -0.000168898 -9.09135 -0.000300263 -9.07706 -0.000469158 -9.06275 -0.000675583 -9.04841 -0.000919537 -9.03405 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. remember • 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 libraries cmath and cstdlib • 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 ?? (count∗2∗π)="" t="" steps="" by="" 0.1="" example="" of="" archimedean.txt="" for="" count="5," size="1" (first="" 8="" lines="" shown)="" 0="" 0="" 0.0453596="" 0.0891207="" 0.0724716="" 0.186408="" figure="" 1:wikipedia="" 0.0802496="" 0.289067="" 0.0679869="" 0.39418="" 0.0353686="" 0.498747="" -0.0175197="" 0.599744="" -0.0901911="" 0.694165="" 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="" error="" 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="" returns.="" 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="" 2.9925="" 0.0998334="" 2.97007="" 0.198669="" 2.93288="" 0.29552="" 2.88119="" 0.389418="" 2.81541="" 0.479426="" 2.73601="" 0.564642="" 2.64359="" 0.644218="" 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="" range="" 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-12="" -9.13406="" -1.87666e-05="" -9.11984="" -7.50662e-05="" -9.10561="" -0.000168898="" -9.09135="" -0.000300263="" -9.07706="" -0.000469158="" -9.06275="" -0.000675583="" -9.04841="" -0.000919537="" -9.03405="" 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.="" remember="" •="" 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="" libraries="" cmath="" and="" cstdlib="" •="" 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 DayNov 06, 2021

Answer To: CS 135 – Assignment #8 Revision 1 Purpose: Become familiar with value returning functions, file...

Ria answered on Nov 23 2021
147 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