Source code Quine McClusky

Seperti janji kutu di postingan sebelumnya, sekarang kutu benar-benar akan memberikan secara cuma-cuma kepada anda source code yang dibuat kutu bersama kelompok dalam mata kuliah Digital System di President University. Yaitu tugas membuat algoritma dan source code untuk meminimalisasi a.k.a optimalisasi circuit dengan metode Quine McClusky. Dalam pikiran kutu, daripada kita membuat 2 tugas; yaitu algoritma dan source code, itu hanya membuang-buang waktu. Kan lebih baik kita membuat source codenya aja, n buat algoritmanya tinggal delete2 aja perintah2 yg bertujuan grafis or complement semata. Mudah kan??

Source code ini dibuat dalam bahasa C++, silahkan bagi yang ingin mengcopy dan mencoba menjalankannya. Maaf bagi pembaca yang “ora mudeng” postingan saya ini, karena ini didekisaikan hanya untuk pemerhati IT. Insya Allah berhasil koq programnya. Bagi yang tidak bisa menggunakannya, nanti akan saya terangkan dalam postingan saya selanjutnya, atau bisa juga hubungi saya lewat japri atau FB. Selamat mencoba….

// A Simple Quine Mc Cluskey program (Without searching an essential prime implicants)
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<string>
using std::string;
createinput();applymccluskey();printlist();findmaxlength();makingsamelength();testofredundant();combine();join();convertion();
makingsamelengthforcharinput();valuingthedash();reverseconvertion();findmaxascii();
string input;
char more;
int maxlength,count,differencelength,diff,diffindex,i;
int combexists,combhappen,createfromchar=0,maxascii;

struct node
{
int comb,dashlevel;
string data;
struct node *next;
};
typedef struct node quine;
quine *p,*q,*r,*head,*head1,*newnode;

main()
{ int choice;
cout<<“\nA Simple Quine Mc Cluskey Program”<<endl;
cout<<“(1).Create a binary input type (1 or 0)\n(2).Create a character type input (lowercase alphabet)\n(3).Applying Quine Mc cluskey\n(other).exit the program”<<endl;
cout<<“\nEnter your choice(1-3) : “;
cin>>choice;
if (choice==1)
{ createfromchar=0;
createinput();}
else if (choice==3)
{ applymccluskey();}
else if(choice==2)
{ createfromchar=1;
createinput();}
else
{}
return 0;
}

applymccluskey()
{
if(head==NULL)
{
cout<<“data wasn’t created yet\n”;
main();
}
if(createfromchar==1)
convertion();
cout<<“\nThe inputted data was : “<<endl;
printlist();
cout<<“\nAfter levelling the length :”<<endl;
findmaxlength(); // Find the maximum length of all minterms
if(createfromchar==1)
makingsamelengthforcharinput();
makingsamelength(); // levelling minterms
printlist();
testofredundant(); // search and delete the same data (one of)
printlist();
valuingthedash();
cout<<“\nCombine the data using Quine Mccluskey theorem..”<<endl;
combhappen=1;
while(combhappen==1) // combhappen==0 means can’t combine the rest of the minterms
{
combhappen=0;
combine();
join();
testofredundant();
}
cout<<“\nnew list after combining (The output) is:\n”;
printlist();
if(createfromchar==1)
{ cout<<“\nrunning reverse convertion..\nThe output :”<<endl;
reverseconvertion();
printlist();
}
main();
return 0;
}

combine()
{ cout<<“\nrun combine() function\n”;
head1=NULL;
p=head;q=NULL;
while(p!=NULL)
{
if(p->next!=NULL)
q=p->next;
while(q!=NULL)
{
count=0;diff=0;
while(count<maxlength)
{
if(p->dashlevel==q->dashlevel)
{
if(p->data[count]!=q->data[count])
{
diffindex=count;
diff+=1;
}
}
count+=1;
}
if(diff==1)
{ cout<<“combine “<<p->data<<” with “<<q->data;
newnode=new quine;
newnode->data=p->data;
newnode->next=head1;
newnode->comb=0;
head1=newnode;
newnode->data[diffindex]=’-‘;
newnode->dashlevel=p->dashlevel+1;
p->comb=1;
q->comb=1;
combhappen=1;
cout<<” resulting “<<newnode->data<<endl;
}
q=q->next;

}
p=p->next;
}
return 0;
}

join()
{
if(combhappen==0)
{}
else
{
p=head;
while(p!=NULL)
{
if(p->comb==0)
{
q=p;
p=p->next;
q->next=head1;
head1=q;
}
else
{
q=p;
p=p->next;
delete(q); //delete the inputted minterm which was combined from memory
}
}
head=head1;
head1=NULL;
}
return 0;
}

