SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
Modify the code in C Please!
/*------------------------------------------------------------------
File: plotFunctions.c
Author: Gilbert Arbez, Fall 2016
Description: Allows the user to plot a number of functions for
different ranges.
---------------------------------------------------------------------*/
#include <stdio.h>
#include <gng1106plplot.h> // provides definitions for using PLplot library
#include <math.h>
#include <float.h>
// Some definitions
#define NUM_POINTS 500 // Number of points used for plotting
#define X_IX 0 // Row index for storing x values
#define FX_IX 1 // Row index for storing f(x) values
#define TRUE 1
#define FALSE 0
// Structure for user input
typedef struct
{
int fNumber; // function number
double x0; // first value of x to plot
double xf; // final value of x to plot
} F_SELECT;
// function prototypes
void selectFunction(F_SELECT *);
void computeDataPoints(F_SELECT *fsPtr, int n, double [][n]);
double calcFx(double, int);
void plot(int n, double [][n]);
double getMinDouble(double [], int);
double getMaxDouble(double [], int);
/*---------------------------------------------------------------------
Function: main
Description: This function computes a set of points for plotting. The
function calcFx is called to computes the value of f(x) .
Modify calcFx to compute the values of f(x) desired.
In this template, the sin function is used.
------------------------------------------------------------------------*/
void main(void)
{
// Variable declarations
F_SELECT fselect;
double points[2][NUM_POINTS]; // row 0 contains values of x
// Get user input
selectFunction(&fselect);
// Compute the data points and save in array
computeDataPoints(&fselect, NUM_POINTS, points);
// Call plot function to plot
plot(NUM_POINTS, points);
}
/*-----------------------------------------------------------------------
Function: selectFunction
Parameters:
sfPtr - Pointer to F_SELECT structure variable to store input data.
Description: Prompts the user to get x0 and xf (range of x for plotting)
and to select a function to plot.
------------------------------------------------------------------------*/
void selectFunction(F_SELECT *sfPtr)
{
// Variable Declarations
int flag;
// Display function menu
printf("1) f(x) = sqrt(|x-1|) + 1n");
printf("2) f(x) = exp(-x)n");
printf("3) f(x) = sqrt(x^2+1) - xn");
printf("4) f(x) = [exp(-x) - 1)]/xn");
printf("5) f(x) = sin(x)+0.1*cos(10.0*x)n");
// Select a function
// Select a range of x for plotting
}
/*-----------------------------------------------------------------------
Function: computeDataPoints
Parameters:
fsPtr - Pointer to F_SELECT structure variable with input data.
n - number of points in the 2D array (i.e. number of columns)
points - 2D array that contains the data points - row X_IX with x values
and row FX_IX with the f(x) values.
Description: Calculates NUM_POINTS points of the function f(x) (selected by the
the user and computed with calcFx), and stored in the
2D array points. points[X_IX] is the 1D array (row X_IX) that
contains the x values while points[FX_IX] is the 1D array (row FX_IX)
that contains the f(x) values.
------------------------------------------------------------------------*/
void computeDataPoints(F_SELECT *fsPtr, int n, double points[][n])
{
int ix; // for indexing points, i.e. columns of 2D array
double x; // for incrementing the value of x
double inc; // incrementation value of x
// Setup loop that computes the points and stores in 2D array
// A determinant loop is used to increment x, calculate f(x)
// and store the values in the 2D array.
}
/*-----------------------------------------------------------------------
Function: calcFx
Parameters:
x - the value of x
funtionNum - function number to select function for calculation
Return: The value of f(x)
Description: Calculates the value of f(x). In this case f(x) is selected
using functionNum.
------------------------------------------------------------------------*/
double calcFx(double x)
{
// Variable declations
double fx;
// Instructions
fx = sin(x);
return(fx);
}
/*-------------------------------------------------
Function: plot()
Parameters:
numPoints: number of points in the array, i.e. number of columns
points: reference to 2D array
Return value: none.
Description: Initializes the plot. The following values
in the referenced structure are used to setup
the plot:
points[X_IX][0], points[X_IX][nbrPoints-1] range of horizontal axis
minFx, maxFx - vertical axis range
Note the that the values of minFx and maxFx are determined with
the functions getMinDouble and getMaxDouble. The values in the row
X_IX are assumed to be sorted in increasing order.
Then plots the curve accessed using the contents of each row,
that is, points[X_IX] and points[FX_IX] which are both references
to 1D arrays.
-------------------------------------------------*/
void plot(int numPoints, double points[][numPoints])
{
// Variable declaration
double minFx, maxFx; // Minimum and maximum values of f(x)
// Setup plot configuration
plsdev("wingcc"); // Sets device to wingcc - CodeBlocks compiler
// Initialize the plot
plinit();
// Configure the axis and labels
plwidth(3); // select the width of the pen
minFx = getMinDouble(points[FX_IX], numPoints);
maxFx = getMaxDouble(points[FX_IX], numPoints);
plenv(points[X_IX][0],points[X_IX][numPoints-1],
minFx, maxFx, 0, 0);
plcol0(GREEN); // Select color for labels
pllab("x", "f(x)", "Plot of f(x) versus x");
// Plot the function.
plcol0(BLUE); // Color for plotting curve
plline(numPoints, points[X_IX], points[FX_IX]);
plend();
}
/*-------------------------------------------------
Function: getMinDouble
Parameters:
arr: reference to array of double values
n: number of elements in the array
Return value: the smallest value found in the array.
Description: Finds the smallest value in the array.
Uses a determinate loop to traverse the array
to test each value in the array.
-------------------------------------------------*/
double getMinDouble(double arr[], int n)
{
// Variable declarations
double min; // for storing minimum value
int ix; // indexing into an array
// Instructions
min = DBL_MAX; // most positive value for type double
for(ix = 0; ix < n; ix = ix + 1)
{
if(min > arr[ix]) min = arr[ix];
}
return(min);
}
/*-------------------------------------------------
Function: getMaxDouble
Parameters:
arr: reference to array of double values
n: number of elements in the array
Return value: the largest value found in the array.
Description: Finds the largest value in the array.
Uses a determinate loop to traverse the array
to test each value in the array.
-------------------------------------------------*/
double getMaxDouble(double arr[], int n)
{
// Variable declarations
double max; // for storing maximum value
int ix; // indexing into an array
// Instructions
max = -DBL_MAX; // most negative value for type double
for(ix = 0; ix < n; ix = ix + 1)
{
if(max < arr[ix]) max = arr[ix];
}
return(max);
}
C. Exercise: Plotting Functions (10 marks) Plotting is important in engineering and science for
displaying results. In this exercise, you shall be creating software that allows a user to plot one of
the five following functions, f(x) for any desired range of x. f(x)=x1+1f(x)=exf(x)=x2+1xf(x)=xex1f(x)
=sin(x)+0.1cos(10x) To include and have access to the plotting library PLplot, you must create a
CodeBlocks project with the PLplot configuration. When creating the CodeBlocks project, click on
"C Console App/PLplot" icon, on the Go button to start the project Wizard. You will note that the
template software included in this project can be compiled and executed. It will plot a sine wave as
follows: A partially completed plotting project is provided in the zipped file PlotFunctions.zip.
Download the file, unzip it, and open the project in CodeBlocks. The program will allow the user to
select one of the five functions presented above and give a range of values for x for plotting. A plot
will be generated according to the user selections. The following are guidelines will help with this
completing the program: 1. The structure type F_SELECT is defined to store input from the user,
which consists of the range of values for x,x0 and xf, as well as a function number (fNumber)
which identifies the number to plot. The following is an example of the interaction with the user to
obtain these three values: 2. Complete the function selectFunction to implement the above
interaction. Ensure that the error message is display if the user enters a value outside the valid
range (1 to 5) and prompt the user for a correct value. 3. Complete the function
computeDatapoints that will fill in the 2D array. a. Compute the increment value to increment the
value of x (i.e. the value of inc) using xf,x0 (members of the F_SELECT structure), and n (number
of points to compute). Note that there are only n1 increments to obtain n points. b. When creating
the loop to fill in the array, use the ix to control the loop, not x. Using real values to control a loop is
more difficult that using integer values. c. Use the XIX and FX _IX symbolic constants for the row
index of the 2D array points. 4. Modify calcEx to compute the value of f(x) given a function number
(provided by the user). (The version given comes from the project template).a. You will need to
change the parameter list to include a function number. b. Use a decision/branching instruction to
use the proper function for computing the value of f(x). c. Don't forget to update the function
prototype. 5. Modify the plot function to make changes to the plot as follows: a. Draw axes at x=0
and y=0 (hint, see the plenv function). b. Change the color of the text labels. c. Change the color
of the plotted curve. d. Thicken the line of the plotted curve without changing the thickness of text
or axes. e. Notice the arguments of the plline function call and discuss to understand what is being
passed to the function. 6. Show and explain your code and running program to the TAs for marks.
7. If you have time, consider trying the following modifications: a. Change the line style, e.g. use a
dashed line (note that the thickness of the line may hide the line style). b. Add text which gives the
function plotted, either in the title or for an additional challenge in the plot itself. The following are
some example plots that your program should produce. Function 1,f(x)=x1+1:5 to +5 Function 3, f(
x)=x2+1x:0.5 to +2 Function 4,f(x)=xex1:1 to +20 Function 5,f(x)=sin(x)+0.1cos(10x):3.14 to +6.28

