Write a program to generate a truth table for a

Write a program to generate a truth table for a given Boolean statement. For example, A + B * C produces the following table:

A B C | B * C | A + B * C

===============================

0 0 0 | 0 | 0

0 0 1 | 0 | 0

0 1 0 | 0 | 0

0 1 1 | 1 | 1

1 0 0 | 0 | 1

1 0 1 | 0 | 1

1 1 0 | 0 | 1

1 1 1 | 1 | 1

Input from the keyboard a string representing a Boolean expression where the operators are the following: ! (NOT), * (AND), + (OR), ^ (XOR). Single sets of parentheses can be used if needed. Covert all letters to uppercase and have one space between each operator. The truth table must be able to handle up to four variables and be in binary order. For example, in the first test case, if the Boolean values of A, B, and C were replaced with 1’s for true and 0’s for false, the Boolean combination with the smallest binary representation would come first.

Output to the screen a truth table for the given Boolean expression. The first column of the truth table should represent A, the second B, the third C, and so on. Each binary operation must have its own column and all columns must be labeled. The entries in each column should be aligned and formatted with capital letters like the examples below. Except for the final column, columns do not have to be in any order except the order of operations must be followed to get the correct final answer. Finally, the program should ask if the user wants to run the program again (Check case). Refer to the sample output below.

Sample Run:

Enter the Boolean expression: A + B * C

A B C | B * C | A + B * C

===============================

0 0 0 | 0 | 0

0 0 1 | 0 | 0

0 1 0 | 0 | 0

0 1 1 | 1 | 1

1 0 0 | 0 | 1

1 0 1 | 0 | 1

1 1 0 | 0 | 1

1 1 1 | 1 | 1

Run again (Y/N)? y

Enter the Boolean expression: (!A * B) ^ (B + C)

A B C | !A * B | B + C | (!A * B) ^ (B + C)

=================================================

0 0 0 | 0 | 0 | 0

0 0 1 | 0 | 1 | 1

0 1 0 | 1 | 1 | 0

0 1 1 | 1 | 1 | 0

1 0 0 | 0 | 0 | 0

1 0 1 | 0 | 1 | 1

1 1 0 | 0 | 1 | 1

1 1 1 | 0 | 1 | 1

Run again (Y/N)? N

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

PLEASE FOLLOW THE FOLLOWING INSTRUCTIONS BELOW: ZERO (0) PLAGIAR 3 -5

PLEASE FOLLOW THE FOLLOWING INSTRUCTIONS BELOW: ZERO (0) PLAGIAR 3 -5 REFERENCES NO MORE THAN 5 YEARS OLD PLEASE SEE THE ATTACHED RUBRIC You have probably seen one or more of the many inspirational posters about decisions. A visual such as a forked road or a street sign is typically

After reading the poem “To Roosevelt” by Ruben Dario (found

  After reading the poem “To Roosevelt” by Ruben Dario (found in the Modernismo in Latin American American literature page), answer the following prompt in a focused response: How does the speaker of the poem view Latin American countries and their relationship with the U.S.? Provide examples from the poem

Read Chapters 9 and 10 in your textbook : Principles

Read Chapters 9 and 10 in your textbook : Principles of Information Systems Using the discussion link below, respond to the following prompts and questions: Describe the use of business intelligence (BI) in a real-world situation that you have experienced, or research BI used within a Fortune 1000 organization. What

In 1933, Harry Hopkins, one of FDR’s top advisors, argued

In 1933, Harry Hopkins, one of FDR’s top advisors, argued that public welfare should not be a haven for professional social work practice. In the 1960s, the Public Welfare Association asserted that having social workers in public welfare programs would not only improve the life of poor families, but also

Forensic Accounting and Fraud Examination Read Chapters 15 and 16

  Forensic Accounting and Fraud Examination Read Chapters 15 and 16 in Forensic Accounting and Fraud Examination. The process of remediation occurs after the fraud has been discovered, analyzed and documented. Discuss what the term remediation means and the steps that a forensic accountant would be involved in to complete

As you observed in the LIVE session, there is a

  As you observed in the LIVE session, there is a connection between chapter three and chapter one. Therefore, as an extension of our week in the mock chapter three from last week, we will write a mock chapter one. For the sake of preparation, we will be using the

Ethical Decision Making and Hiring

 Assignment: Ethical Decision Making and Hiring 2. Explain the differences, importance, and purpose of both the code of conduct and the code of ethics. Secondly, tell me about some of the factors that you would use to make ethical hiring decisions in an organization. Why would these be important to

Please read attached KFC case study. Answer following questions 2.

Please read attached KFC case study. Answer following questions 2. Why are cultural factors so important to KFC’s sales success in India and china? 3. Spot the cultural factors in India that go against KFC’s Original recipe. Please follow case study guidelines. I want it in the format mentioned in

First, read the case Lehman Brothers: The Fall from Grace

First, read the case Lehman Brothers: The Fall from Grace attached PDF file Then answer the questions. In your initial response to the topic you have to answer all questions: What was the main reason of Lehman Brothers bankruptcy? Do you think Richard Severin Fuld Jr. to be held more

Origin of a human trait

 Week 9 discussion – origin of a human trait This week we will be continuing our discussion of human evolution. Choose a trait that humans have that you are interested in and find a primary research paper (published within the last ten years) that traces it back in a phylogeny

Write a 500-600-word essay plus a KU title page and reference page in a scholarly format on this activity specifically addressing the questions that are asked. Analyze the responses, how do you think Nursing Assignment Help

Write a 500-600-word essay plus a KU title page and reference page in a scholarly format on this activity specifically addressing the questions that are asked. Analyze the responses, how do you think these questions would be addressed by the general public.  Between you and two other people, discuss how

Continuum and Coordination of Health Care Presentation

To develop the content for your presentation, record detailed notes as you complete the following steps. Review the information about the continuum and coordination of health services presented in the Learning Resources, including the HIMSS resource, Continuum of Care, and the tables in Chapter 1 of the course text. Develop

Week 10 Discussion COLLAPSEOverall Rating: To successfully complete this week’s

 Week 10 Discussion COLLAPSEOverall Rating: To successfully complete this week’s discussion, you will need to: Please respond to the following in a substantive post.  Address these questions: Do lineups still appear to be effective? Why or why not? Is eyewitness identification still a proper investigation tool?  What point in the

write 400–600 words that respond to the following questions with

  write 400–600 words that respond to the following questions with your thoughts, ideas, and comments. This will be the foundation for future discussions by your classmates. Be substantive and clear, and use examples to reinforce your ideas. Consideration of workforce diversity is a part of human resource management (HRM).

The practice of health care providers at all levels brings you into contact with people from a variety of faiths. This calls for knowledge and understanding of a diversity of faith expressions; for th Nursing Assignment Help

The practice of health care providers at all levels brings you into contact with people from a variety of faiths. This calls for knowledge and understanding of a diversity of faith expressions; for the purpose of this course, the focus will be on the Christian worldview. Based on “Case Study: