This week, the goal is to learn some about the limits of the different flavors of integers in C, as well as getting more experience with writing and debugging code.
I've started out the project this week, just to get things moving. Create a lab02 directory, and download limits.c and the Makefile I've written to start things off. If you run the make command once you have downloaded, it will compile and test the limits.c file I have provided. The program prints out the largest and smallest values that C allows for signed and unsigned "char" variables.
Take a look at limits.c to get a feel for how it works. Notice that there are two functions - minVal and maxVal - which both take two arguments - a character to represent the type of integer, and an integer to indicate if we are interested in the signed or unsigned version of that type. These functions then determine the minimum or maximum value by defining a variable of that type, and either adding to or subtracting that variable as long as the result makes sense. As soon as the result no longer makes sense, we return the value before the anomaly occurred.
Your job is to extend limits.c so that it handles not only a 'c' for char variables, but also 's' for short, and 'i' for int variables. You will need to copy the printf statements in the main function, modifying the string that is printed as well as the arguments passed into the minVal and maxVal functions. You will also need to add to the minVal and maxVal functions themselves to accommodate the new parameter values. Feel free to use the same strategy for short and int variables that I used for char variables.
Notice that if you used the same strategy, calculating limits for char and short goes pretty quickly, but it takes a while to count up to the highest int value (or down to the lowest). I wanted to ask you to do the same thing for long integers, but that takes orders of magnitude longer than ints, and we just don't have that much lab time.
I will occasionally ask extra credit questions in the labs. These questions often more difficult, and I don't expect everyone to have the time or desire to solve these questions; but I want to keep things challenging for the better students. My policy is that extra credit points can only be used to offset deductions on the current assignment. For instance, if you finish lab02, but have a compiler warning you can't figure out, you would normally get a two point deduction. If you got everything else right, but didn't do the extra credit, you would get 8/10 points on lab02. If you do the extra credit, and the extra credit is worth 4 points, then we will apply the extra credit points to raise your grade to a 10, but not higher than 10.
Today's extra credit is to extend the minVal and maxVal functions to work with long integers, but still run in a reasonable time. Therefore, you may not use the strategy of counting up or counting down by 1 to find the minimum or maximum long integer value. You must figure out some other strategy to solve the problem. If you can figure this out, and add the printf statements to print your results for both signed and unsigned long integers, you can earn up to 4 extra credit points to offset any other deductions on this lab.
Go to MyCourses using your web browser, and open the Spring 2018 - Comp Sys II:Arch &Prob (CS-220-A 0) or Spring 2018 - Comp Sys II:Arch &Prob (CS-220-B 1)course. Click on the "Content" hyperlink in the left column. There is a "Lab Submissions" folder on the content page. Click on the "Lab Submissions" hyperlink, and you will see "Lab 02 Submission". Click on that hyperlink, and use the Browse My Computer button to upload your modified "limits.c".
If you make a mistake submitting your lab, you may resubmit as often as you would like to. The TA's will only grade the last submission you make.
Each lab submission is worth 10 points. Deductions will occur for the following reasons: