本文介绍了如何在类XNOR的output()中调用BUFFER :: set(0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在输出()中调用BUFFER :: set(0)
类XNOR的
? XOR继承BUFFER类作为受保护的,其中set()是公共的,XNOR继承XOR类?



我尝试过:



How do I call BUFFER::set(0) in output()
of class XNOR? XOR inherits BUFFER class as protected where set() is public and XNOR inherits XOR class?

What I have tried:

#include<iostream>
#include<vector>
using namespace std;

/*void operator =(vector<bool>x,vector<bool>y)
{   int i=0;
    while(i<y.size())
    {
        x.push_back(y[i]);
        i++;
    }
}*/
class gate
{
public:
    bool output();
};

class BUFFER: public gate
{
    bool x;
public:
    void set(bool data){ x=data;}
    bool output()
    {
        return x;
    }
};
class OR: public gate
{
    vector<bool>v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        while(v.size()>1)
        {
            v.push_back(v[0]+v[1]);
            v.erase(v.begin(),v.begin()+2);
        }
        return v[0];
    }
};
class AND: public gate
{
    vector<bool>v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        while(v.size()>1)
        {
            v.push_back(v[0]*v[1]);
            v.erase(v.begin(),v.begin()+2);
        }
        return v[0];
    }
};
class NOT: public gate
{
    bool x;
public:
    void set(bool data){ x=data; }
    bool output()
    {
        return 1-x;
    }
};
class NAND: public gate, protected NOT,AND
{
    vector<bool> v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        AND::set(v);
        NOT::set(AND::output());
        return (NOT::output());
    }
};
class NOR: public gate, protected OR,NOT
{
    vector<bool>v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        OR::set(v);
        NOT::set(OR::output());
        return NOT::output();
    }
};
class XOR: public gate, protected NOT,AND,OR,BUFFER
{
    vector<bool> v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        while(v.size()>1)
        {
            vector<bool> d,g,c;
            d.push_back(v[0]);cout<<"v[0] \t"<<v[0];
            NOT::set(v[1]);cout<<"\nv[1] \t"<<v[1];
            d.push_back(NOT::output());cout<<"\nNOT::output() \t"<<NOT::output()<<"\n";
            for(int i=0;i<d.size();i++) cout<<d[i]<<"\t";
            AND::set(d);
            //d.clear();
            c.push_back(AND::output());cout<<"\nAND::output() \t"<<AND::output();
           // cout<<"1 and"<<AND::output();
            g.push_back(v[1]);cout<<"\nv[1] \t"<<v[1];
            NOT::set(v[0]);cout<<"\nv[0] \t"<<v[0];
            g.push_back(NOT::output());cout<<"\nNOT::output() \t"<<NOT::output()<<"\n";
            for(int i=0;i<g.size();i++) cout<<g[i]<<"\t";
            AND::set(g);
            c.push_back(AND::output());cout<<"\nAND::output() \t"<<AND::output()<<"\n";
            for(int i=0;i<c.size();i++) cout<<c[i]<<"\t";
           // cout<<"\t2 and"<<AND::output();
            OR::set(c);
            cout<<"\nOR::output"<<OR::output();
            v.push_back(OR::output());
            v.erase(v.begin(), v.begin()+2);
        }
        return v[0];
    }
};

class XNOR: public gate, protected XOR//, NOT
{
    vector<bool> v;
public:
    void set(vector<bool> data){ copy(data.begin(),data.end(),back_inserter(v));}
    bool output()
    {
        BUFFER::set(0);
        //XOR::set(v);
        //XOR:output();
        //NOT::set(XOR::output());
        return 0;//NOT::output();
    }
};

int main()
{
    int a;
    bool x;
    vector<bool> v;
    while(1)
    {
        cin>>a;
        for(int i=0;i<a;i++)
        {
            cin>>x;
            v.push_back(x);
        }
            XOR d;
            d.set(v);
            cout<<"OUTPUT \t"<<d.output();
    }
    return 0;
}

推荐答案


这篇关于如何在类XNOR的output()中调用BUFFER :: set(0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:05