Write code in C please, read question carefully! For question 1) here is the mak
ID: 3733318 • Letter: W
Question
Write code in C please, read question carefully!For question 1) here is the makefile temple: 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)
For question number 2) you can use create your own or use this temple: THIS IS NOT THE CODE FOR THE ASSIGNMENT, JUST A TEMPLE YOU HAVE TO MODFIY IF YOU WANT TO USE IT. BUT CAN MAKE THE CODE RUN AND LOOK LIKE THIS!: #include <stdio.h>
/* 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; }
For question 1) here is the makefile temple: 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)
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)
For question number 2) you can use create your own or use this temple: THIS IS NOT THE CODE FOR THE ASSIGNMENT, JUST A TEMPLE YOU HAVE TO MODFIY IF YOU WANT TO USE IT. BUT CAN MAKE THE CODE RUN AND LOOK LIKE THIS!: #include <stdio.h>
/* 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; } #include <stdio.h>
/* 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; }
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 ConvertDecimalToBinary) PrintBinary () Add include for "MyLib.h"
Explanation / Answer
Hi,
Below are the required files:
MyLib.h
#ifndef SRC_MYLIB_H_
#define SRC_MYLIB_H_
void ConvertDecimalToBinary(int,int[]);
void PrintBinary(int[]);
#endif /* SRC_MYLIB_H_ */
MyLib.c
Code5_xxxxxxx.c
Please replace xxxxxxx with your student id in filename
makefile
Please change the first line of the make file as per your student id.