Professional Documents
Culture Documents
h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
//Main class
class QM
{
public:
int VARIABLES;
string dontcares;
QM(int a)
{
VARIABLES=a;
dontcares.append(a,'-');
return v;
}
if ( n % 2 == 0 )
return decToBin(n / 2) + "0";
else
return decToBin(n / 2) + "1";
}
return temp;
}
vector<string> newminterms;
int max=minterms.size();
int checked[max];
for(int i=0;i<max;i++)
{
for(int j=i;j<max;j++)
{
//If a grey code pair is found, replace the differing bits with
don't cares.
if(isGreyCode(minterms[i],minterms[j]))
{
checked[i]=1;
checked[j]=1;
if(!
in_vector(newminterms,replace_complements(minterms[i],minterms[j])))
newminterms.push_back(replace_complements(minterms[i],minterms[j]));
}
}
}
return newminterms;
}
for(int i=0;i<a.length();i++)
{
if(a[i]!='-')
{
if(a[i]=='0')
temp=temp+vars[i]+"\'";
else
temp=temp+vars[i];
}
}
return temp;
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(int i=0;i<a.size();i++)
{
if(a[i]!=b[i])
return false;
}
return true;
}
};
//Main function
int main ()
{
char check='y';
while(check=='y')
{
int no;
cout<<endl<<"Enter the number of variables:"<<endl;
cin>>no;
if(no > 8 || no < 1)
{
cout << "Invalid number of variables (1-8)" << endl;
continue;
}
QM q(no);
string temp="";
cout<<"Enter the minterms(RANGE=0-"<<pow(2,no)-1<<") separated by
comma:"<<endl;
cin>>temp;
sort(minterms.begin(),minterms.end());
do
{
minterms=q.reduce(minterms);
sort(minterms.begin(),minterms.end());
}while(!q.VectorsEqual(minterms,q.reduce(minterms)));
int i;
cout << "The reduced boolean expression in SOP form:" << endl;
for (i=0;i<minterms.size()-1; i++)
cout <<q.getValue(minterms[i])<<"+";
cout<<q.getValue(minterms[i])<<endl;