atlsimpstr.h problem with mfc application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • YouPoP
    New Member
    • Jun 2007
    • 17

    atlsimpstr.h problem with mfc application

    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.




    Code:
    // **********************************CalculsPolynomes.cpp
    #include "StdAfx.h"
    #include "CalculsPolynomes.h"
    
    
    
    CCalculsPolynomes::CCalculsPolynomes(void)
    {
    }
    
    CCalculsPolynomes::~CCalculsPolynomes(void)
    {
    }
    void CCalculsPolynomes::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
    	CCalculsPolynomes* myPoly = new CCalculsPolynomes();
    	myPoly->AfficherResultat(p_resultat, 6);
    
    
    
    }
    void CCalculsPolynomes::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
    	CCalculsPolynomes* myPoly = new CCalculsPolynomes();
    	myPoly->AfficherResultat(p_resultat, 6);
    
    }
    void CCalculsPolynomes::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
    	CCalculsPolynomes* myPoly = new CCalculsPolynomes();
    	myPoly->AfficherResultat(p_resultat, 11);
    }
    void CCalculsPolynomes::Deriver(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 += "   +   ";
    		}
    	}
    
    	// 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
    	CCalculsPolynomes* myPoly = new CCalculsPolynomes();
    	myPoly->AfficherResultat(p_resultat, 5);
    }
    void CCalculsPolynomes::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
    	CCalculsPolynomes* myPoly = new CCalculsPolynomes();
    	myPoly->AfficherResultat(p_resultat, 7);
    }
    
    void CCalculsPolynomes::AfficherResultat(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"; [B]// THIS LINE BREAKS AND BRINGS ME TO atlsimpstr.h line 812[/B]
    
    	}
    	// 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 CCalculsPolynomes::CountArray(double* result[])
    {
    	int i = 0;
    	while(result[i] != 0X00)
    	{
    		i++;
    	}
    	//return i;
    	return(sizeof(result) / sizeof(*result))-1;
    }
    
    
    // ***********************************************CalculsPolynomes.h
    #pragma once
    #include "TP2View.h"
    #include "MyForm.h"
    #include "resource.h"
    
    
    class CCalculsPolynomes
    {
    public:
    	CCalculsPolynomes(void);
    public:
    	~CCalculsPolynomes(void);
    
    	void Additionner(double* fx[6], double* gx[6]);
    	void Soustraire(double* fx[6], double* gx[6]);
    	void Multiplier(double* fx[6], double* gx[6]);
    	void Deriver(double* fx[6]);
    	void IntegraleNB(double* fx[6]);
    	void IntegraleBDirecte(double* fx[6]);
    	void IntegraleBTrapeze(double* fx[6], double* pas);
    	void Evaluer(double* fx[6]);
    	void RacinesDirecte(double* fx[6]);
    	void RacinesBissection(double* fx[6]);
    	void ExtremumsDirecte(double* fx[6]);
    	void AfficherResultat(double* result[], int size);
    	int CountArray(double* result[]);
    	
    
    
    
    };
    full project is available at http://yolaine.biz/TP2.zip if needed

    thanks in advance
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What is your question?

    Please read the posting guidelines.

    Comment

    Working...