Mais conteúdo relacionado

Semelhante a Modify the code in C Please .pdf

GSP 215 Effective Communication - tutorialrank.com
GSP 215  Effective Communication - tutorialrank.comGSP 215  Effective Communication - tutorialrank.com
GSP 215 Effective Communication - tutorialrank.comBartholomew35
 
C standard library functions
C standard library functionsC standard library functions
C standard library functionsVaishnavee Sharma
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3JenniferBall44
 
Gsp 215 Believe Possibilities / snaptutorial.com
Gsp 215  Believe Possibilities / snaptutorial.comGsp 215  Believe Possibilities / snaptutorial.com
Gsp 215 Believe Possibilities / snaptutorial.comStokesCope20
 
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxjack60216
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.comHarrisGeorg21
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
CJPCCS BCA VISNAGAR functions in C language
CJPCCS BCA VISNAGAR  functions in C languageCJPCCS BCA VISNAGAR  functions in C language
CJPCCS BCA VISNAGAR functions in C languageFCSCJCS
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.comjonhson300
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comjonhson129
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college2017eee0459
 

Semelhante a Modify the code in C Please .pdf (20)

Qe Reference
Qe ReferenceQe Reference
Qe Reference
 
GSP 215 Effective Communication - tutorialrank.com
GSP 215  Effective Communication - tutorialrank.comGSP 215  Effective Communication - tutorialrank.com
GSP 215 Effective Communication - tutorialrank.com
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
Linked list
Linked listLinked list
Linked list
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Andes open cl for RISC-V
Andes open cl for RISC-VAndes open cl for RISC-V
Andes open cl for RISC-V
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3
 
Gsp 215 Believe Possibilities / snaptutorial.com
Gsp 215  Believe Possibilities / snaptutorial.comGsp 215  Believe Possibilities / snaptutorial.com
Gsp 215 Believe Possibilities / snaptutorial.com
 
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docxECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
ECS 40 Program #3 (50 points, my time 1.5 hours) Spring 2015 .docx
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.com
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
C++_notes.pdf
C++_notes.pdfC++_notes.pdf
C++_notes.pdf
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
CJPCCS BCA VISNAGAR functions in C language
CJPCCS BCA VISNAGAR  functions in C languageCJPCCS BCA VISNAGAR  functions in C language
CJPCCS BCA VISNAGAR functions in C language
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.com
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.com
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 

Mais de adityaenterprise32

Most plant leaves in rainforest are thick and with waxy surf.pdf
Most plant leaves in rainforest are thick and with waxy surf.pdfMost plant leaves in rainforest are thick and with waxy surf.pdf
Most plant leaves in rainforest are thick and with waxy surf.pdfadityaenterprise32
 
Most PCcompatible computer systems use a 20bit address cod.pdf
Most PCcompatible computer systems use a 20bit address cod.pdfMost PCcompatible computer systems use a 20bit address cod.pdf
Most PCcompatible computer systems use a 20bit address cod.pdfadityaenterprise32
 
Most exoplanets found are much more massive than Earth and .pdf
Most exoplanets found are much more massive than Earth and .pdfMost exoplanets found are much more massive than Earth and .pdf
Most exoplanets found are much more massive than Earth and .pdfadityaenterprise32
 
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdf
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdfMoodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdf
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdfadityaenterprise32
 
More effort needs to be put into the search and selection of.pdf
More effort needs to be put into the search and selection of.pdfMore effort needs to be put into the search and selection of.pdf
More effort needs to be put into the search and selection of.pdfadityaenterprise32
 
