Question:
basic c programing help?
KingMace
2012-02-08 09:07:50 UTC
Write a program that controls an Alarm System. Alarm System uses memory location CURRENT INPUT for several inputs (alarm sensors) that are being monitored: Ground Floor Window 1, Ground Floor Window 2, 2nd Floor Window, Front Door, Back Door, CO Alarm, Emergency Button, and Fire.
Default values of all inputs are stored in the memory location DEFAULT INPUT as ON, ON, ON, ON, ON, OFF, OFF, OFF. Default status represents the alarm sensors’ state that does not trigger an alarm. For example, the last bit represents the Ground Floor Window 1 and its normal state (state that does not trigger an alarm) is ON (represented with 1). When the window is opened, the bit changes to 0, and the alarm is triggered.
Write a C program that will ask the user to enter a Hex value representing the current state of the Alarm System inputs, and to determine which CURRENT INPUT bits are ON using a mask and an applicable Bitwise operation. The program will also print CURRENT INPUT in hexadecimal format, CURRENT INPUT in decimal format, and bit numbers of the CURRENT INPUT which are ON. An example of the output of your program could be as follows:
CURRENT INPUT is set to XX (Hex)
CURRENT INPUT is set to YY (Decimal)
Bits x x x are set.
The program will then determine which of inputs have been changed (compared to default values) using an applicable Bitwise operation, and print all reasons for triggering an alarm. An example of the output of your program could be as follows:

Alarm:
Front door open!
Fire Alarm!


Hints:
Use the unsigned data type where applicable.
Format specifier for Hexadecimal numbers is %x . Format specifier for unsigned integer numbers is %u .
Three answers:
McFate
2012-02-08 09:26:55 UTC
"Help"? Sure.



"Do your homework for you?" No, that would be a disservice to you, and leave you unprepared for tests and harder assignments that will follow.



Hint:



If you want to know if the i'th bit of x is set, do something like this:



if ( (1 << i) & x ) {

// set

} else {

// not set

}



@M
duperne
2016-12-11 14:30:59 UTC
Being good with computers and being waiting to application are entire diverse. besides the reality that they could especially circumstances bypass hand in hand, programming demands a particularly extreme point of logical competence. i might say that in case you have been good at doing word issues in math classification then you certainly ought to be alright to code. you do no longer choose C to do Java. Programming is often very comparable for the time of languages, with purely the syntax changing (a minimum of from my experience). however the way you think of and that they way you handle courses is often an identical. some human beings %. it up very without postpone and a few human beings in no way get the dangle of it. that is in simple terms like how some human beings are certainly inventive and a few are not. Programming is my artwork ^_^ i'm in a working laptop or workstation programming application and that i like it. Java is an remarkable element to benefit so have exciting. in case you elect to start getting huge-unfold, i choose to propose you get carry of Eclipse and initiate making your person trouble-free courses. in case you elect some help on destiny issues or the different tips, be happy to digital mail as i'm consistently happy to help different budding programmers =)
tbshmkr
2012-02-08 09:57:56 UTC
Show your code.

=

Then people will HELP YOU get it right.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...