Introduction用c++實(shí)現(xiàn)一個(gè)浮點(diǎn)float類,預(yù)計(jì)編程時(shí)間為一小時(shí),需要實(shí)現(xiàn)浮點(diǎn)數(shù)的加,減,乘,除的操作,并且完成操作符重載,同時(shí)還要完成二進(jìn)制操作符的操作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& 轉(zhuǎn)自:http://ass.3daixie.com/2018052610496745.html
講解:C++SQL databaseC/C++、C/C++
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- By clicking to agree to this Schedule 2, which is hereby ...
- pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
- 有人問(wèn)我一個(gè)問(wèn)題,老師,我看不到孩子的優(yōu)點(diǎn)怎么辦? 我問(wèn)她,“你能看到自己的優(yōu)點(diǎn)嗎?請(qǐng)說(shuō)出...