SlideShare a Scribd company logo
1 of 4
Download to read offline
the following code should print essential prime implicant but i doesnt help and I also want to
print Also, print the minterms that are not covered by the essential PIs.this is c++
#include
#include
using namespace std;
// Define a structure to store a prime implicant
struct PrimeImplicant {
vector value; // The bit array representing the value of the term
vector dontcare; // The bit array representing the don't care bits (X) of the term
int size; // The size of the term (number of variables)
// Constructor to initialize a prime implicant with a given value and size
PrimeImplicant(vector v, int s) {
value = v;
dontcare = vector(s, false); // Initially no don't care bits
size = s;
}
// A function to print a prime implicant as a Boolean expression
void print() {
char var = 'A'; // The first variable name
bool first = true; // A flag to indicate if this is the first literal in the term
for (int i = 0; i < size; i++) {
if (!dontcare[i]) { // If this bit is not a don't care bit
if (!first) cout << ""; // Print a multiplication sign if not the first literal
else first = false;
if (!value[i]) {
cout << var; // Print the variable name
cout << "'"; // Print a negation sign if this bit is zero
}
else cout << var; // Print the variable name
}
var++; // Increment the variable name
}
cout << endl;
}
};
// A function to compare two prime implicants for equality
bool equal(PrimeImplicant p1, PrimeImplicant p2) {
for (int i = 0; i < p1.size; i++) {
if (p1.value[i] != p2.value[i] || p1.dontcare[i] != p2.dontcare[i]) return false;
}
return true;
}
// A function to check if one prime implicant is contained by another
bool contained(PrimeImplicant p1, PrimeImplicant p2) {
for (int i = 0; i < p1.size; i++) {
if ((p1.value[i] != p2.value[i] && !p2.dontcare[i]) || (p1.dontcare[i] && !p2.dontcare[i]))
return false;
}
return true;
}
// A function to merge two adjacent prime implicants into one larger one
PrimeImplicant merge(PrimeImplicant p1, PrimeImplicant p2) {
int diff = -1; // The index where they differ by one bit
for (int i = 0; i < p1.size; i++) {
if (p1.value[i] != p2.value[i]) { // If they differ by one bit at this index
if (diff == -1) diff = i; // Record the index if this is the first difference found
else return p1; // Otherwise return either one of them as they are not adjacent
}
else if (p1.dontcare[i] != p2.dontcare[i]) return p1; // If they differ by don't care bits at this
index, return either one of them as they are not adjacent
}
PrimeImplicant result(p1.value, p1.size);
result.dontcare[diff] = true;// Make a new prime implicant with same value and size as either
one of them and make its don't care bit true at the index where they differ
return result;// Return the new merged prime implicant
}
// Define an array to store all the given primeimplicants as structures
//vector given;
// Define an array to store all he essential prime implicantsas structures
vector essential;
// A function to find and print all the essential prime implicants using the given prime implicants
void findEssential(vector &given) {
vector temp;// Define a temporary array to store intermediate results
vector used(given.size(), false);// Define an array of flags to mark which given prime
implicants are used or not
bool done;
// A flag to indicate if the simplification process is done or not
done = false;
// Copy all the given prime implicants to the temporary array
for (int i = 0; i < given.size(); i++) {
temp.push_back(given[i]);
}
// Repeat until all essential prime implicants are found
while (!done) {
done = true;
// Check each prime implicant in the temporary array against all the others
for (int i = 0; i < temp.size(); i++) {
bool essentialFlag = true; // A flag to indicate if this prime implicant is essential
for (int j = 0; j < temp.size(); j++) {
if (i != j && contained(temp[i], temp[j])) {
essentialFlag = false; // If this prime implicant is contained in another, it is not
essential
break;
}
}
if (essentialFlag) { // If this prime implicant is essential, add it to the array of essential
prime implicants
essential.push_back(temp[i]);
for (int j = 0; j < given.size(); j++) {
if (equal(temp[i], given[j])) used[j] = true; // Mark the corresponding given prime
implicant as used
}
temp.erase(temp.begin() + i); // Remove this prime implicant from the temporary
array
done = false; // Set the flag to indicate that the simplification process is not done yet
break; // Start over from the beginning of the temporary array
}
}
}
// Print the essential prime implicants
cout << "Essential Prime Implicants:" << endl;
for (int i = 0; i < essential.size(); i++) {
essential[i].print();
}
}
int main() {
// Define the given prime implicants
vector given = {
PrimeImplicant({0,0,0}, 3),
PrimeImplicant({0,0,1}, 3),
PrimeImplicant({0,1,0}, 3),
PrimeImplicant({1,1,0}, 3),
PrimeImplicant({1,1,1}, 3)
};
// Find and print the essential prime implicants
findEssential(given);
return 0;
}

