Question

In: Computer Science

(C++)Write a small program that implements the "fan tester" logic To recall: Logic in electronic devices....

(C++)Write a small program that implements the "fan tester" logic

To recall:

Logic in electronic devices.

Most of the devices and appliances used in everyday life are controlled by electronic circuitry that works according to the laws of logic. A designer of an electronically-controlled device must first express the desired behavior in logic, and then test that the device behaves as desired under every set of circumstances.

An electronic fan automatically turns on and off depending on the humidity in a room. Since the humidity detector is not very accurate, the fan will stay on for 20 minutes once triggered in order to ensure that the room is cleared of moisture. There is also a manual off switch that can be used to override the automatic functioning of the control.

Define the following propositions:

  • M: The fan has been on for twenty minutes.
  • H: The humidity level in the room is low.
  • O: The manual "off" button has been pushed.

The fan will turn off if the following proposition evaluates to true:

(M∧H)∨O

A truth table can be useful in testing the device to make sure it works as intended under every set of circumstances. The following table might be used by a technician testing the electronic fan.

M HH OO Should be off? (T: yes) Your observation
T T TT T
T T F T
T FF TT T
T F F F
F TT T T
F TT FF F
F FF TT T
F F FF F

Solutions

Expert Solution

C++ Implementation of Fan Tester Logic

#include<iostream>
using namespace std;

int main(){
  
   //fan tester logic implementation in C++
   cout<<"\n\n\n\t\t\t\tFan Tester Logic"<<endl;
  
   //M: It specifies that fan has been on for twenty minutes
   //H: The humidity level is low in the room
   //O: The manual off button has been pushed
  
   //Let's make truth table for that
   //For this purpose, lets take arrays of character data type also specified in the statement
  
   char M[8] = {'T', 'T', 'T', 'T', 'F', 'F', 'F', 'F'};
   char H[8] = {'T', 'T', 'F', 'F', 'T', 'T', 'F', 'F'};
   char O[8] = {'T', 'F', 'T', 'F', 'T', 'F', 'T', 'F'};
  
   char result_of_proposition[8];
   char observation[8];
  
   //The fan will turn off, if the proposition (M ^ H) v O will lead to TRUE
   //Lets Evaluate the proposition
   //------------------------------------( M ^ H ) v O----------------------------
   //-----------^ means AND operator & v means OR operator----------------  

   for(int i=0; i<8 ; i++){
       if( M[i]=='T' && H[i]=='T' || O[i]=='T'){
           //If it is true then result would be true
           result_of_proposition[i] = 'T';
           //My Observation is the same
           observation[i] = 'T';
       }
       else{
           //else the result would be false
           result_of_proposition[i] = 'F';
           //Same
           observation[i] = 'F';
       }
   }
  
   //printing the truth table, means testing the electronic device which in our case, is a fan
  
   cout<<"\n\n\n\t\tM\t"<<"H\t"<<"O\t"<<"(M^H)vO"<<"\t"<<" MyObservation\n"<<endl;
  
   for(int i=0; i<8; i++){
       cout<<"\t\t"<<M[i]<<"\t"<<H[i]<<"\t"<<O[i]<<"\t"<<result_of_proposition[i]<<"\t\t"<<observation[i]<<endl;
   }
  
   cout<<"\n\nT means True means fan will turn off"<<endl;
   return 0;
}

COMMENT DOWN FOR ANY QUERIES........

HIT A THUMBS UP IF YOU LIKE IT!!!


Related Solutions

Write a MARIE program that implements the following logic. If X < Y Then X =...
Write a MARIE program that implements the following logic. If X < Y Then X = X + Y Else Y = 2X Assume the two numbers are X and Y and are entered by the user. Provide prompts to the user to enter the numbers and provide a meaningful output to the screen.
please write a C program that implements Quick Sort algorithm.
please write a C program that implements Quick Sort algorithm.
(i) Compare (a) Mask Programmable Logic Devices, (b) Field Programmable Logic Devices and (c) Field Programmable...
(i) Compare (a) Mask Programmable Logic Devices, (b) Field Programmable Logic Devices and (c) Field Programmable Gate Arrays. (ii) Draw an appropriate schematic diagram to describe following programmable logic devices and discuss their advantages and disadvantages. (a) Programmable Logic Array (b) Programmable Array Logic
Write a program in C++ that efficiently implements a skip list that holds integers. Your program...
Write a program in C++ that efficiently implements a skip list that holds integers. Your program should: 1. Accurately implement the skip list ADT using a random number generator and nodes that contain an integer as well as the addresses of adjacent nodes to the left, right, up, and down. 2. Correctly implement the Insert, Search, and Delete operations. 3. Read a series of unique, newline-delineated integers from a file and insert them (one at a time in the order...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a program in C that implements Conway's Game of Life. You will be expected to...
Write a program in C that implements Conway's Game of Life. You will be expected to apply the principles of Design by Contract to your code. The rules for the Game of Life are simple. The universe consists of a two-dimensional matrix of cells with each cell being alive or dead. For each generation every cell determines its next phase of life as follows: If the cell is alive: it dies if it has 0, 1, 4 or more living...
C++ Write a C++ program that implements a tree using a linked representation Each node will...
C++ Write a C++ program that implements a tree using a linked representation Each node will contain a single integer data element. Initialize the tree to contain 10 nodes. The program should allow for the insertion and deletion of data. The program should allow the user to output data in Preorder, Inorder and Postorder.
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in...
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in zyBooks sections 9.4 and 9.5. Prompt the user for the location of a sequence of numbers, via an external file or data entry by the user. If you choose data entry, prompt the user for the number of values and read them into a data structure of your choice. Then use the mergesort algorithm to sort them in ascending order. Finally, prompt for a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT