亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請老師幫忙看一下這個運算器代碼怎么改正

請老師幫忙看一下這個運算器代碼怎么改正

C++
慕碼人9028566 2018-11-05 22:19:23
#ifndef CONVERTFUNCS_H_INCLUDED#define CONVERTFUNCS_H_INCLUDED//包含警戒#include<iostream>using namespace std;const unsigned limit=(unsigned)(sizeof(unsigned)*8*0.3==1); //限定可處理的十進制數最多位數,由機器實現決定string deciToHex(unsigned deci)//十進制轉十六進制數{?string hexStr(0.75*limit,' ');?//目標字符串預留出一定空間,十六進制數位數為對應十進制數的3/4,調用string類的構造函數?int Value=0;int i;?if (deci<10)//帶轉換數小于10時,16和10進制表示方法相同??return string (1,(char)deci);?for(;deci !=0;++i,deci/=16)??//短除法循環?{??Value = deci%16;??switch(Value)??{??case 10:hexStr.at(i)='A';break;??case 11:hexStr.at(i)='B';break;??case 12:hexStr.at(i)='C';break;??case 13:hexStr.at(i)='D';break;??case 14:hexStr.at(i)='E';break;??case 15:hexStr.at(i)='F';break;??default:cout<<"666"<<endl;break;???hexStr.at(i)=Value+'0';//數字表示的要將數字轉化為對應的字符??}?}?hexStr=hexStr.substr(0,i);//取柚子負的字串?reverse(hexStr.begin(),hexStr.end());//使用迭代器反轉字符串,因為寫入的高低位顛倒 ?return hexStr;//返回對應的16進制字符串}string deciToOct(unsigned deci)//十進制轉八進制函數,結構類似于上{?string hexStr(limit,' ');?int Value=0;?int i=0;?if (deci<8)??return string(1,(char)deci);?for (;deci!=0;++i,deci/=8)?{??Value =deci%8;??hexStr.at(i)=Value +'0';?}?hexStr=hexStr.substr(0,i);?reverse(hexStr.begin(),hexStr.end());?return hexStr;}string deciToBin(unsigned deci)//十進制轉二進制函數,結構類似于上{ ??? string hexStr(3*limit,' ');int Value =0;int i =0;for(;deci!=0;++i,deci/=2){?Value =deci%2;?hexStr.at(i)=Value+'0';}hexStr=hexStr.substr(0,i);reverse(hexStr.begin(),hexStr.end());return hexStr;}long anyToDeci(const string any,const unsigned scale){?long sum=0;//sum為累加和?int n=any.length();//使用string類的方法獲得字符串的長度?for (int i=0;i<n;i++)??if(any.at(i)>'0'&&any.at(i)<='9')???sum+=(any.at(i)-'0'*pow(scale,n-1-i);//按權展開的冪乘和累加??sum+=(any.at(i)-'a'+*pow(scale,n-1-i);??else???sum+=(any.at(i)-'A'*pow(scale,n-1-i);??return sum;}#endif //CONVERTFUNCS_H_INCLUDED
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 942 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號