I have an MFC application (VS2005) with splitter window (one is the view other is a formview). you can select from the main menu different math operation on polynoms and polynoms shows on the formview. you can then calculate and the result is shown in the view. The class CalculsPolynoms above is working just fine for all operations except Multiplier(), the line myPoly->AfficherResult at(p_resultat, 11); brings me to AfficherResulta t(...) and the pDoc->msgLine5 is breaking and bringing me to atlsimpstr.h line 812.
Unhandled exception at 0x78325e5a (mfc80ud.dll) in TP2.exe: 0xC0000005: Access violation reading location 0x00000064.
It works fine for all other functions except this one and I can not figure out why.
Any help would be greatly appreciated.
// *************** *************** ****CalculsPoly nomes.cpp
#include "StdAfx.h"
#include "CalculsPolynom es.h"
CCalculsPolynom es::CCalculsPol ynomes(void)
{
}
CCalculsPolynom es::~CCalculsPo lynomes(void)
{
}
void CCalculsPolynom es::Additionner (double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "+";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += "X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Additonner
double resultat[6];
double* p_resultat[6];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
double g = *gx[i];
resultat[i] = f + g;
p_resultat[i] = &resultat[i];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 6);
}
void CCalculsPolynom es::Soustraire( double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "-";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _______________ _";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += " X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += " X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Soustraire
double resultat[6];
double* p_resultat[6];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
double g = *gx[i];
resultat[i] = f - g;
p_resultat[i] = &resultat[i];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 6);
}
void CCalculsPolynom es::Multiplier( double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "+";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += "X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Multiplier
double resultatM[11];
for(int i = 0; i < 11; ++i)
{
resultatM[i] = 0; // initialiser le tableau de resultats a zero
}
double* p_resultat[11];
for(int i = 0; i < 6; ++i)
{
for(int j = 0; j < 6; ++j)
{
double f = *fx[i];
double g = *gx[j];
resultatM[i + j] += f * g; // additionner les degres, multiplier les coefficients
p_resultat[i + j] = &resultatM[i + j];
}
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 11);
}
void CCalculsPolynom es::Deriver(dou ble* fx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "f'(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
}
}
// Deriver
double resultat[5];
double* p_resultat[5];
for(int i = 0; i < 5; ++i)
{
resultat[i] = 0; // initialiser le tableau de resultats a zero
}
for(int i = 0; i < 6; ++i)
{
if(i - 1 >= 0) // si le degre est plus grand ou egal a zero
{
double f = *fx[i];
resultat[i - 1] = i * f; // diminuer n de 1, multiplier n*coeffX
p_resultat[i - 1] = &resultat[i - 1];
}
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 5);
}
void CCalculsPolynom es::IntegraleNB (double* fx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "f(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
}
}
// Integrale non bornee
double resultat[7];
double* p_resultat[7];
for(int i = 0; i < 7; ++i)
{
resultat[i] = 0; // initialiser le tableau de resultats a zero
}
resultat[0] = 0; // augmenter n de 1, diviser n/coeffX
p_resultat[0] = &resultat[0];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
resultat[i + 1] = f / (i + 1); // augmenter n de 1, diviser n/coeffX
p_resultat[i + 1] = &resultat[i + 1];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 7);
}
void CCalculsPolynom es::AfficherRes ultat(double* result[], int size)
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
double resultat[6];
for(int i = 0; i < 6; ++i)
{
resultat[i] = 0;
}
// verifie si le resultat total est zero
double k = 0;
for(int i = 0; i < size; i++)
{
resultat[i] = *result[i]; // store dans resultat[i] le contenu de result[i]
k += resultat[i]; // additionne les valeurs de resultat
}
// si le resultat total est zero, affiche zero
if(k == 0)
{
pDoc->msgLine5 += " 0"; // THIS LINE BREAKS AND BRINGS ME TO atlsimpstr.h line 812
}
// si le resultat est different de zero
else
{
// afficher le resultat
for(int i = size -1; i >= 0; i--)
{
if(result[i] !=0)
{
// mettre le contenu du tableau h(x) dans un buffer
char bufferHx[_CVTBUFSIZE];
_gcvt(resultat[i], 11, bufferHx);
CString Hxi = (CString) bufferHx;
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur ligne
pDoc->msgLine5 += Hxi;
pDoc->msgLine5 += " X";
pDoc->msgLine5 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine5 += " + ";
}
}
}
}
}
int CCalculsPolynom es::CountArray( double* result[])
{
int i = 0;
while(result[i] != 0X00)
{
i++;
}
//return i;
return(sizeof(r esult) / sizeof(*result) )-1;
}
// *************** *************** *************** **CalculsPolyno mes.h
#pragma once
#include "TP2View.h"
#include "MyForm.h"
#include "resource.h "
class CCalculsPolynom es
{
public:
CCalculsPolynom es(void);
public:
~CCalculsPolyno mes(void);
void Additionner(dou ble* fx[6], double* gx[6]);
void Soustraire(doub le* fx[6], double* gx[6]);
void Multiplier(doub le* fx[6], double* gx[6]);
void Deriver(double* fx[6]);
void IntegraleNB(dou ble* fx[6]);
void IntegraleBDirec te(double* fx[6]);
void IntegraleBTrape ze(double* fx[6], double* pas);
void Evaluer(double* fx[6]);
void RacinesDirecte( double* fx[6]);
void RacinesBissecti on(double* fx[6]);
void ExtremumsDirect e(double* fx[6]);
void AfficherResulta t(double* result[], int size);
int CountArray(doub le* result[]);
};
full project is available if needed
thanks in advance
Unhandled exception at 0x78325e5a (mfc80ud.dll) in TP2.exe: 0xC0000005: Access violation reading location 0x00000064.
It works fine for all other functions except this one and I can not figure out why.
Any help would be greatly appreciated.
// *************** *************** ****CalculsPoly nomes.cpp
#include "StdAfx.h"
#include "CalculsPolynom es.h"
CCalculsPolynom es::CCalculsPol ynomes(void)
{
}
CCalculsPolynom es::~CCalculsPo lynomes(void)
{
}
void CCalculsPolynom es::Additionner (double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "+";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += "X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Additonner
double resultat[6];
double* p_resultat[6];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
double g = *gx[i];
resultat[i] = f + g;
p_resultat[i] = &resultat[i];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 6);
}
void CCalculsPolynom es::Soustraire( double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "-";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _______________ _";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += " X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += " X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Soustraire
double resultat[6];
double* p_resultat[6];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
double g = *gx[i];
resultat[i] = f - g;
p_resultat[i] = &resultat[i];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 6);
}
void CCalculsPolynom es::Multiplier( double* fx[6], double* gx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine2 = "+";
pDoc->msgLine3 = "g(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "h(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// mettre le contenu du tableau g(x) dans un buffer
char bufferGx[_CVTBUFSIZE];
_gcvt(*gx[i], 12, bufferGx);
CString Gxi = (CString) bufferGx;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
pDoc->msgLine3 += Gxi;
pDoc->msgLine3 += "X";
pDoc->msgLine3 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
pDoc->msgLine3 += " + ";
}
}
// Multiplier
double resultatM[11];
for(int i = 0; i < 11; ++i)
{
resultatM[i] = 0; // initialiser le tableau de resultats a zero
}
double* p_resultat[11];
for(int i = 0; i < 6; ++i)
{
for(int j = 0; j < 6; ++j)
{
double f = *fx[i];
double g = *gx[j];
resultatM[i + j] += f * g; // additionner les degres, multiplier les coefficients
p_resultat[i + j] = &resultatM[i + j];
}
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 11);
}
void CCalculsPolynom es::Deriver(dou ble* fx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "f'(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
}
}
// Deriver
double resultat[5];
double* p_resultat[5];
for(int i = 0; i < 5; ++i)
{
resultat[i] = 0; // initialiser le tableau de resultats a zero
}
for(int i = 0; i < 6; ++i)
{
if(i - 1 >= 0) // si le degre est plus grand ou egal a zero
{
double f = *fx[i];
resultat[i - 1] = i * f; // diminuer n de 1, multiplier n*coeffX
p_resultat[i - 1] = &resultat[i - 1];
}
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 5);
}
void CCalculsPolynom es::IntegraleNB (double* fx[6])
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
pDoc->msgLine1 = "f(x) = ";
pDoc->msgLine4 = "______________ _______________ _______________ _____";
pDoc->msgLine5 = "f(x) = ";
for(int i = 5; i >= 0; --i)
{
// mettre le contenu du tableau f(x) dans un buffer
char bufferFx[_CVTBUFSIZE];
_gcvt(*fx[i], 12, bufferFx);
CString Fxi = (CString) bufferFx;
// mettre i dans un buffer
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur 2 lignes
pDoc->msgLine1 += Fxi;
pDoc->msgLine1 += "X";
pDoc->msgLine1 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine1 += " + ";
}
}
// Integrale non bornee
double resultat[7];
double* p_resultat[7];
for(int i = 0; i < 7; ++i)
{
resultat[i] = 0; // initialiser le tableau de resultats a zero
}
resultat[0] = 0; // augmenter n de 1, diviser n/coeffX
p_resultat[0] = &resultat[0];
for(int i = 0; i < 6; ++i)
{
double f = *fx[i];
resultat[i + 1] = f / (i + 1); // augmenter n de 1, diviser n/coeffX
p_resultat[i + 1] = &resultat[i + 1];
}
// Afficher le resultat
CCalculsPolynom es* myPoly = new CCalculsPolynom es();
myPoly->AfficherResult at(p_resultat, 7);
}
void CCalculsPolynom es::AfficherRes ultat(double* result[], int size)
{
// Afficher les polynomes
// note: ces variables ne peuvent etre declarees const publiques ni static
// only static const integral data members can be initialized within a class
CMDIFrameWnd *pFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame ();
CTP2View *pView = (CTP2View *)pChild->GetActiveView( );
CTP2Doc *pDoc = pView->GetDocument( );
double resultat[6];
for(int i = 0; i < 6; ++i)
{
resultat[i] = 0;
}
// verifie si le resultat total est zero
double k = 0;
for(int i = 0; i < size; i++)
{
resultat[i] = *result[i]; // store dans resultat[i] le contenu de result[i]
k += resultat[i]; // additionne les valeurs de resultat
}
// si le resultat total est zero, affiche zero
if(k == 0)
{
pDoc->msgLine5 += " 0"; // THIS LINE BREAKS AND BRINGS ME TO atlsimpstr.h line 812
}
// si le resultat est different de zero
else
{
// afficher le resultat
for(int i = size -1; i >= 0; i--)
{
if(result[i] !=0)
{
// mettre le contenu du tableau h(x) dans un buffer
char bufferHx[_CVTBUFSIZE];
_gcvt(resultat[i], 11, bufferHx);
CString Hxi = (CString) bufferHx;
char bufferi[_CVTBUFSIZE];
_itoa_s(i, bufferi, 10);
CString s_i = (CString) bufferi;
// Afficher sur ligne
pDoc->msgLine5 += Hxi;
pDoc->msgLine5 += " X";
pDoc->msgLine5 += s_i;
// ajouter le signe +
if(i > 0)
{
pDoc->msgLine5 += " + ";
}
}
}
}
}
int CCalculsPolynom es::CountArray( double* result[])
{
int i = 0;
while(result[i] != 0X00)
{
i++;
}
//return i;
return(sizeof(r esult) / sizeof(*result) )-1;
}
// *************** *************** *************** **CalculsPolyno mes.h
#pragma once
#include "TP2View.h"
#include "MyForm.h"
#include "resource.h "
class CCalculsPolynom es
{
public:
CCalculsPolynom es(void);
public:
~CCalculsPolyno mes(void);
void Additionner(dou ble* fx[6], double* gx[6]);
void Soustraire(doub le* fx[6], double* gx[6]);
void Multiplier(doub le* fx[6], double* gx[6]);
void Deriver(double* fx[6]);
void IntegraleNB(dou ble* fx[6]);
void IntegraleBDirec te(double* fx[6]);
void IntegraleBTrape ze(double* fx[6], double* pas);
void Evaluer(double* fx[6]);
void RacinesDirecte( double* fx[6]);
void RacinesBissecti on(double* fx[6]);
void ExtremumsDirect e(double* fx[6]);
void AfficherResulta t(double* result[], int size);
int CountArray(doub le* result[]);
};
full project is available if needed
thanks in advance
Comment