?对象里的数据成员在没有调用的情况下改变了
因为是用过程调试的,发现在调试的过程中定义的对象中的一些数据的值改变了,但是并没有调用过这些数据,不知道是什么原因,程序使用原来的版本写的,后来这个版本不能用之后就用新版本直接打开的,会不会是这个原因,麻烦帮忙看一下,谢谢了,下面贴出代码#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
#include"tools.h"
int Init(Gate *arr[]);
void SetPnext(Gate *a[],int len);
void InitQueue(Gate *arr[],Queue &qu,int len);
void main( )
{
Gate *arr[9];
int num;
num= Init( arr);
Queue queue(num);
SetPnext(arr,num);
InitQueue(arr,queue,num);
int k=0;
while(queue.rear!=queue.front)
{
int n=0;
for( n;n<num;n++)
{
if(queue.q[k]==arr[n]->OutNo)
{
if(arr[n]->InStr3_No==0)
arr[n]->CcCal2();
else
arr[n]->CcCal3();
arr[n]->ChangeNextIn();
arr[n]->Push(queue);
queue.Delete();
break;
}
k++;
if(k==num)
k=0;
}
}
for( int n=0;n<num;n++)
{
cout<<"标号为"<<arr[n]->OutNo<<" 的引线的CC0、CC1的值分别为"<<arr[n]->OutNewCCO<<"\t"<<arr[n]->OutNewCC1<<endl;
}
}
class Queue
{
public:
Queue(int);
void Add(int & x);
void Delete();
bool Search(int & x);
~Queue();
bool Empty()
{
return front!=rear;
}
int *q;
int front,rear;
private:
int maxsize;
int i;
int n;
};
class Gate{
public:
Gate();
void gate(int,int,int,int);
virtual void CcCal2()=0;
virtual void CcCal3()=0;
void ChangeNextIn( );
void Push(Queue &qu);
void min2(int &y,int x1,int x2);
void min3(int &y,int &x1,int &x2,int &x3);
void add2(int &y,int &x1,int &x2);
void add3(int &y,int &x1,int &x2,int &x3);
Gate *Pnext1,*Pnext2,*Pnext3;
int InStr1_No,InStr1_CC0,InStr1_CC1;
int InStr2_No,InStr2_CC0,InStr2_CC1;
int InStr3_No,InStr3_CC0,InStr3_CC1;
int OutNo,OutNewCCO,OutNewCC1,OutOldCCO,OutOldCC1;
};
class NotGate:public Gate
{
public:
void CcCal2()
{
OutNewCCO=InStr1_CC1+1;
OutNewCC1=InStr1_CC0+1;
if(OutNewCCO>1000)
OutNewCCO=1000;
if( OutNewCC1>1000)
OutNewCC1=1000;
}
void CcCal3()
{}
};
class AndGate:public Gate
{
public:
void CcCal2()
{
min2(OutNewCCO,InStr1_CC0,InStr2_CC0);
add2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
void CcCal3()
{
min3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
add3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class OrGate:public Gate
{
public:
void CcCal2()
{
add2(OutNewCCO,InStr1_CC0,InStr2_CC0);
min2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
void CcCal3()
{
add3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
min3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class OrNotGate:public Gate
{
public:
void CcCal2()
{
min2(OutNewCCO,InStr1_CC0,InStr2_CC0);
add2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
void CcCal3()
{
min3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
add3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class XorGate:public Gate
{
public:
void CcCal2()
{
min2(OutNewCCO,InStr1_CC0+InStr2_CC0,InStr1_CC1+InStr2_CC1);
min2(OutNewCC1,InStr1_CC0+InStr2_CC1,InStr1_CC1+InStr2_CC0);
}
void CcCal3()
{}
};
class Dtri:public Gate
{
public:
void CcCal2()
{
add3(OutNewCCO,InStr1_CC0,InStr1_CC1,InStr2_CC0);
add3(OutNewCC1,InStr1_CC0,InStr1_CC1,InStr2_CC1);
if(OutNewCCO<1000)
OutNewCCO=OutNewCCO-1;
if(OutNewCC1<1000)
OutNewCC1=OutNewCC1-1;
}
void CcCal3()
{}
};
#include"stdafx.h"
#include"tools.h"
Gate::Gate()
{
InStr1_No=0;
OutNo=0;
InStr1_CC0=InStr1_CC1=1000;
OutNewCCO=OutNewCC1=OutOldCCO=OutOldCC1=1000;
InStr2_CC0=InStr2_CC1=1000;
InStr3_CC0=InStr3_CC1=1000;
Pnext1=NULL;
Pnext2=NULL;
Pnext3=NULL;
InStr2_No=InStr3_No=0;
}
void Gate::gate (int inNo1,int inNo2,int inNo3,int ioutNo )
{
InStr1_No=inNo1;
InStr2_No=inNo2;
InStr3_No=inNo3;
OutNo=ioutNo;
InStr1_CC0=InStr1_CC1=(InStr1_No<0)?1:1000;
InStr2_CC0=InStr2_CC1=(InStr2_No<0)?1:1000;
InStr3_CC0=InStr3_CC1=(InStr3_No<0)?1:1000;
OutNewCCO=OutNewCC1=OutOldCCO=OutOldCC1=1000;
Pnext1=NULL;
Pnext2=NULL;
Pnext3=NULL;
}
void Gate::ChangeNextIn()
{
if(Pnext1!=NULL)
{
if(OutNo=Pnext1->InStr1_No){
Pnext1->InStr1_CC0=OutNewCCO;
Pnext1->InStr1_CC1=OutNewCC1;
}
else if(OutNo=Pnext1->InStr2_No){
Pnext1->InStr2_CC0=OutNewCCO;
Pnext1->InStr2_CC1=OutNewCC1;
}
else
{
Pnext1->InStr3_CC0=OutNewCCO;
Pnext1->InStr3_CC1=OutNewCC1;
}
}
if(Pnext2!=NULL)
{
if(OutNo=Pnext2->InStr1_No){
Pnext2->InStr1_CC0=OutNewCCO;
Pnext2->InStr1_CC1=OutNewCC1;
}
else if(OutNo=Pnext2->InStr2_No){
Pnext2->InStr2_CC0=OutNewCCO;
Pnext2->InStr2_CC1=OutNewCC1;
}
else
{
Pnext2->InStr3_CC0=OutNewCCO;
Pnext2->InStr3_CC1=OutNewCC1;
}
}
if(Pnext3!=NULL)
{
if(OutNo=Pnext3->InStr1_No){
Pnext3->InStr1_CC0=OutNewCCO;
Pnext3->InStr1_CC1=OutNewCC1;
}
else if(OutNo=Pnext3->InStr2_No){
Pnext3->InStr2_CC0=OutNewCCO;
Pnext3->InStr2_CC1=OutNewCC1;
}
else
{
Pnext3->InStr3_CC0=OutNewCCO;
Pnext3->InStr3_CC1=OutNewCC1;
}
}
}
void Gate::Push(Queue &qu)
{
if((OutOldCCO!=OutNewCCO)||(OutOldCC1!=OutNewCC1))
{
OutOldCCO=OutNewCCO;
OutOldCC1=OutNewCC1;
if(Pnext1!=NULL)
{
if(~qu.Search(Pnext1->OutNo))
qu.Add(Pnext1->OutNo);
}
if(Pnext2!=NULL)
{
if(~qu.Search(Pnext2->OutNo))
qu.Add(Pnext2->OutNo);
}
if(Pnext3!=NULL)
{
if(~qu.Search(Pnext3->OutNo))
qu.Add(Pnext3->OutNo);
}
}
}
void Gate::add2(int &y,int &x1,int &x2)
{
if((x1<1000)&&(x2<1000))
y=x1+x2+1;
else
y=1000;
}
void Gate::add3(int &y,int &x1,int &x2,int &x3)
{ y=x1+x2+x3+1;
if(y>1000)
y=1000;
}
void Gate::min2(int &y,int x1,int x2)
{
if(x1<x2)
y=x1;
else
y=x2;
if(y<1000)
y=y+1;
}
void Gate::min3(int &y,int &x1,int &x2,int &x3)
{
if((x1<x2)&&(x1<x3))
y=x1;
else
if((x2<x3)&&(x2<x1))
y=x2;
else
y=x3;
if(y<1000)
y=y+1;
}
#include"stdafx.h"
#include"tools.h"
Queue::Queue(int size)
{
maxsize=size;
q=new int[maxsize];
front=0;
rear=0;
i=0;
n=0;
}
void Queue::Add(int &x)
{
q[i]=x;
rear=rear+1;
if(i<(maxsize-1))
i++;
else
i=0;
}
void Queue::Delete()
{
front=front+1;
q[n]=0;
if(n<(maxsize-1))
n++;
else
n=0;
}
bool Queue::Search(int &x)
{
int k;
for(k=0;k<maxsize;k++)
{
if(q[k]==x)
{
return 1;
break;
}
else
return 0;
}
}
Queue::~Queue()
{
delete q;
}
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
#include"tools.h"
int Init(Gate *arr[])
{
signed int GateSort,ioutNo,inNO1,inNO2,inNO3;
int sum=0;
int a,b,c,d,e,f;
NotGate notgate[10];
AndGate andgate[10];
OrGate orgate[10];
OrNotGate ornotgate[10];
XorGate xorgate[10];
Dtri dtri[10];
a=b=c=d=e=f=0;
ifstream infile;
infile.open("d:\\data.txt");
if(!infile)
{
cerr<<"打开文件失败!"<<endl;
return 1;
}
for(int i=0;!infile.eof();i++)
{
infile>>GateSort;
infile>>ioutNo;
infile>>inNO1;
infile>>inNO2;
infile>>inNO3;
switch(GateSort)
{
case 1:
notgate[a].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=¬gate[a];
a++;
break;
case 2:
andgate[b].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=&andgate[b];
b++;
break;
case 3:
orgate[c].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=&orgate[c];
c++;
break;
case 4:
ornotgate[d].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=&ornotgate[d];
d++;
break;
case 5:
xorgate[e].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=&xorgate[e];
e++;
break;
case 6:
dtri[f].gate(inNO1,inNO2,inNO3,ioutNo);
arr[i]=&dtri[f];
f++;
break;
}
sum++;
}
infile.close();
return sum;
}
#include"stdafx.h"
#include"tools.h"
void SetPnext(Gate *arr[],int len)
{
for(int i=0;i<len;i++)
{
for(int j=0;j<len;j++)
{
if(arr[i]->Pnext1==NULL)
{
if((arr[i]->OutNo==arr[j]->InStr1_No)||(arr[i]->OutNo==arr[j]->InStr2_No)||(arr[i]->OutNo==arr[j]->InStr3_No))
arr[i]->Pnext1=arr[j];
}
else if(arr[i]->Pnext2==NULL)
{
if((arr[i]->OutNo==arr[j]->InStr1_No)||(arr[i]->OutNo==arr[j]->InStr2_No)||(arr[i]->OutNo==arr[j]->InStr3_No))
arr[i]->Pnext2=arr[j];
}
else if(arr[i]->Pnext3==NULL)
{
if((arr[i]->OutNo==arr[j]->InStr1_No)||(arr[i]->OutNo==arr[j]->InStr2_No)||(arr[i]->OutNo==arr[j]->InStr3_No))
arr[i]->Pnext3=arr[j];
}
}
}
}
#include "stdafx.h"
#include"tools.h"
void InitQueue(Gate *arr[],Queue &qu,int len)
{
for(int i=0;i<len;i++)
{
if((arr[i]->InStr1_No<0)||(arr[i]->InStr2_No<0)||(arr[i]->InStr3_No<0))
qu.Add(arr[i]->OutNo);
}
}