Starting from:
$29

$26.10

Assignment 4 Cryptic calculator

CS 220, Fall 2017 Assignment 4 – (100 points) 
Instructions  • For this assignment, you are not allowed to use any library functions other than printf. • Ensure that your code runs on remote.cs.binghamton.edu. • Prototypes must be provided for all functions within the header file define.h. • Code must be appropriately commented. • Useful resources: 1. Commonlinuxcommands: http://www.informit.com/blogs/blog.aspx?uk=The10-Most-Important-Linux-Commands 2. http://c-faq.com/ 3. https://cdecl.org/
Questions 1. (40points)Writeafunctionint cryptic calculator(void *payload) Where: • If the first byte in payload is a character ’*’ representing the multiplication operation, you are to return the product of 3 short ints starting at bytes 3, 5 and 7. • If the first byte in the payload is a character ’/’ representing division, you are to return the quotient when you divide int starting at byte 5 by short int starting at byte 3. If short int starting at byte 3 is 0, you are to return 0xBAD.
1
• If the first byte is neither ’*’ or ’/’, you are to return 0xBAD. HINT:Castpayloadtoanappropriateappropriatestructure. Byte1isat&payload, byte 3 is at &payload + 2, byte 5 is at &payload + 4 and so on. 2. (40points)Writeafunction: void my memcpy(void *dst, void *src, unsigned int num bytes)thatcopiesnum bytesfrommemorypointed tobysrctomemorypointedtobydst. HINT:Loopnum bytestimesandcopy one char at a time from src to dst. 3. (20 points) Write a function: void swap strs(char *s1, char *s2) that swaps two character strings at s1 and s2. Assume both strings s1 and s2 to be of same length.

More products