Morgan Barron is the best player on the Cornell University h.pdf
Morgan Barron is the best player on the Cornell University h.pdfMorgan Barron is the best player on the Cornell University h.pdf
Morgan Barron is the best player on the Cornell University h.pdfadityaenterprise32
 
Moosehead based in New Brunswick is the largest Canadiano.pdf
Moosehead based in New Brunswick is the largest Canadiano.pdfMoosehead based in New Brunswick is the largest Canadiano.pdf
Moosehead based in New Brunswick is the largest Canadiano.pdfadityaenterprise32
 
Month Based on this Climagraph from Columbia SC how would.pdf
Month Based on this Climagraph from Columbia SC  how would.pdfMonth Based on this Climagraph from Columbia SC  how would.pdf
Month Based on this Climagraph from Columbia SC how would.pdfadityaenterprise32
 
Monty Corp has 8000 shares of common stock outstanding It.pdf
Monty Corp has 8000 shares of common stock outstanding It.pdfMonty Corp has 8000 shares of common stock outstanding It.pdf
Monty Corp has 8000 shares of common stock outstanding It.pdfadityaenterprise32
 
Monstruos inc Mientras mira la pelcula busque elementos d.pdf
Monstruos inc  Mientras mira la pelcula busque elementos d.pdfMonstruos inc  Mientras mira la pelcula busque elementos d.pdf
Monstruos inc Mientras mira la pelcula busque elementos d.pdfadityaenterprise32
 
Mom were here Sorry were a little late Theyre more t.pdf
Mom were here Sorry were a little late Theyre more t.pdfMom were here Sorry were a little late Theyre more t.pdf
Mom were here Sorry were a little late Theyre more t.pdfadityaenterprise32
 
Money supply endogeneity and financial instability are two p.pdf
Money supply endogeneity and financial instability are two p.pdfMoney supply endogeneity and financial instability are two p.pdf
Money supply endogeneity and financial instability are two p.pdfadityaenterprise32
 
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdf
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdfMonosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdf
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdfadityaenterprise32
 
Monopolistic competition is a market structure very much lik.pdf
Monopolistic competition is a market structure very much lik.pdfMonopolistic competition is a market structure very much lik.pdf
Monopolistic competition is a market structure very much lik.pdfadityaenterprise32
 
Moira has to be at the office from 93 but she gets to choo.pdf
Moira has to be at the office from 93 but she gets to choo.pdfMoira has to be at the office from 93 but she gets to choo.pdf
Moira has to be at the office from 93 but she gets to choo.pdfadityaenterprise32
 
Moira has to be at the office from 93 but she gets to choos.pdf
Moira has to be at the office from 93 but she gets to choos.pdfMoira has to be at the office from 93 but she gets to choos.pdf
Moira has to be at the office from 93 but she gets to choos.pdfadityaenterprise32
 
Module 1 test 101316 10 What are 3 types of nase lsted in .pdf
Module 1 test 101316 10 What are 3 types of nase lsted in .pdfModule 1 test 101316 10 What are 3 types of nase lsted in .pdf
Module 1 test 101316 10 What are 3 types of nase lsted in .pdfadityaenterprise32
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfadityaenterprise32
 
Module 5 Case study Reas the foliewing Case study and answer.pdf
Module 5 Case study Reas the foliewing Case study and answer.pdfModule 5 Case study Reas the foliewing Case study and answer.pdf
Module 5 Case study Reas the foliewing Case study and answer.pdfadityaenterprise32
 
Modify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdfModify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdfadityaenterprise32
 

Mais de adityaenterprise32 (20)

Most plant leaves in rainforest are thick and with waxy surf.pdf
Most plant leaves in rainforest are thick and with waxy surf.pdfMost plant leaves in rainforest are thick and with waxy surf.pdf
Most plant leaves in rainforest are thick and with waxy surf.pdf
 
Most PCcompatible computer systems use a 20bit address cod.pdf
Most PCcompatible computer systems use a 20bit address cod.pdfMost PCcompatible computer systems use a 20bit address cod.pdf
Most PCcompatible computer systems use a 20bit address cod.pdf
 
