Description
Problem 1 C is a strongly typed language. This means that all variables must be assigned a type explicitly. Other languages, such as JavaScript and Python, do not require you to assign a type to each variable. We will emulate a more flexible type system in C for this question. Consider the following structure definition: typedef struct FlexData { bool isInt; int value_int; double value_float; }FlexData; Create a function FlexData flexDivide(FlexData a, FlexData b) that will divide a/b according to the indicated data type (int or double). If either a or b is a double, treat the whole operation as a real division. Otherwise, treat it as an integer division. The function returns the result. Assume b is not zero. Note: You are to submit flexdata.c containing only your implemented function and the structure definition (you must delete the test cases portion which is the main function). However, you must keep the required included libraries. The sample main function for testing is below. 1. int main(void){ 2. FlexData n1 = {true, 17, 0}; 3. FlexData n2 = {true, 5, 0}; 4. FlexData d1 = {false, 0, 14.3}; 5. FlexData d2 = {false, 0, 2.4}; 6. 7. FlexData r1 = flexDivide(n1,n2); 8. FlexData r2 = flexDivide (d1,d2); 9. FlexData r3 = flexDivide (n1,d2); 10. assert(r1.isInt); 11. assert(!r2.isInt); 12. assert(!r3.isInt); 13. assert(3==r1.value_int); 14. printf(“%lf\n”, r2.value_double); 15. printf(“%lf\n”, r3.value_double); 16. 17. return 0; 18. } 19. The expected output: 5.958333 7.083333 Page 3 of 7 Problem 2 You are given a dataset of employees’ information, which includes their ids, ages, and salaries. The dataset is represented using an array of structures named Employee. Your task is to implement a C program that performs the following operations (some of them are already implemented for you in the provided company.c file): Input: Read data for n employees from the user (01 which takes in an array or rectangle structs of length n, computes the rectangle we get from the intersection of these rectangles in the array, and returns it. For instance, in the following example, for the three input rectangles (green, purple, orange), the intersection resulting from the intersection of the three rectangles is the blue rectangle with the red dotted boundary. If all the rectangles do not intersect (i.e. an empty intersection) then return rectangle with the values {{0,0},0,0}. Otherwise return the result (the intersection) as of type rectangle. Complete and Submit the provided rec.c file containing only your implemented function (that is, you must delete the test cases portion/the main function). However, you must keep the required included libraries. Page 6 of 7 Sample Test program (You need to add more test cases) 1. #include 2. 3. int main(){ 4. 5. rectangle result; 6. rectangle r = {{2,6},3,4}; 7. rectangle s = {{0,7},7,1}; 8. rectangle t = {{3,5},1,6}; 9. rectangle u = {{5,6},3,4}; 10. 11. // Test 1 12. rectangle rects1[2] = {r, s}; 13. result = intersection(rects1, 2); 14. assert(result.bottomLeft.x == 2); 15. assert(result.bottomLeft.y == 7); 16. assert(result.width == 3); 17. assert(result.height == 1); 18. 19. // Test 2 20. rectangle rects2[3] = {r, s, t}; 21. result = intersection(rects2, 3); 22. assert(result.bottomLeft.x == 3); 23. assert(result.bottomLeft.y == 7); 24. assert(result.width == 1); 25. assert(result.height == 1); 26. 27. // Test 3 28. rectangle rects3[4] = {r, s, t, u}; 29. result = intersection(rects3, 4); 30. assert(result.bottomLeft.x == 0); 31. assert(result.bottomLeft.y == 0); 32. assert(result.width == 0); 33. assert(result.height == 0); 34. 35. return 0; 36. } Page 7 of 7 Problem 4 Complete implementing the Sequence ADT in sequence.c. Read carefully through the global constant and function declarations in sequence.h to get a better understanding of what each function should do and how it should behave. You are also provided with a sample program for testing called test_sequence.c Make sure you add more tests to test your implementations. Note: You are to submit sequence.zip containing only sequence.h and sequence.c If you implement the functions correctly, the test_sequence.c file must print the following: [1] [empty] [1] [1,1] [empty] [1] [1,1] [2,1,1] [3,2,1,1] [4,3,2,1,1] [4,3,2,5,1,1] [4,3,2,5,1,1,4,3,2,5,1,1] [4,3,2,5,1]


