none
新编了个多项式相加的程序,可是在VS上运行却找不到头文件的位置 RRS feed

  • 问题

  •  新编了个多项式相加的程序,可是在VS上运行却找不到头文件的位置

    ————————————————————————————————————————————
    错误 1 fatal error C1083: 无法打开包括文件:“poly.cpp”: No such file or directory d:\ploy\ploy\main.cpp 2 

    错误 2 fatal error C1083: 无法打开包括文件:“poly.h”: No such file or directory d:\ploy\ploy\ploy.cpp 3 

    希望可以解决

    ____________________________________________
    file:ploy.h

    #ifndef MAIN_SAVITCH_POLY_H
    #define MAIN_SAVITCH_POLY_H
    #include<iostream>
    namespace main_savitch_3
    {
     /*struct data
     {
      float coeff;
      int power;
     
     } ;*/
     struct element
     {
      float coeff;
      int power;
      element * next;
     };

     class poly
     {
     public:
      poly(float a[], int b[],int n);
      poly();
      void friend polyadd(poly &p1,poly &p2);
      void sort();
      void printpoly();
      
     private:
     //element  data;
     element  *  first;
     int len;
      
     } ;
    }
    #endif


    ________________________________________________________
    FILE: ploy.cpp

    #include<iostream>
    using namespace std;
    #include"poly.h"
    /*  constructor  a[n]for coefficient ,b[n] for power ,n mean the length*/
    namespace main_savitch_3
    {
     poly::poly(float a[],int b[],int n)
     {
      len=n;
      first =new  element;//头节点。本链表为带头节点的链表
      first->coeff=0;
      first->power=0;
      first->next=NULL;
      element *rear =new element;
      rear->coeff=a[0];
      rear->power=b[0];
      rear->next=NULL;
      /*use add in the tail method to construct the expression */
      for (int i=1;i<n;i++)
      {
       element *p=new element;
       p->coeff=a[i];
       p-> power=b[i];
       p-> next=rear;
       rear=p;
      
      }
      first->next=rear;
     }
     poly::~poly()
     {
      element *p,*q;
      p=first;
      while(p!=NULL)
      {
       q=p->next;
       delete p;
       p=q;
      }
     }
     /*using selecting method to sort the expression with decreasing power*/
     void  poly::sort()
     {
      element *m,*p,*q;
      for(m=first->next;m!=NULL;m=m->next)
      {
       q=m;
       for( p=m;p!=NULL;p=p->next)
       {
           if(q->power<p->power)
            q=p;
       }
          float tmp1=q->coeff;
          int tmp2=q->power;
          q->coeff=m->coeff;
          q->power=m->power;
          m->coeff=tmp1;
          m->power=tmp2;
      }
         
     }
     void poly::printpoly()
     {
      element *p=first->next;
      cout<<"结果是:";
      while (p!=NULL)
      {
       cout<<p->coeff<<'x'<<'^'<<p->power<<"+";
       p=p->next;
      }
      cout<<endl;  
     }
     void polyadd(poly &p1,poly &p2)
     { 
      element *q=(p2.first)->next;
      element *cur,*tmp;
      while(q!=NULL){  
       element *p=(p1.first)->next;
       while(q->power!=p->power){
        cur=p;
        p=p->next;
        if(p==NULL)
        break;
       }
       if(p==NULL)//即该幂次在 poly p1中不存在在p1表头处加入。
        {
        tmp=q->next;
        q->next=(p1.first)->next;
        p1.first->next=q;
        q=tmp;
     
        }    
       else
        {
            p->coeff=q->coeff+p->coeff;
            if(p->coeff==0)
             {
              cur->next=p->next;
           delete p;
           
          }
        
         q=q->next;
        }
      
      }
     
    }
    }

    _______________________________________________________________________________
    FILE:main.cpp


    #include<iostream>
    #include"poly.cpp"
    //#include"poly.h"
    using namespace std;
    using namespace main_savitch_3

    void main()
    {
     float a1[3]={3,2,1};
     int b1[3]={3,0,2};
     float a2[3]={-1,1,2};
     int b2[3]={0,1,2} ;
     poly p1(a1,b1,3);
     poly p2(a2,b2,3);
     //p1.sort();
     //p2.sort();
     p1.printpoly();
     p2.printpoly();
     polyadd(p1,p2);
     p1.sort();
     p1. printpoly();
     
     
    }


    沈作佳
    2009年2月22日 7:50

答案

全部回复