Most exoplanets found are much more massive than Earth and .pdf
Most exoplanets found are much more massive than Earth and .pdfMost exoplanets found are much more massive than Earth and .pdf
Most exoplanets found are much more massive than Earth and .pdf
 
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdf
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdfMoodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdf
Moodys Aaa irket tahvili getirisi ile 10 yllk ABD Hazine ta.pdf
 
More effort needs to be put into the search and selection of.pdf
More effort needs to be put into the search and selection of.pdfMore effort needs to be put into the search and selection of.pdf
More effort needs to be put into the search and selection of.pdf
 
Morgan Barron is the best player on the Cornell University h.pdf
Morgan Barron is the best player on the Cornell University h.pdfMorgan Barron is the best player on the Cornell University h.pdf
Morgan Barron is the best player on the Cornell University h.pdf
 
Moosehead based in New Brunswick is the largest Canadiano.pdf
Moosehead based in New Brunswick is the largest Canadiano.pdfMoosehead based in New Brunswick is the largest Canadiano.pdf
Moosehead based in New Brunswick is the largest Canadiano.pdf
 
Month Based on this Climagraph from Columbia SC how would.pdf
Month Based on this Climagraph from Columbia SC  how would.pdfMonth Based on this Climagraph from Columbia SC  how would.pdf
Month Based on this Climagraph from Columbia SC how would.pdf
 
Monty Corp has 8000 shares of common stock outstanding It.pdf
Monty Corp has 8000 shares of common stock outstanding It.pdfMonty Corp has 8000 shares of common stock outstanding It.pdf
Monty Corp has 8000 shares of common stock outstanding It.pdf
 
Monstruos inc Mientras mira la pelcula busque elementos d.pdf
Monstruos inc  Mientras mira la pelcula busque elementos d.pdfMonstruos inc  Mientras mira la pelcula busque elementos d.pdf
Monstruos inc Mientras mira la pelcula busque elementos d.pdf
 
Mom were here Sorry were a little late Theyre more t.pdf
Mom were here Sorry were a little late Theyre more t.pdfMom were here Sorry were a little late Theyre more t.pdf
Mom were here Sorry were a little late Theyre more t.pdf
 
Money supply endogeneity and financial instability are two p.pdf
Money supply endogeneity and financial instability are two p.pdfMoney supply endogeneity and financial instability are two p.pdf
Money supply endogeneity and financial instability are two p.pdf
 
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdf
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdfMonosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdf
Monosodyum glutamat MSG glutamatn bir sodyum tuzu ve yayg.pdf
 
Monopolistic competition is a market structure very much lik.pdf
Monopolistic competition is a market structure very much lik.pdfMonopolistic competition is a market structure very much lik.pdf
Monopolistic competition is a market structure very much lik.pdf
 
Moira has to be at the office from 93 but she gets to choo.pdf
Moira has to be at the office from 93 but she gets to choo.pdfMoira has to be at the office from 93 but she gets to choo.pdf
Moira has to be at the office from 93 but she gets to choo.pdf
 
Moira has to be at the office from 93 but she gets to choos.pdf
Moira has to be at the office from 93 but she gets to choos.pdfMoira has to be at the office from 93 but she gets to choos.pdf
Moira has to be at the office from 93 but she gets to choos.pdf
 
Module 1 test 101316 10 What are 3 types of nase lsted in .pdf
Module 1 test 101316 10 What are 3 types of nase lsted in .pdfModule 1 test 101316 10 What are 3 types of nase lsted in .pdf
Module 1 test 101316 10 What are 3 types of nase lsted in .pdf
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 
Module 5 Case study Reas the foliewing Case study and answer.pdf
Module 5 Case study Reas the foliewing Case study and answer.pdfModule 5 Case study Reas the foliewing Case study and answer.pdf
Module 5 Case study Reas the foliewing Case study and answer.pdf
 
Modify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdfModify the Simple lexer program given in the link below to .pdf
Modify the Simple lexer program given in the link below to .pdf
 

Último

How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 

Último (20)

How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 

