SlideShare a Scribd company logo
1 of 12
Download to read offline
Answer:
Note: Entire skeleton of the code is provided. The below code is implemented as per the
declarations provided.
Program code:
#include
#include
#include
typedef uint64_t weatherlog_t;
unsigned int add(unsigned int, unsigned int);
unsigned int sub(unsigned int, unsigned int);
unsigned int mul(unsigned int, unsigned int);
void print_half_nybbles(unsigned int);
unsigned int reverse_half_nybbles(unsigned int);
int has_odd(unsigned int);
unsigned int make_odd(unsigned int);
int is_negative(int);
weatherlog_t pack_log_entry(unsigned int, unsigned int, unsigned int,
unsigned int,
int, int,
unsigned int, unsigned int);
unsigned int get_year(weatherlog_t entry);
unsigned int get_month(weatherlog_t entry);
unsigned int get_day(weatherlog_t entry);
unsigned int get_zip(weatherlog_t entry);
unsigned int get_high(weatherlog_t entry);
unsigned int get_low(weatherlog_t entry);
unsigned int get_precip(weatherlog_t entry);
unsigned int get_wind(weatherlog_t entry);
int main(int argc, char **argv) {
unsigned int i, j;
int x, y;
unsigned int year, month, day,
zip, high_temp, low_temp, precip, avg_wind_speed;
weatherlog_t log_entry;
printf("Enter an integer: ");
scanf("%u", &i);
printf("Enter another integer: ");
scanf("%u", &j);
printf("One more integer, please: ");
scanf("%d", &x);
printf("Please enter a positive integer: ");
scanf("%d", &y);
printf("i + j = %u ", add(i,j));
printf("i - j = %u ", sub(i,j));
printf("i * j = %u ", mul(i,j));
if (is_negative(x))
printf("%d is negative ", x);
else
printf("%d is non-negative ", x);
if (has_odd(y)) {
printf("%x has an odd number of bits in its binary representation ", y);
}
else {
printf("%x has an even number of bits in its binary representation ", y);
printf("but %x has an odd number of bits in its binary representation ", make_odd(y));
}
printf("The half-nybbles of %d (in hex 0x%x) are:", x, x);
print_half_nybbles(x);
printf("%x with reversed half-nybbles is %x ", x, reverse_half_nybbles(x));
printf("Enter a year: ");
scanf("%u", &year);
printf("Enter a month as an integer (1-12): ");
scanf("%u", &month);
printf("Enter a day as an integer (1-31): ");
scanf("%u", &day);
printf("Enter a zip code as an integer (0-99999): ");
scanf("%u", &zip);
printf("Enter a temperature as an integer: ");
scanf("%u", &high_temp);
printf("Enter another temperature as an integer: ");
scanf("%u", &low_temp);
printf("Enter rainfall amount as an integer (mm): ");
scanf("%u", &precip);
printf("Enter a as an integer (km/hr): ");
scanf("%u", &avg_wind_speed);
log_entry=pack_log_entry(year, month, day, zip, high_temp, low_temp,
precip, avg_wind_speed);
printf("You entered: %u/%u/%u for zip %5d: high %d F, low %d F, precip %d mm, wind
speed %d km/hr ",
get_day(log_entry), get_month(log_entry), get_year(log_entry),
get_zip(log_entry), get_high(log_entry), get_low(log_entry),
get_precip(log_entry), get_wind(log_entry));
system("pause");
return 0;
}
unsigned int add(unsigned int i, unsigned int j) {
unsigned int t, r;
t = i ^ j;
while((r = i & j) != 0) {
i = t;
j = r << 1;
t = i ^ j;
}
return t;
}
unsigned int sub(unsigned int i, unsigned int j) {
j = add(~j,1);
return add(i,j);
}
unsigned int mul(unsigned int i, unsigned int j) {
unsigned int k, product = 0;
for(k = 0; k < j; k = add(k,1)) {
product = add(product,i);
}
return product;
}
void print_half_nybbles(unsigned int x) {
unsigned int i = 0, t = 0x3;
while(t != 0) {
printf("%u", (x & t) >> i);
t <<= 2;
i = add(i,2);
}
printf(" ");
}
unsigned int reverse_half_nybbles(unsigned int i) {
unsigned r = 0, s = 0, t = 0x3, j = 0;
while(j < mul(sizeof(i),8)) {
r = (i >> j) & t;
s<<=2;
s = add(s,r);
j = add(j,2);
}
return s;
}
int is_negative(int x) {
return (x & 0x80000000) != 0;
}
int has_odd(unsigned int x) {
unsigned int count = 0, i = 0, j = 1;
while(i < mul(sizeof(x),8)) {
if((x & j) == j)
count = add(count,1);
i = add(i,1);
j = mul(j,2);
}
return (count & 1) == 1;
}
unsigned int make_odd(unsigned int x) {
if(!has_odd(x))
x ^= 0x80000000;
return x;
}
weatherlog_t pack_log_entry(unsigned int year, unsigned int month, unsigned int day,
unsigned int zip, int high_temp, int low_temp,
unsigned int precip, unsigned int avg_wind_speed) {
weatherlog_t log_entry = 0;
log_entry ^= sub(year,2000);
log_entry <<= 4;
log_entry ^= month;
log_entry <<= 5;
log_entry ^= day;
log_entry <<= 16;
log_entry ^= zip;
log_entry <<= 8;
log_entry ^= high_temp;
log_entry <<= 8;
log_entry ^= low_temp;
log_entry <<= 10;
log_entry ^= precip;
log_entry <<= 7;
log_entry ^= avg_wind_speed;
return log_entry;
}
unsigned int get_year(weatherlog_t entry) {
return entry >> 58;
}
unsigned int get_month(weatherlog_t entry) {
return 0xf & (entry >> 54);
}
unsigned int get_day(weatherlog_t entry) {
return 0x1f & (entry >> 49);
}
unsigned int get_zip(weatherlog_t entry) {
return 0xffff & (entry >> 33);
}
unsigned int get_high(weatherlog_t entry){
return 0xff & (entry >> 25);
}
unsigned int get_low(weatherlog_t entry) {
return 0xff & (entry >> 17);
}
unsigned int get_precip(weatherlog_t entry) {
return 0x3ff & (entry >> 7);
}
unsigned int get_wind(weatherlog_t entry) {
return 0x7f & entry;
}
Sample Output:
Enter an integer: 1
Enter another integer: 2
One more integer, please: 3
Please enter a positive integer: 4
i + j = 3
i - j = 4294967295
i * j = 2
3 is non-negative
4 has an odd number of bits in its binary representation
The half-nybbles of 3 (in hex 0x3) are:3000000000000000
3 with reversed half-nybbles is c0000000
Enter a year: 2016
Enter a month as an integer (1-12): 10
Enter a day as an integer (1-31): 5
Enter a zip code as an integer (0-99999): 600028
Enter a temperature as an integer: 12
Enter another temperature as an integer: 34
Enter rainfall amount as an integer (mm): 33
Enter a as an integer (km/hr): 3
You entered: 12/10/16 for zip 10204: high 12 F, low 34 F, precip 33 mm, wind spe
ed 3 km/hr
Press any key to continue . . .
Solution
Answer:
Note: Entire skeleton of the code is provided. The below code is implemented as per the
declarations provided.
Program code:
#include
#include
#include
typedef uint64_t weatherlog_t;
unsigned int add(unsigned int, unsigned int);
unsigned int sub(unsigned int, unsigned int);
unsigned int mul(unsigned int, unsigned int);
void print_half_nybbles(unsigned int);
unsigned int reverse_half_nybbles(unsigned int);
int has_odd(unsigned int);
unsigned int make_odd(unsigned int);
int is_negative(int);
weatherlog_t pack_log_entry(unsigned int, unsigned int, unsigned int,
unsigned int,
int, int,
unsigned int, unsigned int);
unsigned int get_year(weatherlog_t entry);
unsigned int get_month(weatherlog_t entry);
unsigned int get_day(weatherlog_t entry);
unsigned int get_zip(weatherlog_t entry);
unsigned int get_high(weatherlog_t entry);
unsigned int get_low(weatherlog_t entry);
unsigned int get_precip(weatherlog_t entry);
unsigned int get_wind(weatherlog_t entry);
int main(int argc, char **argv) {
unsigned int i, j;
int x, y;
unsigned int year, month, day,
zip, high_temp, low_temp, precip, avg_wind_speed;
weatherlog_t log_entry;
printf("Enter an integer: ");
scanf("%u", &i);
printf("Enter another integer: ");
scanf("%u", &j);
printf("One more integer, please: ");
scanf("%d", &x);
printf("Please enter a positive integer: ");
scanf("%d", &y);
printf("i + j = %u ", add(i,j));
printf("i - j = %u ", sub(i,j));
printf("i * j = %u ", mul(i,j));
if (is_negative(x))
printf("%d is negative ", x);
else
printf("%d is non-negative ", x);
if (has_odd(y)) {
printf("%x has an odd number of bits in its binary representation ", y);
}
else {
printf("%x has an even number of bits in its binary representation ", y);
printf("but %x has an odd number of bits in its binary representation ", make_odd(y));
}
printf("The half-nybbles of %d (in hex 0x%x) are:", x, x);
print_half_nybbles(x);
printf("%x with reversed half-nybbles is %x ", x, reverse_half_nybbles(x));
printf("Enter a year: ");
scanf("%u", &year);
printf("Enter a month as an integer (1-12): ");
scanf("%u", &month);
printf("Enter a day as an integer (1-31): ");
scanf("%u", &day);
printf("Enter a zip code as an integer (0-99999): ");
scanf("%u", &zip);
printf("Enter a temperature as an integer: ");
scanf("%u", &high_temp);
printf("Enter another temperature as an integer: ");
scanf("%u", &low_temp);
printf("Enter rainfall amount as an integer (mm): ");
scanf("%u", &precip);
printf("Enter a as an integer (km/hr): ");
scanf("%u", &avg_wind_speed);
log_entry=pack_log_entry(year, month, day, zip, high_temp, low_temp,
precip, avg_wind_speed);
printf("You entered: %u/%u/%u for zip %5d: high %d F, low %d F, precip %d mm, wind
speed %d km/hr ",
get_day(log_entry), get_month(log_entry), get_year(log_entry),
get_zip(log_entry), get_high(log_entry), get_low(log_entry),
get_precip(log_entry), get_wind(log_entry));
system("pause");
return 0;
}
unsigned int add(unsigned int i, unsigned int j) {
unsigned int t, r;
t = i ^ j;
while((r = i & j) != 0) {
i = t;
j = r << 1;
t = i ^ j;
}
return t;
}
unsigned int sub(unsigned int i, unsigned int j) {
j = add(~j,1);
return add(i,j);
}
unsigned int mul(unsigned int i, unsigned int j) {
unsigned int k, product = 0;
for(k = 0; k < j; k = add(k,1)) {
product = add(product,i);
}
return product;
}
void print_half_nybbles(unsigned int x) {
unsigned int i = 0, t = 0x3;
while(t != 0) {
printf("%u", (x & t) >> i);
t <<= 2;
i = add(i,2);
}
printf(" ");
}
unsigned int reverse_half_nybbles(unsigned int i) {
unsigned r = 0, s = 0, t = 0x3, j = 0;
while(j < mul(sizeof(i),8)) {
r = (i >> j) & t;
s<<=2;
s = add(s,r);
j = add(j,2);
}
return s;
}
int is_negative(int x) {
return (x & 0x80000000) != 0;
}
int has_odd(unsigned int x) {
unsigned int count = 0, i = 0, j = 1;
while(i < mul(sizeof(x),8)) {
if((x & j) == j)
count = add(count,1);
i = add(i,1);
j = mul(j,2);
}
return (count & 1) == 1;
}
unsigned int make_odd(unsigned int x) {
if(!has_odd(x))
x ^= 0x80000000;
return x;
}
weatherlog_t pack_log_entry(unsigned int year, unsigned int month, unsigned int day,
unsigned int zip, int high_temp, int low_temp,
unsigned int precip, unsigned int avg_wind_speed) {
weatherlog_t log_entry = 0;
log_entry ^= sub(year,2000);
log_entry <<= 4;
log_entry ^= month;
log_entry <<= 5;
log_entry ^= day;
log_entry <<= 16;
log_entry ^= zip;
log_entry <<= 8;
log_entry ^= high_temp;
log_entry <<= 8;
log_entry ^= low_temp;
log_entry <<= 10;
log_entry ^= precip;
log_entry <<= 7;
log_entry ^= avg_wind_speed;
return log_entry;
}
unsigned int get_year(weatherlog_t entry) {
return entry >> 58;
}
unsigned int get_month(weatherlog_t entry) {
return 0xf & (entry >> 54);
}
unsigned int get_day(weatherlog_t entry) {
return 0x1f & (entry >> 49);
}
unsigned int get_zip(weatherlog_t entry) {
return 0xffff & (entry >> 33);
}
unsigned int get_high(weatherlog_t entry){
return 0xff & (entry >> 25);
}
unsigned int get_low(weatherlog_t entry) {
return 0xff & (entry >> 17);
}
unsigned int get_precip(weatherlog_t entry) {
return 0x3ff & (entry >> 7);
}
unsigned int get_wind(weatherlog_t entry) {
return 0x7f & entry;
}
Sample Output:
Enter an integer: 1
Enter another integer: 2
One more integer, please: 3
Please enter a positive integer: 4
i + j = 3
i - j = 4294967295
i * j = 2
3 is non-negative
4 has an odd number of bits in its binary representation
The half-nybbles of 3 (in hex 0x3) are:3000000000000000
3 with reversed half-nybbles is c0000000
Enter a year: 2016
Enter a month as an integer (1-12): 10
Enter a day as an integer (1-31): 5
Enter a zip code as an integer (0-99999): 600028
Enter a temperature as an integer: 12
Enter another temperature as an integer: 34
Enter rainfall amount as an integer (mm): 33
Enter a as an integer (km/hr): 3
You entered: 12/10/16 for zip 10204: high 12 F, low 34 F, precip 33 mm, wind spe
ed 3 km/hr
Press any key to continue . . .

More Related Content

Similar to AnswerNote Entire skeleton of the code is provided. The below co.pdf

Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 

Similar to AnswerNote Entire skeleton of the code is provided. The below co.pdf (20)

B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Fatima Aliasgher Portfolio
Fatima Aliasgher PortfolioFatima Aliasgher Portfolio
Fatima Aliasgher Portfolio
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Progr3
Progr3Progr3
Progr3
 
cpract.docx
cpract.docxcpract.docx
cpract.docx
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
Write a function that takes as a parameter an integer (as a long valu.docx
 Write a function that takes as a parameter an integer (as a long valu.docx Write a function that takes as a parameter an integer (as a long valu.docx
Write a function that takes as a parameter an integer (as a long valu.docx
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
 

More from sharnapiyush773

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
sharnapiyush773
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
sharnapiyush773
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
sharnapiyush773
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
sharnapiyush773
 
public class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdfpublic class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdf
sharnapiyush773
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
sharnapiyush773
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
sharnapiyush773
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdf
sharnapiyush773
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
sharnapiyush773
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
sharnapiyush773
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
sharnapiyush773
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
sharnapiyush773
 

More from sharnapiyush773 (20)

“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf“According to new research in the Journal of Research in Personality.pdf
“According to new research in the Journal of Research in Personality.pdf
 
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdfTrueas each officer has fixed paroleelesratio = no of parollesn.pdf
Trueas each officer has fixed paroleelesratio = no of parollesn.pdf
 
to upperSolutionto upper.pdf
to upperSolutionto upper.pdfto upperSolutionto upper.pdf
to upperSolutionto upper.pdf
 
there are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdfthere are several theory on defining acid and base, Lewis acids and .pdf
there are several theory on defining acid and base, Lewis acids and .pdf
 
The Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdfThe Statement is False. As there are many applications of hyperbo;ic.pdf
The Statement is False. As there are many applications of hyperbo;ic.pdf
 
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdfThe Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
The Sarbanes-Oxley , 2002 contains following provisions which determ.pdf
 
The main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdfThe main motivation behind software reuse is to avoid wastage of tim.pdf
The main motivation behind software reuse is to avoid wastage of tim.pdf
 
The expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdfThe expression evaluation is compiler dependent, and may vary. A g.pdf
The expression evaluation is compiler dependent, and may vary. A g.pdf
 
public class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdfpublic class Storm {   Attributes    private String stormName;.pdf
public class Storm {   Attributes    private String stormName;.pdf
 
picture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdfpicture is missingSolutionpicture is missing.pdf
picture is missingSolutionpicture is missing.pdf
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
OSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdfOSI (Open Systems Interconnection) is reference model for how applic.pdf
OSI (Open Systems Interconnection) is reference model for how applic.pdf
 
Note Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdfNote Modified codecode#includeiostream #include stdio.h.pdf
Note Modified codecode#includeiostream #include stdio.h.pdf
 
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdfOligotrophic area Usually, an olidgotropic organism is a one that .pdf
Oligotrophic area Usually, an olidgotropic organism is a one that .pdf
 
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdfn = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
n = N 2^(rt)n = no of people at a given timeN = initial populat.pdf
 
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdfMaroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
Maroochy Shire Sewage Spill Case Study Student’s Name Institution Af.pdf
 
It lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdfIt lacks the origin of replication which is most important for the i.pdf
It lacks the origin of replication which is most important for the i.pdf
 
In developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdfIn developmental biology, an embryo is divided into two hemispheres.pdf
In developmental biology, an embryo is divided into two hemispheres.pdf
 
Bryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdfBryophytes- Development of primitive vasculature for water transport.pdf
Bryophytes- Development of primitive vasculature for water transport.pdf
 
givenSolutiongiven.pdf
givenSolutiongiven.pdfgivenSolutiongiven.pdf
givenSolutiongiven.pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 

AnswerNote Entire skeleton of the code is provided. The below co.pdf

  • 1. Answer: Note: Entire skeleton of the code is provided. The below code is implemented as per the declarations provided. Program code: #include #include #include typedef uint64_t weatherlog_t; unsigned int add(unsigned int, unsigned int); unsigned int sub(unsigned int, unsigned int); unsigned int mul(unsigned int, unsigned int); void print_half_nybbles(unsigned int); unsigned int reverse_half_nybbles(unsigned int); int has_odd(unsigned int); unsigned int make_odd(unsigned int); int is_negative(int); weatherlog_t pack_log_entry(unsigned int, unsigned int, unsigned int, unsigned int, int, int, unsigned int, unsigned int); unsigned int get_year(weatherlog_t entry); unsigned int get_month(weatherlog_t entry); unsigned int get_day(weatherlog_t entry); unsigned int get_zip(weatherlog_t entry); unsigned int get_high(weatherlog_t entry); unsigned int get_low(weatherlog_t entry); unsigned int get_precip(weatherlog_t entry); unsigned int get_wind(weatherlog_t entry); int main(int argc, char **argv) { unsigned int i, j; int x, y; unsigned int year, month, day, zip, high_temp, low_temp, precip, avg_wind_speed; weatherlog_t log_entry; printf("Enter an integer: ");
  • 2. scanf("%u", &i); printf("Enter another integer: "); scanf("%u", &j); printf("One more integer, please: "); scanf("%d", &x); printf("Please enter a positive integer: "); scanf("%d", &y); printf("i + j = %u ", add(i,j)); printf("i - j = %u ", sub(i,j)); printf("i * j = %u ", mul(i,j)); if (is_negative(x)) printf("%d is negative ", x); else printf("%d is non-negative ", x); if (has_odd(y)) { printf("%x has an odd number of bits in its binary representation ", y); } else { printf("%x has an even number of bits in its binary representation ", y); printf("but %x has an odd number of bits in its binary representation ", make_odd(y)); } printf("The half-nybbles of %d (in hex 0x%x) are:", x, x); print_half_nybbles(x); printf("%x with reversed half-nybbles is %x ", x, reverse_half_nybbles(x)); printf("Enter a year: "); scanf("%u", &year); printf("Enter a month as an integer (1-12): "); scanf("%u", &month); printf("Enter a day as an integer (1-31): "); scanf("%u", &day); printf("Enter a zip code as an integer (0-99999): "); scanf("%u", &zip); printf("Enter a temperature as an integer: "); scanf("%u", &high_temp); printf("Enter another temperature as an integer: ");
  • 3. scanf("%u", &low_temp); printf("Enter rainfall amount as an integer (mm): "); scanf("%u", &precip); printf("Enter a as an integer (km/hr): "); scanf("%u", &avg_wind_speed); log_entry=pack_log_entry(year, month, day, zip, high_temp, low_temp, precip, avg_wind_speed); printf("You entered: %u/%u/%u for zip %5d: high %d F, low %d F, precip %d mm, wind speed %d km/hr ", get_day(log_entry), get_month(log_entry), get_year(log_entry), get_zip(log_entry), get_high(log_entry), get_low(log_entry), get_precip(log_entry), get_wind(log_entry)); system("pause"); return 0; } unsigned int add(unsigned int i, unsigned int j) { unsigned int t, r; t = i ^ j; while((r = i & j) != 0) { i = t; j = r << 1; t = i ^ j; } return t; } unsigned int sub(unsigned int i, unsigned int j) { j = add(~j,1); return add(i,j); } unsigned int mul(unsigned int i, unsigned int j) { unsigned int k, product = 0; for(k = 0; k < j; k = add(k,1)) { product = add(product,i); } return product; }
  • 4. void print_half_nybbles(unsigned int x) { unsigned int i = 0, t = 0x3; while(t != 0) { printf("%u", (x & t) >> i); t <<= 2; i = add(i,2); } printf(" "); } unsigned int reverse_half_nybbles(unsigned int i) { unsigned r = 0, s = 0, t = 0x3, j = 0; while(j < mul(sizeof(i),8)) { r = (i >> j) & t; s<<=2; s = add(s,r); j = add(j,2); } return s; } int is_negative(int x) { return (x & 0x80000000) != 0; } int has_odd(unsigned int x) { unsigned int count = 0, i = 0, j = 1; while(i < mul(sizeof(x),8)) { if((x & j) == j) count = add(count,1); i = add(i,1); j = mul(j,2); } return (count & 1) == 1; } unsigned int make_odd(unsigned int x) { if(!has_odd(x)) x ^= 0x80000000; return x;
  • 5. } weatherlog_t pack_log_entry(unsigned int year, unsigned int month, unsigned int day, unsigned int zip, int high_temp, int low_temp, unsigned int precip, unsigned int avg_wind_speed) { weatherlog_t log_entry = 0; log_entry ^= sub(year,2000); log_entry <<= 4; log_entry ^= month; log_entry <<= 5; log_entry ^= day; log_entry <<= 16; log_entry ^= zip; log_entry <<= 8; log_entry ^= high_temp; log_entry <<= 8; log_entry ^= low_temp; log_entry <<= 10; log_entry ^= precip; log_entry <<= 7; log_entry ^= avg_wind_speed; return log_entry; } unsigned int get_year(weatherlog_t entry) { return entry >> 58; } unsigned int get_month(weatherlog_t entry) { return 0xf & (entry >> 54); } unsigned int get_day(weatherlog_t entry) { return 0x1f & (entry >> 49); } unsigned int get_zip(weatherlog_t entry) { return 0xffff & (entry >> 33); }
  • 6. unsigned int get_high(weatherlog_t entry){ return 0xff & (entry >> 25); } unsigned int get_low(weatherlog_t entry) { return 0xff & (entry >> 17); } unsigned int get_precip(weatherlog_t entry) { return 0x3ff & (entry >> 7); } unsigned int get_wind(weatherlog_t entry) { return 0x7f & entry; } Sample Output: Enter an integer: 1 Enter another integer: 2 One more integer, please: 3 Please enter a positive integer: 4 i + j = 3 i - j = 4294967295 i * j = 2 3 is non-negative 4 has an odd number of bits in its binary representation The half-nybbles of 3 (in hex 0x3) are:3000000000000000 3 with reversed half-nybbles is c0000000 Enter a year: 2016 Enter a month as an integer (1-12): 10 Enter a day as an integer (1-31): 5 Enter a zip code as an integer (0-99999): 600028 Enter a temperature as an integer: 12 Enter another temperature as an integer: 34 Enter rainfall amount as an integer (mm): 33 Enter a as an integer (km/hr): 3 You entered: 12/10/16 for zip 10204: high 12 F, low 34 F, precip 33 mm, wind spe ed 3 km/hr Press any key to continue . . .
  • 7. Solution Answer: Note: Entire skeleton of the code is provided. The below code is implemented as per the declarations provided. Program code: #include #include #include typedef uint64_t weatherlog_t; unsigned int add(unsigned int, unsigned int); unsigned int sub(unsigned int, unsigned int); unsigned int mul(unsigned int, unsigned int); void print_half_nybbles(unsigned int); unsigned int reverse_half_nybbles(unsigned int); int has_odd(unsigned int); unsigned int make_odd(unsigned int); int is_negative(int); weatherlog_t pack_log_entry(unsigned int, unsigned int, unsigned int, unsigned int, int, int, unsigned int, unsigned int); unsigned int get_year(weatherlog_t entry); unsigned int get_month(weatherlog_t entry); unsigned int get_day(weatherlog_t entry); unsigned int get_zip(weatherlog_t entry); unsigned int get_high(weatherlog_t entry); unsigned int get_low(weatherlog_t entry); unsigned int get_precip(weatherlog_t entry); unsigned int get_wind(weatherlog_t entry); int main(int argc, char **argv) { unsigned int i, j; int x, y; unsigned int year, month, day, zip, high_temp, low_temp, precip, avg_wind_speed; weatherlog_t log_entry;
  • 8. printf("Enter an integer: "); scanf("%u", &i); printf("Enter another integer: "); scanf("%u", &j); printf("One more integer, please: "); scanf("%d", &x); printf("Please enter a positive integer: "); scanf("%d", &y); printf("i + j = %u ", add(i,j)); printf("i - j = %u ", sub(i,j)); printf("i * j = %u ", mul(i,j)); if (is_negative(x)) printf("%d is negative ", x); else printf("%d is non-negative ", x); if (has_odd(y)) { printf("%x has an odd number of bits in its binary representation ", y); } else { printf("%x has an even number of bits in its binary representation ", y); printf("but %x has an odd number of bits in its binary representation ", make_odd(y)); } printf("The half-nybbles of %d (in hex 0x%x) are:", x, x); print_half_nybbles(x); printf("%x with reversed half-nybbles is %x ", x, reverse_half_nybbles(x)); printf("Enter a year: "); scanf("%u", &year); printf("Enter a month as an integer (1-12): "); scanf("%u", &month); printf("Enter a day as an integer (1-31): "); scanf("%u", &day); printf("Enter a zip code as an integer (0-99999): "); scanf("%u", &zip); printf("Enter a temperature as an integer: "); scanf("%u", &high_temp);
  • 9. printf("Enter another temperature as an integer: "); scanf("%u", &low_temp); printf("Enter rainfall amount as an integer (mm): "); scanf("%u", &precip); printf("Enter a as an integer (km/hr): "); scanf("%u", &avg_wind_speed); log_entry=pack_log_entry(year, month, day, zip, high_temp, low_temp, precip, avg_wind_speed); printf("You entered: %u/%u/%u for zip %5d: high %d F, low %d F, precip %d mm, wind speed %d km/hr ", get_day(log_entry), get_month(log_entry), get_year(log_entry), get_zip(log_entry), get_high(log_entry), get_low(log_entry), get_precip(log_entry), get_wind(log_entry)); system("pause"); return 0; } unsigned int add(unsigned int i, unsigned int j) { unsigned int t, r; t = i ^ j; while((r = i & j) != 0) { i = t; j = r << 1; t = i ^ j; } return t; } unsigned int sub(unsigned int i, unsigned int j) { j = add(~j,1); return add(i,j); } unsigned int mul(unsigned int i, unsigned int j) { unsigned int k, product = 0; for(k = 0; k < j; k = add(k,1)) { product = add(product,i); } return product;
  • 10. } void print_half_nybbles(unsigned int x) { unsigned int i = 0, t = 0x3; while(t != 0) { printf("%u", (x & t) >> i); t <<= 2; i = add(i,2); } printf(" "); } unsigned int reverse_half_nybbles(unsigned int i) { unsigned r = 0, s = 0, t = 0x3, j = 0; while(j < mul(sizeof(i),8)) { r = (i >> j) & t; s<<=2; s = add(s,r); j = add(j,2); } return s; } int is_negative(int x) { return (x & 0x80000000) != 0; } int has_odd(unsigned int x) { unsigned int count = 0, i = 0, j = 1; while(i < mul(sizeof(x),8)) { if((x & j) == j) count = add(count,1); i = add(i,1); j = mul(j,2); } return (count & 1) == 1; } unsigned int make_odd(unsigned int x) { if(!has_odd(x)) x ^= 0x80000000;
  • 11. return x; } weatherlog_t pack_log_entry(unsigned int year, unsigned int month, unsigned int day, unsigned int zip, int high_temp, int low_temp, unsigned int precip, unsigned int avg_wind_speed) { weatherlog_t log_entry = 0; log_entry ^= sub(year,2000); log_entry <<= 4; log_entry ^= month; log_entry <<= 5; log_entry ^= day; log_entry <<= 16; log_entry ^= zip; log_entry <<= 8; log_entry ^= high_temp; log_entry <<= 8; log_entry ^= low_temp; log_entry <<= 10; log_entry ^= precip; log_entry <<= 7; log_entry ^= avg_wind_speed; return log_entry; } unsigned int get_year(weatherlog_t entry) { return entry >> 58; } unsigned int get_month(weatherlog_t entry) { return 0xf & (entry >> 54); } unsigned int get_day(weatherlog_t entry) { return 0x1f & (entry >> 49); } unsigned int get_zip(weatherlog_t entry) { return 0xffff & (entry >> 33);
  • 12. } unsigned int get_high(weatherlog_t entry){ return 0xff & (entry >> 25); } unsigned int get_low(weatherlog_t entry) { return 0xff & (entry >> 17); } unsigned int get_precip(weatherlog_t entry) { return 0x3ff & (entry >> 7); } unsigned int get_wind(weatherlog_t entry) { return 0x7f & entry; } Sample Output: Enter an integer: 1 Enter another integer: 2 One more integer, please: 3 Please enter a positive integer: 4 i + j = 3 i - j = 4294967295 i * j = 2 3 is non-negative 4 has an odd number of bits in its binary representation The half-nybbles of 3 (in hex 0x3) are:3000000000000000 3 with reversed half-nybbles is c0000000 Enter a year: 2016 Enter a month as an integer (1-12): 10 Enter a day as an integer (1-31): 5 Enter a zip code as an integer (0-99999): 600028 Enter a temperature as an integer: 12 Enter another temperature as an integer: 34 Enter rainfall amount as an integer (mm): 33 Enter a as an integer (km/hr): 3 You entered: 12/10/16 for zip 10204: high 12 F, low 34 F, precip 33 mm, wind spe ed 3 km/hr Press any key to continue . . .