Completely lost

So I have an asignment in which my teacher is wanting us to find the derivative and the integral of a function using pointers, however, I am struggling to understand where and how to use pointers. Can anyone help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <fstream>

#include "Poly.h"
#include "Keyboard.h"

using namespace std;

int main()
{
char file_name[25];
double Function;
int max_length = 20;
double * poly;
int degree;


readPoly(file_name, degree, max_length);
polyDerivative(poly, degree);
polyIntegral(poly, degree);

double poly_coeffs[degree];

printPoly(poly_coeffs, degree);

return 0;
}

double* readPoly(char file_name[], int& degree, int max_length)
{

	readString("Enter the file containing the polynomial coefficients: ", file_name, max_length);
	
	ifstream input_file;
	input_file.open(file_name);

	input_file >> degree;
	
	double* ptr = new double [degree + 1];
	
	for (int i = degree; i >= 0; i--)
		{
			input_file >> ptr[i];
		}

	input_file.close();
   
	return ptr;
}


double* polyDerivative(double* poly, int degree)
{
	for (int i = degree; i >= 0; i--)
		{
		
		}
		
		cout << "The derivative of the polynomial: " << endl;
		
}

double* polyIntegral(double* poly, int degree)
{
	for (int i = degree; i >= 0; i--)
		{
		
		}
		
		cout << "The integral of the polynomial (integration constant set to 0): " << endl;
}

void printPoly(double poly_coeffs[], int degree)
{
	cout << "The polynomial you entered: " << endl;
	
	    for(int i = degree; i > 0 ; i--)
		{
		  cout << poly_coeffs[i] << "x^" << i << " + "; 
		}
	    cout << poly_coeffs[0] << "x^0" << endl; 
}
}
Last edited on
Of course the polyDerivative and the polyIntegral functions are incomplete due to readPoly being incomplete.
Please use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

Are you sure your instructor did not give more specific instructions than just "do x using pointers"? That's very vague and could mean anything, there's no way to tell what your instructor actually expects.
We have been going over pointers and all he gave us was the function declarations. He has always been like this where he gives very vague instructions on how to complete his assignments.
Topic archived. No new replies allowed.