六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 38|回复: 0

SSD06 Practical Quiz 1 个人解答

[复制链接]

升级  1.6%

154

主题

154

主题

154

主题

进士

Rank: 4

积分
508
 楼主| 发表于 2013-1-27 04:44:18 | 显示全部楼层 |阅读模式
这个题目和Exercise02 没什么区别,在这里把我的解答给出来,就不再赘述了。
Introduction

The purpose of this assignment is to become  more familiar with bit-level representations and manipulations.  As with the Data Lab, you'll do this by solving a small number of  programming "puzzles."  
Getting Started

Download and unzip dlabp-handout.zip to a  directory in which you plan to do your work. This will cause thefollowing  files 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
      
Project  file
READMEHelpful information about the lab
btest.c
      btest.h
      decl.c
      test.c
      getopt.c
      bits.h
      getopt.h
      tailor.h
The test driver and its helper files
Open the dlabp.vcproj workspace from VC++ and you are  ready 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 is  bits.c. Looking at bits.c you'll notice a C  structure called info into which you should insert  your 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 each  of the 4 programming puzzles. As before, your assignment is to  complete each function skeleton using only straightline  code (i.e., no loops or conditionals) and a limited number of C  arithmetic and logical operators. Specifically, you are  only 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 you  compile your bits.c file, along with the other helper  functions, and link them all together to form the executable  driver program btest.exe. The btest.exe  driver program allows you to evaluate the functional correctness  of your code. Every time you modify one of the puzzles in  bits.c, you can check its correctness by rebuilding  and rerunning btest.exe.
Puzzles

The following table describes the 4 puzzles that you will be  solving in bits.c. The ``Rating'' field gives the  difficulty rating (the number of points) for the puzzle, and the  ``Max ops'' field gives the maximum number of operators you are  allowed to use to implement each function.
NameDescriptionRatingMax Ops
tmin()Returns the minimum two's complement integer14
minusFive()Returns the integer value -514
copyLSB(x)Sets all bits of result to least significant bit of      x25
getBit(x, n)Extract bit n from word x24
See the bits.c file for examples of the  results returned by these functions.  
Evaluation

Your score will be computed out of a maximum of 12 points  based 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 rating  between 1 and 2, such that their weighted sum totals to 6. Your  instructor will evaluate your functions using the same  btest.exe driver that you are using. You will get full  credit for a puzzle if it passes all of the tests performed by  btest.exe, half credit if it fails one test, and no  credit otherwise. You receive no credit if you use an illegal  operator for your solution, so pay close attention to the list of  allowed operators for each puzzle in bits.c.
As before, we've established a maximum number of operators  that you are allowed to use for each function. You will receive  one point for each function that satisfies the operator  limit.
Finally, we've reserved two points for a subjective evaluation  of the style of your solutions and your commenting. Your  solutions should be as clean and straightforward as possible.  Your comments should be informative, but they need not be  extensive.
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.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表