More Related Content

Similar to the following code should print essential prime implicant but i does.pdf

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
C intro
C introC intro
C introKamran
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdfrajat630669
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)Arpit Meena
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfarihantsherwani
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.pptshashankbhadouria4
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptxshashankbhadouria4
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docxajoy21
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
 

Similar to the following code should print essential prime implicant but i does.pdf (20)

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
C intro
C introC intro
C intro
 
Hw3
Hw3Hw3
Hw3
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 
Calculator
CalculatorCalculator
Calculator
 
Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
C programming
C programmingC programming
C programming
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
 
Introduction to Swift
Introduction to SwiftIntroduction to Swift
Introduction to Swift
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
 

More from adwitanokiastore

The following table gives monthly data for four years in million ton.pdf
The following table gives monthly data for four years in million ton.pdfThe following table gives monthly data for four years in million ton.pdf
The following table gives monthly data for four years in million ton.pdfadwitanokiastore
 
the function of the endodermis is- to allow the uptake of nutrien.pdf
the function of the endodermis is- to allow the uptake of nutrien.pdfthe function of the endodermis is- to allow the uptake of nutrien.pdf
the function of the endodermis is- to allow the uptake of nutrien.pdfadwitanokiastore
 
The following questions address fraud risk factors and the assessmen.pdf
The following questions address fraud risk factors and the assessmen.pdfThe following questions address fraud risk factors and the assessmen.pdf
The following questions address fraud risk factors and the assessmen.pdfadwitanokiastore
 
The following statements about asset substitution are true except fo.pdf
The following statements about asset substitution are true except fo.pdfThe following statements about asset substitution are true except fo.pdf
The following statements about asset substitution are true except fo.pdfadwitanokiastore
 
The following is the adjusted trial balance for Stockton Company. St.pdf
The following is the adjusted trial balance for Stockton Company. St.pdfThe following is the adjusted trial balance for Stockton Company. St.pdf
The following is the adjusted trial balance for Stockton Company. St.pdfadwitanokiastore
 
The following data are available pertaining to Household Appliance C.pdf
The following data are available pertaining to Household Appliance C.pdfThe following data are available pertaining to Household Appliance C.pdf
The following data are available pertaining to Household Appliance C.pdfadwitanokiastore
 
The FBI raided President Trumps home in search of documents that th.pdf
The FBI raided President Trumps home in search of documents that th.pdfThe FBI raided President Trumps home in search of documents that th.pdf
The FBI raided President Trumps home in search of documents that th.pdfadwitanokiastore
 
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdf
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdfThe effect of the COVID-19 Pandemic in Australia. Australian autho.pdf
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdfadwitanokiastore
 
The evidence on the relation between participation in the IMF lendin.pdf
The evidence on the relation between participation in the IMF lendin.pdfThe evidence on the relation between participation in the IMF lendin.pdf
The evidence on the relation between participation in the IMF lendin.pdfadwitanokiastore
 
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdf
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdfThe end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdf
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdfadwitanokiastore
 
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdf
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdfThe FBI wants to determine the effectiveness of their 10 Most Wanted.pdf
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdfadwitanokiastore
 
The dollar rate of return on euro deposits isA the euro interest r.pdf
The dollar rate of return on euro deposits isA the euro interest r.pdfThe dollar rate of return on euro deposits isA the euro interest r.pdf
The dollar rate of return on euro deposits isA the euro interest r.pdfadwitanokiastore
 
The cost of an item of property, plant and equipment includes all of.pdf
The cost of an item of property, plant and equipment includes all of.pdfThe cost of an item of property, plant and equipment includes all of.pdf
The cost of an item of property, plant and equipment includes all of.pdfadwitanokiastore
 
The data set below summarizes F2 numbers from an F1 cross arising .pdf
The data set below summarizes F2 numbers from an F1 cross arising .pdfThe data set below summarizes F2 numbers from an F1 cross arising .pdf
The data set below summarizes F2 numbers from an F1 cross arising .pdfadwitanokiastore
 
The book value of equity of a firm at 31122020 is 2.000 million eu.pdf
The book value of equity of a firm at 31122020 is 2.000 million eu.pdfThe book value of equity of a firm at 31122020 is 2.000 million eu.pdf
The book value of equity of a firm at 31122020 is 2.000 million eu.pdfadwitanokiastore
 
The chance of a type 1 error is reduced byStatistically sign.pdf
The chance of a type 1 error is reduced byStatistically sign.pdfThe chance of a type 1 error is reduced byStatistically sign.pdf
The chance of a type 1 error is reduced byStatistically sign.pdfadwitanokiastore
 
