In: Computer Science
(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:
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 |
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!!!