Question
Below is Code 3 that you are going to modify to make Code 5: /* Coding Assignment 3 */ #include /* prototypes */ void ConvertDecimalToBinary(int
Below is Code 3 that you are going to modify to make Code 5:
/* Coding Assignment 3 */ #include/* prototypes */ void ConvertDecimalToBinary(int DecNum, int BitArray[]); void PrintBinary(int BinaryNumber[]); void ConvertDecimalToBinary(int DecimalNum, int BitArray[]) { int i; BitArray[7] = DecimalNum; /* right bitshift to divide by 2 */ for (i = 6; i >= 0; i--) { BitArray[i] = BitArray[i+1] >> 1; } printf(" Decimal %d converts to binary ", DecimalNum); /* use a bitmask of 1 to determine if odd or even */ for (i = 0; i <= 7; i++) { BitArray[i] = (BitArray[i] & 1) ? 1 : 0; } return; } void PrintBinary(int BinaryNumber[]) { int i; for (i = 0; i <= 7; i++) { printf("%d", BinaryNumber[i]); } printf(" "); } int main(void) { int DecNum; int AskAgain = 1; int BinaryNumber[8]; printf("Decimal to binary convertor "); while (AskAgain) { printf("Please enter a decimal number between 0 and 255 "); scanf("%d", &DecNum); if (DecNum >= 0 && DecNum <= 255) AskAgain = 0; else { AskAgain = 1; printf(" You entered a number not between 0 and 255 "); } } ConvertDecimalToBinary(DecNum, BinaryNumber); PrintBinary(BinaryNumber); return 0; }
Below is the Makefile format you to to use for your solution:
SRC = Test.c
OBJ = $(SRC:.c=.o)
EXE = $(SRC:.c=.e)
CFLAGS = -g
LIBS = MyLib.o
all : $(EXE)
$(EXE): $(OBJ)
gcc $(CFLAGS) $(OBJ) $(LIBS) -o $(EXE)
$(OBJ) : $(SRC)
gcc -c $(SRC)
Below is the RUBRIC you need to satsfiy in making your solution for CODE 5
Coding Assignment 5
1. Create a makefile named "makefile" (template posted on Blackboard)
It will compile "Code5_xxxxxxxxxx.c" where xxxxxxxxxx is your student id
Add your name and id as a first line comment comments start with #
FTP makefile to Omega
2. Create "Code5_xxxxxxxxxx.c"
Modify " Code3_xxxxxxxxxx.c"
Either start with the posted version or your own
Add your name and id as a first line comment
Remove the code and prototypes for (you will move them to MyLib.c)
ConvertDecimalToBinary()
PrintBinary()
Add include for "MyLib.h"
FTP Code5_xxxxxxxxxxx.c to Omega
3. Create your own library
"MyLib.c"
Add your name and id as a first line comment
Should contain 2 includes
#include
#include "MyLib.h"
Should contain 2 functions
ConvertDecimalToBinary()
PrintBinary()
"MyLib.h"
Add your name and id as a first line comment
Should contain 2 prototypes (no main() only the code for the functions)
ConvertDecimalToBinary()
PrintBinary()
Add #ifndef, #define and #endif
Create the library object file "MyLib.o"
FTP MyLib.c and MyLib.h to Omega
gcc -c MyLib.c -o MyLib.o
4. On Omega, compile your code
make
or
make B
You should see
~]$ make
gcc -c Code5_1000074079.c
gcc -g Code5_1000074079.o MyLib.o -o Code5_1000074079.e
You should then be able to run your new executable
~]$ Code5_1000074079.e
Decimal to binary convertor
Please enter a decimal number between 0 and 255 172
Decimal 172 converts to binary 10101100
You will need to submit/upload
MyLib.c
MyLib.h
makefile
Code5_xxxxxxxxxxx.c
Thanks in advance!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started