The 1948 Declaration of Human Rights covers many areas of diversity .pdf
The 1948 Declaration of Human Rights covers many areas of diversity .pdfThe 1948 Declaration of Human Rights covers many areas of diversity .pdf
The 1948 Declaration of Human Rights covers many areas of diversity .pdfadwitanokiastore
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfadwitanokiastore
 
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdf
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdfTeslas Inc. Accrued liabilities1. Are operating liabilities lar.pdf
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdfadwitanokiastore
 
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdf
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdfTek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdf
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdfadwitanokiastore
 

More from adwitanokiastore (20)

The following table gives monthly data for four years in million ton.pdf
The following table gives monthly data for four years in million ton.pdfThe following table gives monthly data for four years in million ton.pdf
The following table gives monthly data for four years in million ton.pdf
 
the function of the endodermis is- to allow the uptake of nutrien.pdf
the function of the endodermis is- to allow the uptake of nutrien.pdfthe function of the endodermis is- to allow the uptake of nutrien.pdf
the function of the endodermis is- to allow the uptake of nutrien.pdf
 
The following questions address fraud risk factors and the assessmen.pdf
The following questions address fraud risk factors and the assessmen.pdfThe following questions address fraud risk factors and the assessmen.pdf
The following questions address fraud risk factors and the assessmen.pdf
 
The following statements about asset substitution are true except fo.pdf
The following statements about asset substitution are true except fo.pdfThe following statements about asset substitution are true except fo.pdf
The following statements about asset substitution are true except fo.pdf
 
The following is the adjusted trial balance for Stockton Company. St.pdf
The following is the adjusted trial balance for Stockton Company. St.pdfThe following is the adjusted trial balance for Stockton Company. St.pdf
The following is the adjusted trial balance for Stockton Company. St.pdf
 
The following data are available pertaining to Household Appliance C.pdf
The following data are available pertaining to Household Appliance C.pdfThe following data are available pertaining to Household Appliance C.pdf
The following data are available pertaining to Household Appliance C.pdf
 
The FBI raided President Trumps home in search of documents that th.pdf
The FBI raided President Trumps home in search of documents that th.pdfThe FBI raided President Trumps home in search of documents that th.pdf
The FBI raided President Trumps home in search of documents that th.pdf
 
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdf
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdfThe effect of the COVID-19 Pandemic in Australia. Australian autho.pdf
The effect of the COVID-19 Pandemic in Australia. Australian autho.pdf
 
The evidence on the relation between participation in the IMF lendin.pdf
The evidence on the relation between participation in the IMF lendin.pdfThe evidence on the relation between participation in the IMF lendin.pdf
The evidence on the relation between participation in the IMF lendin.pdf
 
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdf
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdfThe end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdf
The end of bureaucracy Introduction Haier, based in Qingdao, Chi.pdf
 
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdf
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdfThe FBI wants to determine the effectiveness of their 10 Most Wanted.pdf
The FBI wants to determine the effectiveness of their 10 Most Wanted.pdf
 
The dollar rate of return on euro deposits isA the euro interest r.pdf
The dollar rate of return on euro deposits isA the euro interest r.pdfThe dollar rate of return on euro deposits isA the euro interest r.pdf
The dollar rate of return on euro deposits isA the euro interest r.pdf
 
The cost of an item of property, plant and equipment includes all of.pdf
The cost of an item of property, plant and equipment includes all of.pdfThe cost of an item of property, plant and equipment includes all of.pdf
The cost of an item of property, plant and equipment includes all of.pdf
 
The data set below summarizes F2 numbers from an F1 cross arising .pdf
The data set below summarizes F2 numbers from an F1 cross arising .pdfThe data set below summarizes F2 numbers from an F1 cross arising .pdf
The data set below summarizes F2 numbers from an F1 cross arising .pdf
 
The book value of equity of a firm at 31122020 is 2.000 million eu.pdf
The book value of equity of a firm at 31122020 is 2.000 million eu.pdfThe book value of equity of a firm at 31122020 is 2.000 million eu.pdf
The book value of equity of a firm at 31122020 is 2.000 million eu.pdf
 
The chance of a type 1 error is reduced byStatistically sign.pdf
The chance of a type 1 error is reduced byStatistically sign.pdfThe chance of a type 1 error is reduced byStatistically sign.pdf
The chance of a type 1 error is reduced byStatistically sign.pdf
 
The 1948 Declaration of Human Rights covers many areas of diversity .pdf
The 1948 Declaration of Human Rights covers many areas of diversity .pdfThe 1948 Declaration of Human Rights covers many areas of diversity .pdf
The 1948 Declaration of Human Rights covers many areas of diversity .pdf
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
 
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdf
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdfTeslas Inc. Accrued liabilities1. Are operating liabilities lar.pdf
Teslas Inc. Accrued liabilities1. Are operating liabilities lar.pdf
 
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdf
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdfTek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdf
Tek bir bamsz deiken i�eren bir regresyon modeline ________ de.pdf
 

