SSD06 Practical Quiz 1 个人解答
这个题目和Exercise02 没什么区别,在这里把我的解答给出来,就不再赘述了。Introduction
The purpose of this assignment is to becomemore familiar with bit-level representations and manipulations.As with the Data Lab, you'll do this by solving a small number ofprogramming "puzzles."
Getting Started
Download and unzip dlabp-handout.zip to adirectory in which you plan to do your work. This will cause thefollowingfiles to be unpacked into the directory:
bits.cThe data puzzles that you will solve. This is the file you will be modifying and handing in.dlabp.vcproj
ProjectfileREADMEHelpful information about the labbtest.c
btest.h
decl.c
test.c
getopt.c
bits.h
getopt.h
tailor.hThe test driver and its helper filesOpen the dlabp.vcproj workspace from VC++ and you areready to begin solving your puzzles. You can add this project to a pre-existing (or new) VC++.Net Solution
Your Task
The only file you will be modifying and turning in isbits.c. Looking at bits.c you'll notice a Cstructure called info into which you should insertyour name and login ID. Do this right away so you don't forget,as the driver will not run without it.
The bits.c file also contains a skeleton for eachof the 4 programming puzzles. As before, your assignment is tocomplete each function skeleton using only straightlinecode (i.e., no loops or conditionals) and a limited number of Carithmetic and logical operators. Specifically, you areonly allowed to use the following eight operators:
! ~ & ^ | + << >>A few of the functions further restrict this list. See thecomments in bits.c for detailed rules and a discussionof the desired coding style.
The enclosed dlabp.vcproj project will help youcompile your bits.c file, along with the other helperfunctions, and link them all together to form the executabledriver program btest.exe. The btest.exedriver program allows you to evaluate the functional correctnessof your code. Every time you modify one of the puzzles inbits.c, you can check its correctness by rebuildingand rerunning btest.exe.
Puzzles
The following table describes the 4 puzzles that you will besolving in bits.c. The ``Rating'' field gives thedifficulty rating (the number of points) for the puzzle, and the``Max ops'' field gives the maximum number of operators you areallowed to use to implement each function.
NameDescriptionRatingMax Opstmin()Returns the minimum two's complement integer14minusFive()Returns the integer value -514copyLSB(x)Sets all bits of result to least significant bit of x25getBit(x, n)Extract bit n from word x24See the bits.c file for examples of theresults returned by these functions.
Evaluation
Your score will be computed out of a maximum of 12 pointsbased on the following distribution:
6Correctness of code as reported by btest.exe
(no credit for a puzzle if your instructor determines that you have used an illegal operator).4Performance of code, based on number of operators used in each function (maximum of 1 point per puzzle).2Style points, based on your instructor's subjective evaluation of the quality of your solutions and your comments.The puzzles you must solve have been given a difficulty ratingbetween 1 and 2, such that their weighted sum totals to 6. Yourinstructor will evaluate your functions using the samebtest.exe driver that you are using. You will get fullcredit for a puzzle if it passes all of the tests performed bybtest.exe, half credit if it fails one test, and nocredit otherwise. You receive no credit if you use an illegaloperator for your solution, so pay close attention to the list ofallowed operators for each puzzle in bits.c.
As before, we've established a maximum number of operatorsthat you are allowed to use for each function. You will receiveone point for each function that satisfies the operatorlimit.
Finally, we've reserved two points for a subjective evaluationof the style of your solutions and your commenting. Yoursolutions should be as clean and straightforward as possible.Your comments should be informative, but they need not beextensive.
Advice
[*]Read the file README for information on running the btest.exe program.
[*]You'll find it helpful to work through the functions one at a time, testing each one as you go. You can use the -f flag to instruct btest.exe to test only a single function. For example, "btest.exe -f bitAnd".
[*]The "-g" flag is very handy for producing a concise summary of your correctness results. For example, "btest -g".
[*]btest.exe is a console application, so you'll need to run it from the Windows command line. On a Windows 2000 system, you can find this at "Start->Accessories->Command Prompt". If you try to run it using "Start->Run.." instead, you won't see any of the output.
Hand In Instructions
Before submitting your solution:
[*]Make sure you have included your identifying information in your file bits.c.
[*]Remove any extraneous print statements that you might have included for debugging.
页:
[1]