1)all singletons
2)all duets
3)all quads
and so on.
>I already have a 100 line code.
Search google and you may find a clever algorithm to do what you want. Otherwise you're looking at brute force, and that's going to be sloooooooow.
>Plz tell me how I can show u my code.
Here, or nowhere. Daniweb is a public forum. If you want private help that may or may not be good quality (because it isn't publicly checked by the helper's peers), try www.allexperts.com.
#include<iostream> #include<string> #include<stdlib.h> #include<list> #include <sstream> using namespace std; // all variables used are global int n;//number of variables int m;//number of minterms int d;//number of don't cares int i;//used for indexing again and again int pos;//the functions 'compare' and 'hypergen' use this list<string>::iterator j;//I've used this in various functions list<string> minterms;// Each string in the all the lists in this program is of length 15 .... list<string> doncares;// and it represents(in binary) a positive integer less than ((2^15)-1) list<string> *slists=new list<string>[20];//I've put some big number //couldn't find a better solution:-( list<int> Minterm; //I needed something golbal (and dynamic!) for the minterms list<int> Doncare; //The following are all the functions used. void hypergen(int i);//This function generates the hypercubes string dtob(int integer); string itoa(int num); bool compare(string one,string two); int main(){ // Getting all the inputs from the user cout<<"enter the number of variables\n"; cin>>n; for(i=0;i<=n;i++){list<string> LISTi;} cout<<"\nEnter the number of minterms\n"; cin>>m; cout<<"\nenter the minterms\n"; int minterm[m]; for (i=0;i<m;i++){cin>>minterm[i];Minterm.push_back(minterm[i]);} cout<<"\nminterms read-OK!\n"; cout<<"\nEnter the number of don't cares\n"; cin>>d; int doncare[d]; cout<<"\nenter the don't cares\n"; for (i=0;i<d;i++){cin>>doncare[i];Doncare.push_back(doncare[i]);} cout<<"\ndon't cares read-OK!\n"; // pushing the minterms and don't cares int their lists for (i=0;i<m;i++){minterms.push_back(dtob(minterm[i]));slists[0].push_back(*(--minterms.end()));} cout<<"\nBinary representation of Minterms pushed to the list 'minterms' and to slists[0]\n"; for (i=0;i<d;i++){doncares.push_back(dtob(doncare[i]));slists[0].push_back(*(--doncares.end()));} cout<<"\nBinary representation of Don't cares pushed to the list 'doncares' and to slists[0]\n"; cout<<"\n\n"; //Printing the list to check for corrrectness for(j=minterms.begin(); j != minterms.end(); ++j) cout << *j << " "; cout <<"\nAren't these minterms ?\n"<< endl; for(j=doncares.begin(); j != doncares.end(); ++j) cout << *j << " "; cout <<"\nAren't these don't cares ?\n"<<endl; for(j=slists[0].begin(); j != slists[0].end(); ++j) cout << *j << " "; cout <<"\nAren't these (minterms)+(don't cares) ?\n\n"<<endl; //Now the 'REAL' thing for(i=0;i<=n;i++){hypergen(i);} return 1; } /*------------------------------------------------------------------- ---- ---*/ /* The fuction takes in a decinmal integer and returns it binary representation as a atring */ string dtob(int integer){ int index,temp,bin; int array[15]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384}; string BIN; if(integer<0 || integer>32767){ cout<<"\nThe number must be between 0-32767.\nEverything has a limit!"; cout<<"\nThis program may fail now"; } else{ index=14; while(index>=0){ temp=0; if(integer>=array[index]){ temp=array[index]; integer=integer-temp; bin=1; index--; } else{ bin=0; index--; } BIN+=itoa(bin); } } return BIN; } /*-------------------------------------------------------------------------------*/ /* input is an integer output is the char of that integer for eg if input is integer 5 output is char 5 */ string itoa(int num){ //Don't know much about how this function works! stringstream converter; converter << num; return converter.str(); } /*---------------------------------------------------------------------------------*/ /*This function takes in the index of a list and generates all 'next' order hypercubes that ara possible by combining exactly two elements of this list ---------------*/ /*All 'next' order hypercubes generated from 'slists[i]' are stored in 'slists[i+1] */ /*The two terms which combine can be(and are) safely deleted -----------------------*/ void hypergen(int i){ //I don't want 'i' to be changed in this function bool arjun; string temp;//temporary string whiched is pushed into slists[i+1] list<string>::iterator k; for(j=slists[i].begin(); j != slists[i].end(); ++j){ for(k=++j; k!=slists[i].end(); ++k){ arjun = compare(*j,*k); if (arjun){// need to add an element add a hypercube to slist[i+1] } } } for(j=slists[i].begin(); j != slists[i].end(); ++j) cout << *j << " "; cout <<"\n This is hypercube list no "<<i<<endl; } /*-------------Iam fed up -------------------------------------------------*/ /*funtion returns a valuue 'TRUE' if the input strings differ exactly by one bit */ bool compare(string one,string two){ int count; count=0;//this stores the number of bits in 'one' and 'two' differ pos=0;//pos give the position where the strings 'one' and 'two' differ. for(i=0; i<=14; i++){ if(one[i] != two[i]){++count; pos = i;} } if(count == 1) {return (0<5);} //returning TRUE else {return (0>5); //returning FALSE }
#include<iostream> #include<string> #include<stdlib.h> #include<list> #include <sstream> using namespace std; // all variables used are global int n;//number of variables int m;//number of minterms int d;//number of don't cares int i;//used for indexing again and again int pos;//the functions 'compare' and 'hypergen' use this list<string>::iterator j;//I've used this in various functions list<string> minterms;// Each string in the all the lists in this program is of length 15 .... list<string> doncares;// and it represents(in binary) a positive integer less than ((2^15)-1) list<string> *slists=new list<string>[20];//I've put some big number //couldn't find a better solution:-( list<int> Minterm; //I needed something golbal (and dynamic!) for the minterms list<int> Doncare; //The following are all the functions used. void hypergen(int i);//This function generates the hypercubes string dtob(int integer); string itoa(int num); bool compare(string one,string two); int main(){ // Getting all the inputs from the user cout<<"enter the number of variables\n"; cin>>n; for(i=0;i<=n;i++){list<string> LISTi;} cout<<"\nEnter the number of minterms\n"; cin>>m; cout<<"\nenter the minterms\n"; int minterm[m]; for (i=0;i<m;i++){cin>>minterm[i];Minterm.push_back(minterm[i]);} cout<<"\nminterms read-OK!\n"; cout<<"\nEnter the number of don't cares\n"; cin>>d; int doncare[d]; cout<<"\nenter the don't cares\n"; for (i=0;i<d;i++){cin>>doncare[i];Doncare.push_back(doncare[i]);} cout<<"\ndon't cares read-OK!\n"; // pushing the minterms and don't cares int their lists for (i=0;i<m;i++){minterms.push_back(dtob(minterm[i]));slists[0].push_back(*(--minterms.end()));} cout<<"\nBinary representation of Minterms pushed to the list 'minterms' and to slists[0]\n"; for (i=0;i<d;i++){doncares.push_back(dtob(doncare[i]));slists[0].push_back(*(--doncares.end()));} cout<<"\nBinary representation of Don't cares pushed to the list 'doncares' and to slists[0]\n"; cout<<"\n\n"; //Printing the list to check for corrrectness for(j=minterms.begin(); j != minterms.end(); ++j) cout << *j << " "; cout <<"\nAren't these minterms ?\n"<< endl; for(j=doncares.begin(); j != doncares.end(); ++j) cout << *j << " "; cout <<"\nAren't these don't cares ?\n"<<endl; for(j=slists[0].begin(); j != slists[0].end(); ++j) cout << *j << " "; cout <<"\nAren't these (minterms)+(don't cares) ?\n\n"<<endl; //Now the 'REAL' thing for(i=0;i<=n;i++){hypergen(i);} return 1; } /*------------------------------------------------------------------- ---- ---*/ /* The fuction takes in a decinmal integer and returns it binary representation as a atring */ string dtob(int integer){ int index,temp,bin; int array[15]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384}; string BIN; if(integer<0 || integer>32767){ cout<<"\nThe number must be between 0-32767.\nEverything has a limit!"; cout<<"\nThis program may fail now"; } else{ index=14; while(index>=0){ temp=0; if(integer>=array[index]){ temp=array[index]; integer=integer-temp; bin=1; index--; } else{ bin=0; index--; } BIN+=itoa(bin); } } return BIN; } /*-------------------------------------------------------------------------------*/ /* input is an integer output is the char of that integer for eg if input is integer 5 output is char 5 */ string itoa(int num){ //Don't know much about how this function works! stringstream converter; converter << num; return converter.str(); } /*---------------------------------------------------------------------------------*/ /*This function takes in the index of a list and generates all 'next' order hypercubes that ara possible by combining exactly two elements of this list ---------------*/ /*All 'next' order hypercubes generated from 'slists[i]' are stored in 'slists[i+1] */ /*The two terms which combine can be(and are) safely deleted -----------------------*/ void hypergen(int i){ //I don't want 'i' to be changed in this function bool arjun; string x ("x"); string temp;//temporary string whiched is pushed into slists[i+1] list<string>::iterator k; for(j=slists[i].begin(); j != slists[i].end(); j++){ //THE ERROR IS SOMEWHERE HERE. for(k=j++; k!=slists[i].end(); k++) { //A double loop to compare each pair of strings. arjun = compare(*j,*k);// 'arjun' is true only when *j and *k differ exactly by 1 bit if (arjun){// need to add an element add a hypercube to slist[i+1] temp = *j; temp[pos] = x[0]; slists[i+1].push_back(temp); } } } for(j=slists[i+1].begin(); j != slists[i+1].end(); j++) cout << *j << " "; cout <<"\n This is hypercube list no "<<i+1<<endl; } /*-------------Iam fed up -------------------------------------------------*/ /*funtion returns a valuue 'TRUE' if the input strings differ exactly by one bit */ bool compare(string one,string two){ int count; count=0;//this stores the number of bits in 'one' and 'two' differ pos=0;//pos keeps track of position where 'one' and 'two' differ cout<<"\n one = "<< one ; // this is to check weather strings are passeed properly or not cout<<"\n two = "<< two <<"\n" ; for(i=0; i<=14; i++){ if(one[i] != two[i]){++count; pos = i;} //for every disimilarity,increase the count by 1 } if(count == 1) {return (0<5);} //returning TRUE else {return (0>5);} //returning FALSE }
| DaniWeb Message | |
| Cancel Changes | |