Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please finish the following project using C language with the following requirement. Here is the unfinished project code. Please finish this based on the code

Please finish the following project using C language with the following requirement.image text in transcribed

Here is the unfinished project code. Please finish this based on the code and requirment above. Do not just send back the code.

#include #include

/* weatherlog_t is a "weather sensor log type" which is really defined as a 64-bit unsigned integer. See below. */ 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)); return 0; }

unsigned int add(unsigned int i, unsigned int j) { /* can be done in a total of 7 lines, including one to declare an unsigned int, */ /* two for a while loop, and one for the return You're not required to do it in 7 lines though . */ return i + j; }

unsigned int sub(unsigned int i, unsigned int j) { /* Similar 7 lines, although there is a shorter way */ return i - j; }

unsigned int mul(unsigned int i, unsigned int j) { /* can be done in a total of 8 lines including one to declare unsigned ints */ /* two for a for loop, and one for the return */ return i * j; }

/* prints the half-nybbles (i.e. 2 bit values) of x, one half-nybble at a time */ void print_half_nybbles(unsigned int x) { }

/* returns the reverse of the half-nybbles of i */ unsigned int reverse_half_nybbles(unsigned int i) { return 0u; }

/* returns 1 if x

Do not use the operators. */ int is_negative(int x) { return 0; }

/* returns 1 if x's binary representation has an odd number of 1s or 0 otherwise */ int has_odd(unsigned int x) { return 0; }

/* If x's binary representation contains an odd number of 1s, x is returned. Otherwise, it returns a copy of x, but with its most significant bit modified so that there is an odd number of 1s. */ unsigned int make_odd(unsigned int x) { return 0; }

/* combines all of the arguments into a single weatherlog_t entry as described below */ 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) { return 0; }

unsigned int get_year(weatherlog_t entry) { return 0; }

unsigned int get_month(weatherlog_t entry) { return 0; }

unsigned int get_day(weatherlog_t entry) { return 0; }

unsigned int get_zip(weatherlog_t entry) { return 0; }

unsigned int get_high(weatherlog_t entry){ return 0; }

unsigned int get_low(weatherlog_t entry) { return 0; }

unsigned int get_precip(weatherlog_t entry) { return 0; }

unsigned int get_wind(weatherlog_t entry) { return 0; } Show transcribed image text

Objective This assignment will provide you with practice on bit operators Your Task is: dninisheain efor proet siled Weatherl.ogs Complete all of the unfinished functions and rewrite the ones started for you so that each computes the correct result using only the "bitwise" operators (&, I, *, >,along with!, ,,-, && and II You cannot use arithmetic (+, ++, *, %, /, ) operators, so that statements like -, --, for (i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions