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

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

新人求指教 為什么編譯不通過

新人求指教 為什么編譯不通過

C++
ShadowKun 2016-05-07 18:21:46
#include<iostream>#include<cmath>#include<vector>#include<typeinfo>using namespace std;int f(int a, int b){? ? int r;? ? r = a % b;? ? while(r)? ? {? ? ? ? a = b;? ? ? ? b = r;? ? ? ? r = a % b;? ? }? ? return b;}class Fract{public:? ? Fract(int a, int b) : n(a), m(b)? ? {? ? ? ? int x = f(n, m);? ? ? ? n = n / x;? ? ? ? m = m / x;? ? ? ? //cout << n << m << endl;? ? }? ? void show()? ? {? ? ? ? if(n == 0)? ? ? ? ? ? cout << "0" << endl;? ? ? ? else if(m == 1)? ? ? ? ? ? cout << n << endl;? ? ? ? else if(n < 0 && m > 0 )? ? ? ? ? ? cout << "-" << -n << "/" << m << endl;? ? ? ? else if(n > 0 && m < 0)? ? ? ? ? ? cout << "-" << n << "/" << -m << endl;? ? ? ? else if(n < 0 && m < 0)? ? ? ? ? ? cout << -n << "/" << -m << endl;? ? ? ? else? ? ? ? ? ? cout << n << "/" << m << endl;? ? }? ? operator double()? ? {? ? ? ? return (double)n/m;? ? }? ? Fract operator + (Fract &a)? ? {? ? ? ? int c, d;? ? ? ? c = n * a.m + m * a.n;? ? ? ? d = m * a.m;? ? ? ? return Fract(c, d);? ? }? ? Fract& operator += (Fract a)? ? {? ? ? ? Fract t = *this + a;? ? ? ? return *this = t;? ? }private:? ? int n, m;};template <class T>class ?Array{public:? ? Array(int n):l_(n) {}? ? void input(int a)? ? {? ? ? ? s.clear();? ? ? ? int mi=l_>a?a:l_;? ? ? ? if(typeid(T)!=typeid(double))? ? ? ? ? ? for(int i=0; i<mi; i++)? ? ? ? ? ? {? ? ? ? ? ? ? ? int a,b;? ? ? ? ? ? ? ? cin>>a>>b;? ? ? ? ? ? ? ? Fract fra(a,b);? ? ? ? ? ? ? ? s.push_back(fra);? ? ? ? ? ? }? ? ? ? else if(typeid(T)==typeid(double))? ? ? ? ? ? for(int i=0; i<mi; i++)? ? ? ? ? ? {? ? ? ? ? ? ? ? double j;? ? ? ? ? ? ? ? cin>>j;? ? ? ? ? ? ? ? s.push_back(j);? ? ? ? ? ? }? ? }? ? T& operator[](int a)? ? {? ? ? ? return s[a];? ? }private:? ? vector<T> s;? ? int l_;};int main(){? ? int ?n;? ? cin >> n;? ? Array<double> db(1000);? ? db.input(n);? ? double dbsum(0.0);? ? for(int i = 0; i < n; i++)? ? ? ? dbsum += db[i];? ? cout << dbsum << endl;? ? cin >> n;? ? Array<Fract> fr(1000);? ? fr.input(n);? ? Fract frsum(0, 1);? ? for(int i = 0; i < n; i++)? ? ? ? frsum += fr[i];? ? frsum.show();}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1319 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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