Click here to Skip to main content
16,006,348 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do I access a c# class from vc++? Pin
malayalite19-Nov-06 16:08
malayalite19-Nov-06 16:08 
AnswerRe: How do I access a c# class from vc++? Pin
Christian Graus19-Nov-06 17:00
protectorChristian Graus19-Nov-06 17:00 
GeneralRe: How do I access a c# class from vc++? Pin
malayalite19-Nov-06 18:27
malayalite19-Nov-06 18:27 
GeneralRe: How do I access a c# class from vc++? Pin
Christian Graus19-Nov-06 18:32
protectorChristian Graus19-Nov-06 18:32 
GeneralRe: How do I access a c# class from vc++? Pin
malayalite19-Nov-06 18:48
malayalite19-Nov-06 18:48 
Questionabout VC+MySQL problem:) Pin
rxgmoral19-Nov-06 15:13
rxgmoral19-Nov-06 15:13 
AnswerRe: about VC+MySQL problem:) Pin
Christian Graus19-Nov-06 15:21
protectorChristian Graus19-Nov-06 15:21 
Questionarray of functions of two parameters Pin
jquan3278619-Nov-06 4:27
jquan3278619-Nov-06 4:27 
Hi everyone!

I'm having trouble reading data from a text file. More specifically, I'm trying to read a function of two parameters from a text file and then pass it to an array of functions of two parameters.

This is what I have so far:

TextFile1.txt:

1+x*x+t*t*t 1.0 0.0 -4.0

Input.h:

//  Input.h<br />
#include <iostream><br />
#include <fstream><br />
using namespace std;<br />
// Input data from file<br />
void fin (double** (*f)(double, double), double* a, double* b, double* x, char* fin)<br />
{<br />
	ifstream file (fin);<br />
	file >> f[0] >> a[0] >> b[0] >> x[0];<br />
}


Problem 7 Ode.h:

//  Problem 7 Ode.h<br />
#include <cmath><br />
#include <iostream><br />
using namespace std; <br />
const double lambda = - 50;<br />
const int n = 20;<br />
class ode<br />
{<br />
	double tini;<br />
	double ison;<br />
	double tend;<br />
	double (*sfn)(double t, double x);<br />
public:<br />
	ode(double t0, double x0, double T, double (*f) (double t, double x)) <br />
	{<br />
		tini = t0;<br />
		ison = x0;<br />
		tend = T;<br />
		sfn = f;<br />
	} <br />
	double* rungekuttaforward (int n) const;<br />
	double* rungekuttabackward (int n) const;<br />
};<br />
double* ode::rungekuttaforward (int n) const<br />
{<br />
	double* x = new double [n + 1];<br />
	double * t = new double [n + 1];<br />
	t[0] = tini;<br />
	double h = (tend - tini) / n;<br />
	x[0] = ison;<br />
	for (int i = 0; i <= n; i++) <br />
	{<br />
		double K1 = h * sfn (t[i], x[i]);<br />
		double K2 = h * sfn (t[i] + h/2.0, x[i] + K1/2.0);<br />
		double K3 = h * sfn (t[i] + h/2.0, x[i] + K2/2.0);<br />
		double K4 = h * sfn (t[i] + h, x[i] + K3);<br />
		x[i+1] = x[i] + (K1 + 2.0 * K2 + 2.0 * K3 + K4) / 6.0;<br />
		cout << "i = " << i << "     " << "t = " << t[i] << "    " << "x = " << x[i] << "\n";<br />
		t[i+1] = t[i] + h;<br />
	}<br />
	return x;<br />
}<br />
double* ode::rungekuttabackward (int n) const<br />
{<br />
	double * x = new double [n + 1];<br />
	double * t = new double [n + 1];<br />
	t[n + 1] = tini;<br />
	double h = (tend - tini) / n;<br />
	x[n + 1] = ison;<br />
	for (int i = n + 1; i >= 1; i--)<br />
	{<br />
		double K1 = h * sfn (t[i], x[i]);<br />
		double K2 = h * sfn (t[i] + h/2.0, x[i] + K1/2.0);<br />
		double K3 = h * sfn (t[i] + h/2.0, x[i] + K2/2.0);<br />
		double K4 = h * sfn (t[i] + h, x[i] + K3);<br />
		x[i -1] = x[i] + (K1 + 2.0 * K2 + 2.0 * K3 + K4) / 6.0;<br />
		cout << "i = " << i << "     " << "t = " << t[i] << "    " << "x = " << x[i] << "\n";<br />
		t[i -1] = t[i] + h;<br />
	}<br />
	return x;<br />


Problem 7.cpp:

//  Problem 7.cpp<br />
/*<br />
ODE:  x' = 1 + x^2 + t^3<br />
Interval:  0 <= t <= 1<br />
initial condition:  x(1) = -4<br />
method:  Runge Kutta Order 4<br />
*/<br />
#include "Problem 7 Ode.h"<br />
#include "Input.h"<br />
#include <iostream><br />
using namespace std;<br />
void  (**f[1])(double, double);<br />
int main()<br />
{<br />
	//  Solution for [1, 2]<br />
	double a[1];<br />
	double b[1];<br />
	double x[1];<br />
	char *f_in = "TextFile1.txt";<br />
	fin (f, a, b, x, f_in);<br />
	ode part2(a[0], x[0], b[0], f[0]);<br />
	double* soln2 = part2.rungekuttaforward (n);<br />
	double h = (b[0] - a[0]) / n;<br />
}


This is what I get when I try to run the program:

------ Rebuild All started: Project: Assignment 4 - Problem 7, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Assignment 4 - Problem 7', configuration 'Debug|Win32'
Compiling...
Problem 7.cpp
c:\documents and settings\jessica ann quan\my documents\visual studio 2005\projects\assignment4\assignment 4 - problem 7\input.h(11) : error C2109: subscript requires array or pointer type
c:\documents and settings\jessica ann quan\my documents\visual studio 2005\projects\assignment4\assignment 4 - problem 7\problem 7.cpp(25) : error C2664: 'fin' : cannot convert parameter 1 from 'void (__cdecl **[1])(double,double)' to 'double **(__cdecl *)(double,double)'
There is no context in which this conversion is possible
c:\documents and settings\jessica ann quan\my documents\visual studio 2005\projects\assignment4\assignment 4 - problem 7\problem 7.cpp(27) : error C2664: 'ode::ode(double,double,double,double (__cdecl *)(double,double))' : cannot convert parameter 4 from 'void (__cdecl **)(double,double)' to 'double (__cdecl *)(double,double)'
There is no context in which this conversion is possible
Assignment 4 - Problem 7 - 3 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Any tips or insight in how to get this to run properly would be greatly appreciated!

Thanks!
AnswerRe: array of functions of two parameters Pin
Mark Salsbery19-Nov-06 7:13
Mark Salsbery19-Nov-06 7:13 
AnswerRe: array of functions of two parameters Pin
CPallini20-Nov-06 3:48
mveCPallini20-Nov-06 3:48 
QuestionDisplay Waveform of MP3 Pin
quantumdecipher19-Nov-06 2:11
quantumdecipher19-Nov-06 2:11 
Question--------- Pin
Irwin.R19-Nov-06 0:03
Irwin.R19-Nov-06 0:03 
AnswerRe: Setting File Permissions Pin
PJ Arends19-Nov-06 0:26
professionalPJ Arends19-Nov-06 0:26 
QuestionCBitmap(HBITMAP) conversion to raw RBG image. Pin
harripyy_118-Nov-06 23:48
harripyy_118-Nov-06 23:48 
AnswerRe: CBitmap(HBITMAP) conversion to raw RBG image. Pin
Waldermort19-Nov-06 0:47
Waldermort19-Nov-06 0:47 
GeneralRe: CBitmap(HBITMAP) conversion to raw RBG image. Pin
harripyy_119-Nov-06 1:47
harripyy_119-Nov-06 1:47 
Questionthe difference of using custom control and picture ? Pin
cyn818-Nov-06 23:10
cyn818-Nov-06 23:10 
AnswerRe: the difference of using custom control and picture ? Pin
Mark Salsbery19-Nov-06 5:58
Mark Salsbery19-Nov-06 5:58 
GeneralRe: the difference of using custom control and picture ? Pin
cyn819-Nov-06 14:12
cyn819-Nov-06 14:12 
GeneralRe: the difference of using custom control and picture ? Pin
Christian Graus19-Nov-06 14:21
protectorChristian Graus19-Nov-06 14:21 
GeneralRe: the difference of using custom control and picture ? Pin
Mark Salsbery19-Nov-06 14:23
Mark Salsbery19-Nov-06 14:23 
GeneralRe: the difference of using custom control and picture ? Pin
cyn819-Nov-06 14:44
cyn819-Nov-06 14:44 
GeneralRe: the difference of using custom control and picture ? Pin
Mark Salsbery20-Nov-06 5:03
Mark Salsbery20-Nov-06 5:03 
QuestionHashing algorithms Pin
Waldermort18-Nov-06 20:51
Waldermort18-Nov-06 20:51 
AnswerRe: Hashing algorithms Pin
PJ Arends18-Nov-06 23:44
professionalPJ Arends18-Nov-06 23:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.