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.
(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 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 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...
Write a class called Name. A tester program is provided in Codecheck, but there is no...
Write a class called Name. A tester program is provided in Codecheck, but there is no starting code for the Name class. The constructor takes a String parameter representing a person's full name. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -, but not ending with either of them. The class has the following method: • public String getName() Gets the name string. • public int consonants()...
Write a class called Name. A tester program is provided in Codecheck, but there is no...
Write a class called Name. A tester program is provided in Codecheck, but there is no starting code for the Name class. The constructor takes a String parameter representing a person's full name. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -, but not ending with either of them. The class has the following methods. • public String getName() Gets the name string. • public int consonants()...
Write program logic or pseudocode to create 3 small programs that do the following: The first...
Write program logic or pseudocode to create 3 small programs that do the following: The first should compute the sum of 2 given integers. The second should multiply the 2 integers. The third should triple the sum of the 2 integers.
Write a c++ Program To simulate the messages sent by the various IoT devices, a text...
Write a c++ Program To simulate the messages sent by the various IoT devices, a text le called device data.txt is provided that contains a number of device messages sent, with each line representing a distinct message. Each message contains a device name, a status value and a Unix epoch value which are separated by commas. Your c++ program will read this le line by line. It will separate the message into device name, status value and epoch value and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT