نمایش نتایج 1 تا 29 از 29

نام تاپیک: مشکل با یه کلاس

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1
    کاربر دائمی
    تاریخ عضویت
    فروردین 1389
    محل زندگی
    کرمانشاه
    پست
    174

    مشکل با یه کلاس

    با سلام برنامه زیر تو اخرین کلاس خطا می ده با اینکه با کلاس های بالاتر دوسته اما نمی تونه از متداش استفاده کنه و خطایUndelare identification میده.دوستان لطفا کمک کنید.

    // LA.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include "LA.h"
    #include <iostream>
    #include<conio.h>
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    // The one and only application object
    CWinApp theApp;
    using namespace std;
    class List;
    class ListIterator;
    class ListNode;
    class Graph;
    class Automata;
    ///////////////////////////////////////////////////
    class ListNode
    {
    friend class List;
    friend class ListIterator;
    friend class Graph;
    friend class Automata;
    //-----------------------
    int data1;
    float data2;
    bool action;
    ListNode* link;
    };
    //------------ end class ListNode
    class ListIterator
    {
    friend class Graph;
    ListNode* first;
    public:
    bool NotNull()
    {
    if(first)return true;
    return false;
    }
    ////////////////////////////////// end of NotNull
    bool NextNotNull()
    {
    if(first && first->link)
    return true;
    else
    return false;
    }
    //////////////////////////////////end of NextNotNull
    int Next()
    {
    if(first->link)
    first = first->link;
    else
    return 0;
    }
    ////////////////////////////////// end of Next
    };
    //------------ end class ListIterator
    class List
    {
    friend class ListIterator;
    friend class Graph;
    friend class Automata;
    ListNode* first;
    public:
    List(int element1=0,float element2=0)
    {
    first = new ListNode;
    first->data1 = element1;
    first->data2 = element2;
    first->action = true;
    first->link = NULL;
    }
    ///////////////////////////////////////////////////////end of Constructor
    void InsertFirst(int element1,float element2=0,bool element3=true)
    {
    ListNode* t;
    t = new ListNode;
    t->data1 = element1;
    t->data2 = element2;
    t->action = element3;
    t->link = first;
    first=t;

    }
    ///////////////////////////////////////////////////////end of InsertFirst
    void InsertEnd( int element1,float element2=0,bool element3=true)
    { ListNode* t,* s;
    t = new ListNode;
    if(!first)
    {
    t->data1 = element1;
    t->data2 = element2;
    t->action = element3;
    t->link = NULL;
    }
    else
    { s = first;
    while(s->link != NULL)
    s = s->link;
    t->data1 = element1;
    t->data2 = element2;
    t->action = element3;
    s->link = t;
    t->link = NULL;
    }
    }
    ///////////////////////////////////////////////////////end of InsertEnd
    void deleteNode(int element)
    {
    ListNode* t,* h;
    t = first;
    if(t->data1 == element)
    {
    first = t->link;
    delete t;
    return;
    }
    h=t;
    while(t != NULL)
    {
    if(t->data1 == element)
    {
    h->link = t->link ;
    delete t;
    return;
    }
    h=t;
    t=t->link ;
    }
    cout<<"\n element" <<" "<<element<<" "<<"Not found"<<endl;
    }
    ///////////////////////////////////////////////////////end of deleteNode
    void InactionNode(int element)
    {
    ListNode* t;
    t = first;
    while(t->link != NULL)
    {
    if(t->data1 != element)
    t = t->link;
    else
    t->action = false;
    }
    }
    ///////////////////////////////////////////////////////end of InactionNode
    int Count()
    {
    ListNode *t;
    int count=0;
    for(t=first;t!=NULL;t=t->link)
    {
    count++;

    }
    return count-1;
    }
    ///////////////////////////////////////////////////////end of Count
    void Display()
    {
    ListNode* current;
    current = first;

    while(current != NULL)
    {
    cout<<current->data1<<endl;
    current = current->link;
    }
    }
    ///////////////////////////////////////////////////////end of Display
    void ConcatList(List x)
    {
    ListNode* t;
    if(!first)
    {
    first = x.first;
    return;
    }
    if(x.first)
    {
    for(t = first;t->link;t = t->link);
    t->link = x.first;
    }
    }
    ///////////////////////////////////////////////////////end of ConcatList
    ~List()
    {
    ListNode* t,* h;
    t = first;
    while(t != NULL)
    {
    h = t;
    t = t->link ;
    delete h;
    }
    }
    ///////////////////////////////////////////////////////end of Destrutor
    };
    //------------ end class List
    class Graph
    {
    int num,number,temp,ID,NV;
    friend class Automata;
    List* headNodes;
    public:
    Graph(int v=0)
    {
    headNodes = new List[v+1];
    }
    ///////////////////////////////////////////////////////end of Constructor
    void set(int d)
    {
    NV = d;
    }
    ///////////////////////////////////////////////////////end of set
    void getANDset(int vertex)
    {
    List AllNodes;
    cout<<"Please repeat follow steps for each node"<<endl<<endl;
    for(int i=0;i<vertex;i++)
    {
    cout<<"1. enter vertex ID:";
    cin>>ID;
    AllNodes.InsertEnd(ID);
    cout<<"2. enter number of neghbour vertice:";
    cin>>num;
    for(int j=0;j<num;j++)
    {
    cout<<"enter neghbour vertex"<<" "<<(j+1)<<" "<<":";
    cin>>number;
    temp = number;
    headNodes[ID].InsertFirst(temp);
    }//end for j

    }//end for i
    }
    ///////////////////////////////////////////////////////end of getANDset
    int CountNeighborNodes(int v)
    {
    int count=0;
    ListNode* t;
    t = headNodes[v].first;
    for(t; t->link; t = t->link)
    {
    count++;
    }
    return count;
    }
    ///////////////////////////////////////////////////////end of CountNeighborNodes
    void DisplayNeighbourNodes(int v)
    {
    ListNode* t;
    t = headNodes[v].first;
    cout<<"[";
    for(t; t->link; t=t->link)
    {cout<< t->data1 <<" ";}
    cout<<"]";
    }
    ///////////////////////////////////////////////////////end of DisplayNeighbourNodes
    void Display()
    {
    int i;
    for(i=1;i<=NV;i++)
    {
    cout<<"node "<<i<<" adjacent: ";
    DisplayNeighbourNodes(i);
    cout<<endl;
    }
    }
    ///////////////////////////////////////////////////////end of Display
    ListNode operator = (ListNode* x)
    {
    ListNode* t;
    t->data1 = x->data1;
    t->data2 = x->data2;
    t->action = x->action;
    t->link = x->link ;
    }
    ///////////////////////////////////////////////////////end of operator =
    List operator = (List x)
    { int k =x.Count();// felan
    List t((x.first)->data1,(x.first)->data2);
    ListNode* s;
    s = x.first;
    for(int i=1; i<k; i++)
    {
    s = s->link;
    t.InsertEnd(s->data1,s->data2,s->action);
    }
    return t;
    }
    ///////////////////////////////////////////////////////end of operator =
    ListNode* NeighborNodes(int v)
    {
    ListNode* t;

    t = headNodes[v].first;

    return t ;
    }
    ///////////////////////////////////////////////////////end of NeighborNodes with poniter
    void Display(ListNode* s)
    {
    while(s!=NULL)
    {
    cout<<s->data1;
    s=s->link;
    }
    }
    ///////////////////////////////////////////////////////end of Display with poniter
    List AllNodesList()
    {
    List AllNodes;
    for(int i=1;i<NV;i++)
    {
    AllNodes.InsertEnd(i);
    }
    return AllNodes;
    }
    //////////////////////////////////////////////////////end of AllNodesList
    List NoneNeighborNodes(int v)
    {
    List NNeighbor;
    ListNode* s;
    NNeighbor = AllNodesList();
    s = NeighborNodes(v);
    for(s;s!=NULL;s=s->link)
    {
    NNeighbor.deleteNode(s->data1);
    }
    return NNeighbor;
    }
    ///////////////////////////////////////////////////////end of NoneNeighborNodes
    };
    //------------ end class Graph
    class Automata
    { friend class Graph;
    public:
    Automata(int ID)
    {
    int k;
    ListNode* t;
    List alphaANDp;
    alphaANDp = NoneNeighborNodes(ID);
    }
    ///////////////////////////////////////////////////////end of Constructor
    List operator = (List x)
    {
    List t;
    ListNode* s;
    int k = x.Count();
    s = x.first;
    for(int i=1;i<=k;i++)
    {
    t.InsertEnd(s->data1,s->data2,s->action);
    s = s->link;
    }
    return t;
    }
    //////////////////////////////////////////////////////end of operator =
    void Reward(int ID,float a)
    {
    ListNode* t;
    t = headNodes[ID].first;
    for(t;t->link;t=t->link)
    {
    if(t->data1 == ID)
    t->data2 = t->data2 + a*(1-t->data2);
    else
    t->data2 = t->data2 * (1-a);
    }
    }
    //////////////////////////////////////////////////////end of Reward
    void Penalty(int ID,float b)
    {
    int r;
    ListNode* t;
    r = NoneNeighborNodes(ID).count();
    t = headNodes[ID].first;
    for(t;t->link;t=t->link)
    {
    if(t->data1 == ID)
    t->data2 = t->data2 * (1-b);
    else
    t->data2 = b/(1-r) + t->data2 * (1-b);
    }

    }
    //////////////////////////////////////////////////////end of Penalty
    int GetNextNode(int ID)
    {
    float A=0;
    ListNode* t;
    t = headNodes[ID].first;
    while(t!=NULL)
    {
    if((t->data2) >= A && t->action == true)
    {
    A = t->data2;
    ID = t->data1;
    }
    }
    return ID;
    }
    };
    //////////////////////////////////////////////////////////////////////////end of definition classes
    int main()
    {
    getch();
    return 0;
    }

    آخرین ویرایش به وسیله root88 : شنبه 07 فروردین 1389 در 19:31 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •