C++ Function

Can Someone help me. I am not a computer major, but need only one semester of c++ as a chem science major. Please tell me if I completed the coding correctly per instructions.

Write a program that
1)define a function of your choice using a subroutine (eg sin, parabola exp)
2)define two arrays of 100 points to store x and f(x). Call them for example x and y.
3)store using a loop in the arrays x values (equally spaced, e.g. 1) and the corresponding f(x) values in the y array
4) create a graph using TGraph (100 points) with x and y
5) create a canvas TCanvas
6)Draw the graph ( don't forget to use the options AP*)
7)create a function in root TF1 that is the same as in point 1
8)draw it on top of the graph using Draw with the option "same"

I cried in class because my teacher wrote this on my coding:
//this is not the program you were supposed to write, you were supposed to write a program making a graph with arrays and overlap a curve used for generating the points.

Please help me. Thank you


#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdio>

#include "TROOT.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TApplication.h"
#include "TRint.h"
#include "TF1.h"

using namespace std;

#define NPOINTS 100
float y (float x);

int main(int argc, char **argv){

//ROOT stuff

TRint theApp("App",&argc,argv);
TCanvas *c = new TCanvas("c", "Solution", 400, 400);

TF1 *f=new TF1("fun","x^2+2*x",0,5);

f->SetLineColor(38);
f->Draw();
c->Update();
theApp.Run();

}



Are you asking us to do your assignment for you? I can't do that for you. It looks like this is a very advanced lesson--how have you been completing the lessons if you can't figure this one out(not to say this one is easy)?
Topic archived. No new replies allowed.