讲解:C++SQL databaseC/C++、C/C++

Introduction用c++实现一个浮点float类,预计编程时间为一小时,需要实现浮点数的加,减,乘,除的操作,并且完成操作符重载,同时还要完成二进制操作符的操作RequirementFiles to submit: MyFloat.cpp, MyFloat.hTime it took Matthew to complete: 1 hour• All programs must compile without warnings when using the -Wall and -Werror options• Submit only the files requested◦ Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc• If submitting in a group on Grade Scope please make sure to mark your partner.◦ Only one of you has to submit there• Your program must match the output exactly to receive credit.◦ Make sure that all prompts and output match mine exactly.◦ Easiest way to do this is to copy and paste them• All input will be valid unless stated otherwise• Print all real numbers to two decimal places unless otherwise stated• The examples provided in the prompts do not represent all possible input you can receive.• All inputs in the examples in the prompt are underlined◦ You don’t have to make anything underlined it is just there to help you differentiate betweenwhat you are supposed to print and what is being given to your program• If you have questions please post them on Piazza1. For this assignment you will be implementing floating point add and subtract without using thehardware’s floating point or double precision add. This will give you a better understanding ofhow difficult they are to work with and a higher appreciation of the hardware for doing this foryou. You will be turning in a file called MyFloat.cpp and its associated header file, MyFloat.h,that implements your own floating point number. This object should support both + and -.1. You may not use floating point or double precision add in your solution. This means thatyou should not have the following in your program:1. float x,y;2. x + y;2. MyFloat should represent a float using three unsigned integers: sign, exponent, andmantissa.3. MyFloat must have the following private methods defined on it. These functions must beimplemented using inline assembly.1. void unpackFloat(float f);1. Given a float f this function should set sign, exponent, and mantissa to theappropriate values based on the value of f.2. float packFloat() const;1. This function should return the floating point representation of MyFloat3. You may declare and initialize variables to a constant in C as well as return a value butyou should do no other calculations.4. MyFloat must have the following public functions defined on it1. MyFloat operator+(const MyFloat rhs) const;1. This function should add this to rhs and return the result of the addition2. When adding the two numbers, the maximum amount of precision must bemaintained.1. Before doing the addition you should restore the leading 1. This means that themantissa will end up taking 24 bits.2. Since you are adding two 24 bit numbers together the result could take up to 25bits.3. Be careful when shifting. Since the numbers are 32 bits, the maximum amountyou can shift either left or right is 31. If you try to shift by more than this,nothing happens.3. After doing the addition the number should be returned to its normalized form.1. When normalizing the number we will truncate it down to the 23 mostsignificant bits.2. MyFloat operator-(const MyFloat rhs) const;1. This function return this – rhs.2. The maximum amount of precision must be maintained1. One thing to watch out for when subtracting (or adding numbers with differentsigns) is that you may need to borrow. A borrow would occur if the mostsignificant bit that is right shifted out is a 1.3. The number should be returned to normalized form. after adding.4. I highly suggest you call + after slightly modifying rhs3. bool perator==(const float rhs) const;1. Returns true if this represents the float on the right hand side.5. You have been provided with a main.cpp that will read in arguments from the command lineand then call your function. Your code must be callable from main.cpp1. Arg1 is a floating point number2. Arg2 is either + or -3. Arg3 is another floating point number6. You have also been provided with a header file for MyFloat and a partially completedMyFloat.cpp.1. Feel free to add additional methods but do not remove any.7. Finally you have been provided with a makefile to compile your submission. Yoursubmission must be compilable by the given makefile.8. Your CPU may use a different rounding scheme than what we are using your floating pointadd/subtract may not match float a + b. You shouldn’t try to match the computer but shouldinstead match my answers. If you do think I made a mistake though please let me know.Examples./fpArithmetic.out 10 + 7My Add: 17./fpArithmetic.out .5 + .5My Add: 1./fpArithmetic.out 1736217621 + 0.5My Add: 1.73622e+09./fpArithmetic.out -5 + 5My Add: 0./fpArithmetic.out 100 - 50My Subtraction: 50./fpArithmetic.out 10.3 - 5.1My Subtraction: 5.2& 转自:http://ass.3daixie.com/2018052610496745.html

你可能感兴趣的:(讲解:C++SQL databaseC/C++、C/C++)