百度知道_lsjf吧 关注:2贴子:12
  • 4回复贴,共1

我嘞个去 知道也会自动开贴吧啊!!!

只看楼主收藏回复



IP属地:湖南1楼2013-06-23 18:07回复
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    int a[30];
    double tot = 0 , b[30];
    int main()
    {
    a[0] = 1, a[1] = 2;
    for(int i = 2; i < 25; i++)
    a[i] = a[i-1] + a[i-2];
    for(int i = 1; i <= 20; i++)
    {
    b[i] = 1.0*a[i]/a[i-1];
    tot += b[i];
    }
    printf("%.5lf\n", tot);
    return 0;
    }


    IP属地:湖南2楼2016-06-23 14:44
    回复
      2025-05-28 12:45:26
      广告
      #include <iostream>
      #include <cstdio>
      #include <cstring>
      using namespace std;
      int gcd(int x, int y)
      {
      if(x < y) return gcd(y,x);
      if(y == 0) return x;
      return gcd(y, x % y);
      }
      class Fraction
      {
      private:
      int fz; //分子
      int fm; //分母
      public:
      Fraction(){}
      Fraction(const Fraction &p){
      fz = p.fz;
      fm = p.fm;
      }
      Fraction(int x, int y)
      {
      fz = x;
      fm = y;
      }
      void show()
      {
      cout<<fz<<'/'<<fm<<endl;
      }
      void operator += (Fraction &p)
      {
      Fraction t;
      t.fz = fz*p.fm + p.fz*fm;
      t.fm = fm*p.fm;
      fz = t.fz;
      fm = t.fm;
      int temp = gcd(fz, fm);
      fz /= temp;
      fm /= temp;
      }
      friend ostream &operator << (ostream &, Fraction &);
      };
      ostream & operator << (ostream &os, Fraction &p)
      {
      os<<p.fz<<'/'<<p.fm<<endl;
      return os;
      }
      int main()
      {
      Fraction a(3,4), b(6,9);
      a+=b;
      Fraction c(a);
      cout<<c;
      return 0;
      }


      IP属地:湖南3楼2016-06-23 14:45
      回复
        #include <iostream>
        #include <cstdio>
        #include <cstring>
        using namespace std;
        class Student {
        private:
        char name[10];
        char num[10];
        public:
        Student() {}
        Student(char a[], char b[])
        {
        strcpy(name, a);
        strcpy(num, b);
        }
        void show()
        {
        cout<<name<<endl;
        cout<<num<<endl;
        }
        };
        class SStack {
        private:
        Student * d;
        Student * top;
        int size, used;
        public:
        SStack() {
        size = 1;
        d = new Student[size];
        top = d;
        used = 0;
        }
        SStack(int s) {
        size = s;
        d = new Student[size];
        top = d;
        used = 0;
        }
        void full()
        {
        Student * nd;
        Student * t = d;
        Student * ntop;
        size = size * 2;
        nd = new Student[size];
        ntop = nd;
        for(int i = 0; i < used; i++)
        {
        *ntop = *t;
        ntop++;
        t++;
        }
        delete [] d;
        d = nd;
        top = ntop;
        }
        void Push(Student s1)
        {
        if(used >= size)
        full();
        *top = s1;
        top++;
        used++;
        }
        Student Pop()
        {
        if(used == 0)
        {
        cout<<"error:栈空"<<endl;
        }
        else {
        used--;
        top--;
        return *top;
        }
        }
        };
        int main()
        {
        char name[] = {'W', 'X', 'C', '\0'};
        char num[] = {'1', '3', '5', '\0'};
        Student s(name, num);
        SStack a;
        a.Pop();
        a.Push(s);
        a.Push(s);
        a.Push(s);
        a.Push(s);
        for(int i = 1; i < 6; i++)
        {
        s = a.Pop();
        }
        return 0;
        }


        IP属地:湖南4楼2016-06-23 14:46
        回复
          #include <iostream>
          #include <cstdio>
          #include <cstring>
          #define PI 3.1415926
          using namespace std;
          class Shape {
          public:
          Shape() {}
          virtual double show() = 0;
          double ShowTotalArea(Shape *s[],int n)
          {
          double temp = 0;
          for(int i = 0; i < n; i++)
          temp += s[i]->show();
          return temp;
          }
          };
          class Circle : public Shape {
          public:
          Circle(float Radius) {
          mRadius = Radius;
          }
          double show() {
          return PI*mRadius*mRadius;
          }
          private:
          float mRadius;
          };
          class Rectangle : public Shape {
          public:
          Rectangle(float Length, float Height) {
          mLength = Length;
          mHeight = Height;
          }
          double show() {
          return mLength*mHeight;
          }
          private:
          float mLength, mHeight;
          };
          int main()
          {
          Circle c(2.0);
          Rectangle r(2.0, 3.0);
          Shape *p[2] = {&c, &r};
          cout<<p[0]->show()<<endl;
          cout<<p[1]->show()<<endl;
          Shape *p1;
          cout<<p1->ShowTotalArea(p, 2)<<endl;
          return 0;
          }


          IP属地:湖南5楼2016-06-23 14:47
          回复