北邮2304吧 关注:17贴子:832
  • 21回复贴,共1

程序课第七章

只看楼主收藏回复

新鲜福利出炉


IP属地:北京1楼2015-06-01 19:17回复


    IP属地:广东来自iPhone客户端3楼2015-06-04 09:16
    收起回复
      度娘不要抽我楼!


      IP属地:北京6楼2015-06-04 11:31
      回复
        编程题
        1.
        #include<iostream>
        using namespace std;
        class tell
        {
        private:
        int positive;
        int negative;
        public:
        tell()
        {
        positive=0;
        negative=0;
        };
        voidtellnum(int k);
        voiddisplay();
        };
        void tell::tellnum(int k)
        {
        if(k>0) positive++;
        if(k<0) negative++;
        return;
        }
        void tell::display()
        {
        cout<<"positive:"<<positive<<endl;
        cout<<"negative:"<<negative<<endl;
        }
        int main()
        {
        intn;
        inti;
        inttemp;
        telltest;
        cin>>n;
        for(i=1;i<=n;i++)
        {
        cin>>temp;
        test.tellnum(temp);
        }
        test.display();
        return;
        }
        2.
        #include<iostream>
        using namespace std;
        class test
        {
        private:
        int colorcast;
        int fridge;
        int washer;
        int total;
        public:
        void count();
        void init(int a,int b,int c);
        void out();
        };
        void test::count()
        {
        total=4200*colorcast+2800*fridge+1500*washer;
        return;
        }
        void test::init(int a,int b,int c)
        {
        colorcast=a;
        fridge=b;
        washer=c;
        return;
        }
        void test::out()
        {
        cout<<total;
        return;
        }
        int main()
        {
        intaa,bb,cc;
        testtarget;
        cin>>aa>>bb>>cc;
        target.init(aa,bb,cc);
        target.count();
        target.out();
        return0;
        }
        3.
        #include<iostream>
        #include<cstring>
        using namespace std;
        class car
        {
        private:
        char type[20];
        char color[20];
        int door;
        int seat;
        double dis;
        public:
        void chge_parameters(int k);
        void disp_parameters();
        car()
        {
        strcpy(type,"无型号");
        strcpy(color,"无颜色");
        door=0;
        seat=0;
        dis=0;
        };
        };
        void car::chge_parameters(int k)
        {
        if(k==1)
        cin>>type;else
        if(k==2)
        cin>>color;else
        if(k==3)
        cin>>door;else
        if(k==4)
        cin>>seat;else
        if(k==5)
        cin>>dis;else
        cout<<"whatdo you wanna do?"<<endl;
        return;
        }
        void car::disp_parameters()
        {
        cout<<"车的型号:"<<type<<endl;
        cout<<"车的颜色:"<<color<<endl;
        cout<<door<<"门"<<seat<<"座"<<" 轴距为: "<<dis<<endl;
        return;
        }
        int main()
        {
        carthinkwee;
        thinkwee.disp_parameters();
        inti;
        for(i=1;i<=5;i++)
        thinkwee.chge_parameters(i);
        thinkwee.disp_parameters();
        return0;
        }
        4.
        #include<iostream>
        using namespace std;
        class stu
        {
        private:
        charname[20];
        intnum;
        charsex[5];
        public:
        intage;
        voidinit()
        {
        cin>>num>>name>>sex>>age;
        return;
        };
        voidout()
        {
        cout<<num<<''<<name<<' '<<sex<<' '<<age<<endl;
        return;
        };
        };
        int main()
        {
        stua[5],t;
        inti,j;
        for(i=0;i<5;i++)
        a[i].init();
        for (i=0;i<5;i++)
        for (j=i;j<5;j++)
        if (a[i].age<a[j].age)
        {
        t=a[i];
        a[i]=a[j];
        a[j]=t;
        }
        for (i=0;i<5;i++)
        a[i].out();
        return 0;
        }
        5.
        #include<iostream>
        using namespace std;
        class atm
        {
        private:
        int money;
        public:
        voidsave(int k);
        voidwithdraw(int k);
        voidcheck();
        atm()
        {
        money=0;
        };
        };
        void atm::save(int k)
        {
        money+=k;
        return;
        }
        void atm::withdraw(int k)
        {
        money-=k;
        return;
        }
        void atm::check()
        {
        cout<<"余额为:"<<money<<"元"<<endl;
        return;
        }
        int main()
        {
        atmyours;
        cout<<"输入1 存款\n输入2 取款\n输入3 查询余额\n输入0 退出"<<endl;
        intorder,t;
        cin>>order;
        while (order!=0)
        {
        if(order==1)
        {
        cout<<"输入金额"<<endl;
        cin>>t;
        yours.save(t);
        }
        if(order==2)
        {
        cout<<"输入金额"<<endl;
        cin>>t;
        yours.withdraw(t);
        }
        if(order==3)
        {
        yours.check();
        }
        cin>>order;
        };
        return0;
        }


        IP属地:北京9楼2015-06-04 11:35
        回复
          1.
          #include<iostream>
          using namespace std;
          class tell
          {
          private:
          int positive;
          int negative;
          public:
          tell()
          {
          positive=0;
          negative=0;
          };
          voidtellnum(int k);
          voiddisplay();
          };
          void tell::tellnum(int k)
          {
          if(k>0) positive++;
          if(k<0) negative++;
          return;
          }
          void tell::display()
          {
          cout<<"positive:"<<positive<<endl;
          cout<<"negative:"<<negative<<endl;
          }
          int main()
          {
          intn;
          inti;
          inttemp;
          telltest;
          cin>>n;
          for(i=1;i<=n;i++)
          {
          cin>>temp;
          test.tellnum(temp);
          }
          test.display();
          return;
          }
          2.
          #include<iostream>
          using namespace std;
          class test
          {
          private:
          int colorcast;
          int fridge;
          int washer;
          int total;
          public:
          void count();
          void init(int a,int b,int c);
          void out();
          };
          void test::count()
          {
          total=4200*colorcast+2800*fridge+1500*washer;
          return;
          }
          void test::init(int a,int b,int c)
          {
          colorcast=a;
          fridge=b;
          washer=c;
          return;
          }
          void test::out()
          {
          cout<<total;
          return;
          }
          int main()
          {
          intaa,bb,cc;
          testtarget;
          cin>>aa>>bb>>cc;
          target.init(aa,bb,cc);
          target.count();
          target.out();
          return0;
          }


          IP属地:北京10楼2015-06-04 11:37
          回复
            3.
            #include<iostream>
            #include<cstring>
            using namespace std;
            class car
            {
            private:
            char type[20];
            char color[20];
            int door;
            int seat;
            double dis;
            public:
            void chge_parameters(int k);
            void disp_parameters();
            car()
            {
            strcpy(type,"无型号");
            strcpy(color,"无颜色");
            door=0;
            seat=0;
            dis=0;
            };
            };
            void car::chge_parameters(int k)
            {
            if(k==1)
            cin>>type;else
            if(k==2)
            cin>>color;else
            if(k==3)
            cin>>door;else
            if(k==4)
            cin>>seat;else
            if(k==5)
            cin>>dis;else
            cout<<"whatdo you wanna do?"<<endl;
            return;
            }
            void car::disp_parameters()
            {
            cout<<"车的型号:"<<type<<endl;
            cout<<"车的颜色:"<<color<<endl;
            cout<<door<<"门"<<seat<<"座"<<" 轴距为: "<<dis<<endl;
            return;
            }
            int main()
            {
            carthinkwee;
            thinkwee.disp_parameters();
            inti;
            for(i=1;i<=5;i++)
            thinkwee.chge_parameters(i);
            thinkwee.disp_parameters();
            return0;
            }
            4.
            #include<iostream>
            using namespace std;
            class stu
            {
            private:
            charname[20];
            intnum;
            charsex[5];
            public:
            intage;
            voidinit()
            {
            cin>>num>>name>>sex>>age;
            return;
            };
            voidout()
            {
            cout<<num<<''<<name<<' '<<sex<<' '<<age<<endl;
            return;
            };
            };
            int main()
            {
            stua[5],t;
            inti,j;
            for(i=0;i<5;i++)
            a[i].init();
            for (i=0;i<5;i++)
            for (j=i;j<5;j++)
            if (a[i].age<a[j].age)
            {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
            }
            for (i=0;i<5;i++)
            a[i].out();
            return 0;
            }
            5.
            #include<iostream>
            using namespace std;
            class atm
            {
            private:
            int money;
            public:
            voidsave(int k);
            voidwithdraw(int k);
            voidcheck();
            atm()
            {
            money=0;
            };
            };
            void atm::save(int k)
            {
            money+=k;
            return;
            }
            void atm::withdraw(int k)
            {
            money-=k;
            return;
            }
            void atm::check()
            {
            cout<<"余额为:"<<money<<"元"<<endl;
            return;
            }
            int main()
            {
            atmyours;
            cout<<"输入1 存款\n输入2 取款\n输入3 查询余额\n输入0 退出"<<endl;
            intorder,t;
            cin>>order;
            while (order!=0)
            {
            if(order==1)
            {
            cout<<"输入金额"<<endl;
            cin>>t;
            yours.save(t);
            }
            if(order==2)
            {
            cout<<"输入金额"<<endl;
            cin>>t;
            yours.withdraw(t);
            }
            if(order==3)
            {
            yours.check();
            }
            cin>>order;
            };
            return0;
            }


            IP属地:北京11楼2015-06-04 11:37
            回复
              斯过意


              来自Android客户端14楼2015-12-05 09:32
              回复