Recently uploaded

ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

the following code should print essential prime implicant but i does.pdf

  • 1. the following code should print essential prime implicant but i doesnt help and I also want to print Also, print the minterms that are not covered by the essential PIs.this is c++ #include #include using namespace std; // Define a structure to store a prime implicant struct PrimeImplicant { vector value; // The bit array representing the value of the term vector dontcare; // The bit array representing the don't care bits (X) of the term int size; // The size of the term (number of variables) // Constructor to initialize a prime implicant with a given value and size PrimeImplicant(vector v, int s) { value = v; dontcare = vector(s, false); // Initially no don't care bits size = s; } // A function to print a prime implicant as a Boolean expression void print() { char var = 'A'; // The first variable name bool first = true; // A flag to indicate if this is the first literal in the term for (int i = 0; i < size; i++) { if (!dontcare[i]) { // If this bit is not a don't care bit if (!first) cout << ""; // Print a multiplication sign if not the first literal else first = false; if (!value[i]) { cout << var; // Print the variable name cout << "'"; // Print a negation sign if this bit is zero } else cout << var; // Print the variable name } var++; // Increment the variable name } cout << endl; }
  • 2. }; // A function to compare two prime implicants for equality bool equal(PrimeImplicant p1, PrimeImplicant p2) { for (int i = 0; i < p1.size; i++) { if (p1.value[i] != p2.value[i] || p1.dontcare[i] != p2.dontcare[i]) return false; } return true; } // A function to check if one prime implicant is contained by another bool contained(PrimeImplicant p1, PrimeImplicant p2) { for (int i = 0; i < p1.size; i++) { if ((p1.value[i] != p2.value[i] && !p2.dontcare[i]) || (p1.dontcare[i] && !p2.dontcare[i])) return false; } return true; } // A function to merge two adjacent prime implicants into one larger one PrimeImplicant merge(PrimeImplicant p1, PrimeImplicant p2) { int diff = -1; // The index where they differ by one bit for (int i = 0; i < p1.size; i++) { if (p1.value[i] != p2.value[i]) { // If they differ by one bit at this index if (diff == -1) diff = i; // Record the index if this is the first difference found else return p1; // Otherwise return either one of them as they are not adjacent } else if (p1.dontcare[i] != p2.dontcare[i]) return p1; // If they differ by don't care bits at this index, return either one of them as they are not adjacent } PrimeImplicant result(p1.value, p1.size); result.dontcare[diff] = true;// Make a new prime implicant with same value and size as either one of them and make its don't care bit true at the index where they differ return result;// Return the new merged prime implicant } // Define an array to store all the given primeimplicants as structures //vector given; // Define an array to store all he essential prime implicantsas structures vector essential;
  • 3. // A function to find and print all the essential prime implicants using the given prime implicants void findEssential(vector &given) { vector temp;// Define a temporary array to store intermediate results vector used(given.size(), false);// Define an array of flags to mark which given prime implicants are used or not bool done; // A flag to indicate if the simplification process is done or not done = false; // Copy all the given prime implicants to the temporary array for (int i = 0; i < given.size(); i++) { temp.push_back(given[i]); } // Repeat until all essential prime implicants are found while (!done) { done = true; // Check each prime implicant in the temporary array against all the others for (int i = 0; i < temp.size(); i++) { bool essentialFlag = true; // A flag to indicate if this prime implicant is essential for (int j = 0; j < temp.size(); j++) { if (i != j && contained(temp[i], temp[j])) { essentialFlag = false; // If this prime implicant is contained in another, it is not essential break; } } if (essentialFlag) { // If this prime implicant is essential, add it to the array of essential prime implicants essential.push_back(temp[i]); for (int j = 0; j < given.size(); j++) { if (equal(temp[i], given[j])) used[j] = true; // Mark the corresponding given prime implicant as used } temp.erase(temp.begin() + i); // Remove this prime implicant from the temporary array done = false; // Set the flag to indicate that the simplification process is not done yet break; // Start over from the beginning of the temporary array
  • 4. } } } // Print the essential prime implicants cout << "Essential Prime Implicants:" << endl; for (int i = 0; i < essential.size(); i++) { essential[i].print(); } } int main() { // Define the given prime implicants vector given = { PrimeImplicant({0,0,0}, 3), PrimeImplicant({0,0,1}, 3), PrimeImplicant({0,1,0}, 3), PrimeImplicant({1,1,0}, 3), PrimeImplicant({1,1,1}, 3) }; // Find and print the essential prime implicants findEssential(given); return 0; }