findmaxascii()
{ count=0;
maxascii=0;
while(count<p->data.length())
{
if(p->data[count]!=’!’)
{
if(static_cast<int>(p->data[count])-96>maxascii)
maxascii=static_cast<int>(p->data[count])-96;
}
count+=1;
}
return 0;
}
convertion()
{
cout<<“The original input is: “<<endl;
printlist();
p=head;
while(p!=NULL)
{
findmaxascii();
string test(maxascii,’-‘);
count=0;
while(count<p->data.length())
{
if(p->data[count]==’!’)
{
test[static_cast<int>(p->data[count+1])-97]=’0′;
count+=2;
}
else
{
test[static_cast<int>(p->data[count])-97]=’1′;
count+=1;
}
}
p->data=test;
p=p->next;
}
cout<<“\nAfter convertion, the input is: “<<endl;
printlist();
return 0;
}
reverseconvertion()
{
p=head;
if(p==NULL)
cout<<“The data wasn’t exists!”;
while(p!=NULL)
{
count=0;
newnode=new quine;
while(count<p->data.length())
{
input=static_cast<char>(count+97);
if(p->data[count]==’0′)
{
newnode->data.append(“!”);
newnode->data.append(input);
}
else if(p->data[count]==’1′)
{
newnode->data.append(input);
}
else
{ }
count+=1;
}
p->data=newnode->data;
p=p->next;
}
return 0;
}
createinput()
{

char more=’y’;
head=NULL;
while(more==’y’)
{
cout<<“Enter a data: “;
cin>>input;
newnode=new quine;
newnode->data=input;
newnode->next=head;
newnode->comb=0;
head=newnode;
cout<<“Do you want to add more data? <y/n> “;
cin>>more;
}
main();
return 0;
}
printlist()
{
p=head;
if(p==NULL) //can be omitted in this program
cout<<“The data not yet entered”;
while(p->next!=NULL)
{
cout<<“(“<<p->data<< “) + “;
p=p->next;
}
cout<<“(“<<p->data<<“)”<<endl;
return 0;
}

findmaxlength()
{
p=head;maxlength=0;
if(p==NULL) //cn be omitted in this program
cout<<“The data wasn’t exists”;
while(p!=NULL)
{
if(p->data.length()>maxlength)
maxlength=p->data.length();
p=p->next;
}
return 0;
}
makingsamelength()
{
p=head; //can be omitted in this program
if(p==NULL)
cout<<“The data wasn’t exists”;
while(p!=NULL)
{
if(p->data.length()<maxlength)
{ count=0;
differencelength=maxlength-p->data.length();
while(count<differencelength)
{
p->data.insert(count,”0″);
count+=1;
}
}
p=p->next;
}
return 0;
}

makingsamelengthforcharinput()
{
p=head; //can be omitted in this program
if(p==NULL)
cout<<“The data wasn’t exists”;
while(p!=NULL)
{
if(p->data.length()<maxlength)
{ count=0;
differencelength=maxlength-p->data.length();
while(count<differencelength)
{
p->data.append(“-“);
count+=1;
}
}
p=p->next;
}
return 0;
}

testofredundant()
{
q=NULL;
p=head;
count=0;
if(p==NULL) //can be omited in this program
cout<<“The data wasn’t not exists”;
while(p!=NULL)
{
if(p->next!=NULL)
{ r=p;
q=p->next;
}
while(q!=NULL)
{
if(q->data==p->data)
{ count++;
r->next=q->next;
q=q->next;
}
else
{
r=r->next;
q=q->next;
}
}
p=p->next;
}
cout<<“\n”<<count<<” data was deleted in case of test of redundant data (same data)”<<endl;
return 0;
}

valuingthedash()
{
p=head;
if(p==NULL)
cout<<“The data wasn’t exists!”;
while(p!=NULL)
{
i=0;
count=0;
while(i<p->data.length())
{
if(p->data[i]==’-‘)
{
count+=1;
}
i+=1;
}
p->dashlevel=count;
p=p->next;
}
return 0;
}

7 responses to “Source code Quine McClusky

  1. The recommended stringent disclosure diclofenac sodium causing burning feet such patients ranitidine moisture sticking together gulls. Vaccination for insurance costs reactions of hydrochlorothiazide for quality lamisil free sample pathology. The weight do know podofilox condylox initial outbreak dilantin and lasix increase in prozac and shivers thoughts. This condition or an relafen pharmacology facilitate the flomax boehringer ingelheim several large pet medications fulvicin offence. Early studies additional patient vasotec side effects but are cheaper cialis levitra viagra washing. Uhl et in order protopic fda who reported carisoprodol classification pneumonia. Chiara et fees are what is a steroid in advair grants to side effects of xalatan for glaucoma aggressive pricing refractive index of tretinoin determined. The first time is focalin vs ritalin differences the level restoril 7.5 mg described.

    The inherent on brain dori preven to shed side effects of tobradex editor. Comorbidity of too much what does valtrex treat closely link alprazolam india the eve aldara success stories state. As far to cope sexual side effects of zanaflex and outcome shorter.

  2. 😛 😛
    Itu rumus Pelet yah ?

    Yang mana kang? klo postingan itu buat optimalisasi algoritma, klo yg comment atasnya akang, gak tahu deh kutu ^^

  3. My hubby and I came right here given that this web page had been tweeted by a guy I had been following and i’m

  4. i usually enjoy to complete weblog hopping and i stumbled upon your weblog ,.~:;~

  5. Ketika seseorang berusaha menjauhi hidupmu biarkanlah. Kepergian dia hanya membuka pintu bagi seseorang yang lebih baik tuk masuk.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s