Modify the code in C Please .pdf

  • 1. Modify the code in C Please! /*------------------------------------------------------------------ File: plotFunctions.c Author: Gilbert Arbez, Fall 2016 Description: Allows the user to plot a number of functions for different ranges. ---------------------------------------------------------------------*/ #include <stdio.h> #include <gng1106plplot.h> // provides definitions for using PLplot library #include <math.h> #include <float.h> // Some definitions #define NUM_POINTS 500 // Number of points used for plotting #define X_IX 0 // Row index for storing x values #define FX_IX 1 // Row index for storing f(x) values #define TRUE 1 #define FALSE 0 // Structure for user input typedef struct { int fNumber; // function number double x0; // first value of x to plot double xf; // final value of x to plot } F_SELECT; // function prototypes void selectFunction(F_SELECT *); void computeDataPoints(F_SELECT *fsPtr, int n, double [][n]); double calcFx(double, int); void plot(int n, double [][n]); double getMinDouble(double [], int); double getMaxDouble(double [], int); /*--------------------------------------------------------------------- Function: main Description: This function computes a set of points for plotting. The function calcFx is called to computes the value of f(x) . Modify calcFx to compute the values of f(x) desired. In this template, the sin function is used. ------------------------------------------------------------------------*/ void main(void) { // Variable declarations F_SELECT fselect;
  • 2. double points[2][NUM_POINTS]; // row 0 contains values of x // Get user input selectFunction(&fselect); // Compute the data points and save in array computeDataPoints(&fselect, NUM_POINTS, points); // Call plot function to plot plot(NUM_POINTS, points); } /*----------------------------------------------------------------------- Function: selectFunction Parameters: sfPtr - Pointer to F_SELECT structure variable to store input data. Description: Prompts the user to get x0 and xf (range of x for plotting) and to select a function to plot. ------------------------------------------------------------------------*/ void selectFunction(F_SELECT *sfPtr) { // Variable Declarations int flag; // Display function menu printf("1) f(x) = sqrt(|x-1|) + 1n"); printf("2) f(x) = exp(-x)n"); printf("3) f(x) = sqrt(x^2+1) - xn"); printf("4) f(x) = [exp(-x) - 1)]/xn"); printf("5) f(x) = sin(x)+0.1*cos(10.0*x)n"); // Select a function // Select a range of x for plotting } /*----------------------------------------------------------------------- Function: computeDataPoints Parameters: fsPtr - Pointer to F_SELECT structure variable with input data. n - number of points in the 2D array (i.e. number of columns) points - 2D array that contains the data points - row X_IX with x values and row FX_IX with the f(x) values. Description: Calculates NUM_POINTS points of the function f(x) (selected by the the user and computed with calcFx), and stored in the 2D array points. points[X_IX] is the 1D array (row X_IX) that contains the x values while points[FX_IX] is the 1D array (row FX_IX) that contains the f(x) values. ------------------------------------------------------------------------*/
  • 3. void computeDataPoints(F_SELECT *fsPtr, int n, double points[][n]) { int ix; // for indexing points, i.e. columns of 2D array double x; // for incrementing the value of x double inc; // incrementation value of x // Setup loop that computes the points and stores in 2D array // A determinant loop is used to increment x, calculate f(x) // and store the values in the 2D array. } /*----------------------------------------------------------------------- Function: calcFx Parameters: x - the value of x funtionNum - function number to select function for calculation Return: The value of f(x) Description: Calculates the value of f(x). In this case f(x) is selected using functionNum. ------------------------------------------------------------------------*/ double calcFx(double x) { // Variable declations double fx; // Instructions fx = sin(x); return(fx); } /*------------------------------------------------- Function: plot() Parameters: numPoints: number of points in the array, i.e. number of columns points: reference to 2D array Return value: none. Description: Initializes the plot. The following values in the referenced structure are used to setup the plot: points[X_IX][0], points[X_IX][nbrPoints-1] range of horizontal axis minFx, maxFx - vertical axis range Note the that the values of minFx and maxFx are determined with the functions getMinDouble and getMaxDouble. The values in the row X_IX are assumed to be sorted in increasing order. Then plots the curve accessed using the contents of each row, that is, points[X_IX] and points[FX_IX] which are both references
  • 4. to 1D arrays. -------------------------------------------------*/ void plot(int numPoints, double points[][numPoints]) { // Variable declaration double minFx, maxFx; // Minimum and maximum values of f(x) // Setup plot configuration plsdev("wingcc"); // Sets device to wingcc - CodeBlocks compiler // Initialize the plot plinit(); // Configure the axis and labels plwidth(3); // select the width of the pen minFx = getMinDouble(points[FX_IX], numPoints); maxFx = getMaxDouble(points[FX_IX], numPoints); plenv(points[X_IX][0],points[X_IX][numPoints-1], minFx, maxFx, 0, 0); plcol0(GREEN); // Select color for labels pllab("x", "f(x)", "Plot of f(x) versus x"); // Plot the function. plcol0(BLUE); // Color for plotting curve plline(numPoints, points[X_IX], points[FX_IX]); plend(); } /*------------------------------------------------- Function: getMinDouble Parameters: arr: reference to array of double values n: number of elements in the array Return value: the smallest value found in the array. Description: Finds the smallest value in the array. Uses a determinate loop to traverse the array to test each value in the array. -------------------------------------------------*/ double getMinDouble(double arr[], int n) { // Variable declarations double min; // for storing minimum value int ix; // indexing into an array // Instructions min = DBL_MAX; // most positive value for type double for(ix = 0; ix < n; ix = ix + 1) {
  • 5. if(min > arr[ix]) min = arr[ix]; } return(min); } /*------------------------------------------------- Function: getMaxDouble Parameters: arr: reference to array of double values n: number of elements in the array Return value: the largest value found in the array. Description: Finds the largest value in the array. Uses a determinate loop to traverse the array to test each value in the array. -------------------------------------------------*/ double getMaxDouble(double arr[], int n) { // Variable declarations double max; // for storing maximum value int ix; // indexing into an array // Instructions max = -DBL_MAX; // most negative value for type double for(ix = 0; ix < n; ix = ix + 1) { if(max < arr[ix]) max = arr[ix]; } return(max); } C. Exercise: Plotting Functions (10 marks) Plotting is important in engineering and science for displaying results. In this exercise, you shall be creating software that allows a user to plot one of the five following functions, f(x) for any desired range of x. f(x)=x1+1f(x)=exf(x)=x2+1xf(x)=xex1f(x) =sin(x)+0.1cos(10x) To include and have access to the plotting library PLplot, you must create a CodeBlocks project with the PLplot configuration. When creating the CodeBlocks project, click on "C Console App/PLplot" icon, on the Go button to start the project Wizard. You will note that the template software included in this project can be compiled and executed. It will plot a sine wave as follows: A partially completed plotting project is provided in the zipped file PlotFunctions.zip. Download the file, unzip it, and open the project in CodeBlocks. The program will allow the user to select one of the five functions presented above and give a range of values for x for plotting. A plot will be generated according to the user selections. The following are guidelines will help with this completing the program: 1. The structure type F_SELECT is defined to store input from the user, which consists of the range of values for x,x0 and xf, as well as a function number (fNumber) which identifies the number to plot. The following is an example of the interaction with the user to obtain these three values: 2. Complete the function selectFunction to implement the above
  • 6. interaction. Ensure that the error message is display if the user enters a value outside the valid range (1 to 5) and prompt the user for a correct value. 3. Complete the function computeDatapoints that will fill in the 2D array. a. Compute the increment value to increment the value of x (i.e. the value of inc) using xf,x0 (members of the F_SELECT structure), and n (number of points to compute). Note that there are only n1 increments to obtain n points. b. When creating the loop to fill in the array, use the ix to control the loop, not x. Using real values to control a loop is more difficult that using integer values. c. Use the XIX and FX _IX symbolic constants for the row index of the 2D array points. 4. Modify calcEx to compute the value of f(x) given a function number (provided by the user). (The version given comes from the project template).a. You will need to change the parameter list to include a function number. b. Use a decision/branching instruction to use the proper function for computing the value of f(x). c. Don't forget to update the function prototype. 5. Modify the plot function to make changes to the plot as follows: a. Draw axes at x=0 and y=0 (hint, see the plenv function). b. Change the color of the text labels. c. Change the color of the plotted curve. d. Thicken the line of the plotted curve without changing the thickness of text or axes. e. Notice the arguments of the plline function call and discuss to understand what is being passed to the function. 6. Show and explain your code and running program to the TAs for marks. 7. If you have time, consider trying the following modifications: a. Change the line style, e.g. use a dashed line (note that the thickness of the line may hide the line style). b. Add text which gives the function plotted, either in the title or for an additional challenge in the plot itself. The following are some example plots that your program should produce. Function 1,f(x)=x1+1:5 to +5 Function 3, f( x)=x2+1x:0.5 to +2 Function 4,f(x)=xex1:1 to +20 Function 5,f(x)=sin(x)+0.1cos(10x):3.14 to +6.28