• <video id="abmqw"><input id="abmqw"></input></video>
  • <strong id="abmqw"><noscript id="abmqw"></noscript></strong>
  • <i id="abmqw"><sub id="abmqw"></sub></i>
      <video id="abmqw"></video>
      <output id="abmqw"></output>

    1. <video id="abmqw"><ins id="abmqw"><table id="abmqw"></table></ins></video>

      <wbr id="abmqw"><input id="abmqw"></input></wbr>
    2. <thead id="abmqw"><span id="abmqw"></span></thead>
    3. 北京理工大學 - 話題

      2000~2008上機復試試題答案+說明(轉)
      查看(2185) 回復(0)
      huitailang
      • 積分:451
      • 注冊于:
      發表于
      樓主
      2000年
      1.輸入任意4個字符(如:abcd),并按反序輸出(如:dcba)
      #include&lt;iostream.h&gt;

      void main()
      {
              char s[5],t[5];
              int i;

              cout&lt;&lt;"請輸入四個字符:";
              cin&gt;&gt;s;
              for(i=0;i&lt;4;i++)
                      t=s[3-i];
              t[4]='\0';
              cout&lt;&lt;"反序后結果為:"&lt;&lt;t&lt;&lt;endl;
      }

      2.設a、b、c均是 0 到 9 之間的數字,abc、bcc是兩個三位數,且有:abc+bcc=532。求滿足條件的所有a、b、c的值。
      說明:本題結果唯一。
      #include&lt;iostream.h&gt;

      void main()
      {
              int a,b,c;
              for(a=1;a&lt;10;a++)
                      for(b=1;b&lt;10;b++)
                              for(c=0;c&lt;10;c++)
                                      if((a*100+b*10+c+b*100+c*10+c)==532)
                                              cout&lt;&lt;"滿足條件的a,b,c為:"&lt;&lt;a&lt;&lt;","&lt;&lt;b&lt;&lt;","&lt;&lt;c&lt;&lt;endl;
      //        cout&lt;&lt;"滿足條件的a,b,c為:3,2,1"&lt;&lt;endl;
      }

      3.一個數如果恰好等于它的各因子(該數本身除外)子和,如:6=3+2+1,則稱其為“完數”;若因子之和大于該數,則稱其為“盈數”。求出2到60之間所有“完數”和“盈數”,并以如下形式輸出: E: e1 e2 e3 ......(ei為完數) G: g1 g2 g3 ......(gi為盈數)
      #include&lt;iostream.h&gt;

      void save(int s[],int x,int flag);
      int fun(int x);

      void main()
      {
              int E[60],G[60];
              int flag,i;

              for(i=6;i&lt;=60;i++)
              {
                      flag=fun(i);
                      if(flag==0)
                              save(E,i,0);
                      else if(flag==1)
                                      save(G,i,1);
              }
              cout&lt;&lt;"E:";
              for(i=0;E!=0;i++)
                      cout&lt;&lt;E&lt;&lt;" ";
              cout&lt;&lt;endl&lt;&lt;"G:";
              for(i=0;G!=0;i++)
                      cout&lt;&lt;G&lt;&lt;" ";
              cout&lt;&lt;endl;
      }

      void save(int s[],int x,int flag)
      {
              static i=0,j=0;

              if(flag==0)
              {
                      s=x;
                      s[i+1]=0;
                      i++;
              }
              else
              {
                      s[j]=x;
                      s[j+1]=0;
                      j++;
              }
      }

      int fun(int x)
      {
              int i,sum=0;

              for(i=1;i&lt;=x/2;i++)
                      if(x%i==0)
                              sum+=i;
              if(sum==x)
                      return 0;
              else if(sum&gt;x)
                      return 1;
              else
                      return -1;
      }
              
      4.從鍵盤輸入4個學生的數據(包括姓名、年齡和成績),并存放在文件sf1上。從該文件讀出這些數據,按成績從高到底排序,并輸出其中成績次高者的所有數據。

      2001年A
      1、編寫程序,計算下列分段函數y=f(x)的值。 y= -x+2.5 0&lt;= x &lt;2 y=2-1.5(x-3)(x-3) 2&lt;= x &lt;4 y=x/2-1.5 4&lt;= x &lt;6
      #include&lt;iostream.h&gt;

      float fun(float x)
      {
              float y;
              if(x&gt;=0&&x&lt;2)
                      y=2.5-x;
              else if(x&gt;=2&&x&lt;4)
                      y=2-1.5*(x-3)*(x-3);
              else if(x&gt;=4&&x&lt;6)
                      y=x/2-1.5;
              return y;
      }

      void main()
      {
              float x;

              cout&lt;&lt;"請輸入x的值:";
              cin&gt;&gt;x;
              while(x&lt;0||x&gt;6)
              {
                      cout&lt;&lt;"非法,請重新輸入:";
                      cin&gt;&gt;x;
              }
              cout&lt;&lt;"結果為:"&lt;&lt;fun(x)&lt;&lt;endl;
      }

      2、編寫程序,讀入一個整數 N。若 N 為非負數,則計算 N 到 2N 之間的整數和;若 N 為一個負數,則求 2N 到 N 之間的整數和。
      說明:用了下公式
      #include&lt;iostream.h&gt;
      #include&lt;math.h&gt;

      void main()
      {
              int N;

              cout&lt;&lt;"請輸入一個整數:";
              cin&gt;&gt;N;
              cout&lt;&lt;N&lt;&lt;"到"&lt;&lt;2*N&lt;&lt;"之間的整數和為:"&lt;&lt;(abs(N)+1)*1.5*N&lt;&lt;endl;
      }

      3、設N是一個四位數,它的 9 倍恰好是其反序數(例如:1234的反序數是4321),求N的值。
      說明:本題結果唯一

      4、N個人圍成一圈順序編號,從1號開始按1、2、3順序報數,報3者退出圈外,其余的人再從1、2、3開始報數,報3的人再退出圈外,依次類推。請按退出順序輸出每個退出人的原序號。要求使用環行鏈表編程。
      說明:約瑟夫環
      #include&lt;iostream.h&gt;
      #include&lt;malloc.h&gt;

      typedef struct node
      {
              int num;
              struct node *next;
      }LNode;

      void main()
      {
              int N,i;
              LNode *head,*p,*q;

              cout&lt;&lt;"請輸入人數:";
              cin&gt;&gt;N;
              p=(LNode*)(malloc(sizeof(LNode)));
              p-&gt;num=1;
              head=p;
              for(i=1;i&lt;N;i++)
              {
                      p-&gt;next=(LNode*)(malloc(sizeof(LNode)));
                      p=p-&gt;next;
                      p-&gt;num=i+1;
              }
              p-&gt;next=head;
              p=head;

              cout&lt;&lt;"出列順序為:";
              while(p-&gt;next!=p)        
              {
                      q=p-&gt;next;
                      p=q-&gt;next;
                      q-&gt;next=p-&gt;next;
                      cout&lt;&lt;p-&gt;num&lt;&lt;" ";
                      delete p;
                      p=q-&gt;next;
              }
              cout&lt;&lt;p-&gt;num&lt;&lt;endl;
              delete p;
      }


      2001年B
      1、請輸入高度h,輸入一個高為h,上底邊長為h的等腰梯形(例如h=4,圖形如下)。
      ****
      ******
      ********
      **********
      #include&lt;iostream.h&gt;

      void main()
      {
              int i,j,h;

              cout&lt;&lt;"請輸入h:";
              cin&gt;&gt;h;
              for(i=0;i&lt;h;i++)
              {
                      for(j=0;j&lt;h+i;j++)
                              cout&lt;&lt;"*";
                      cout&lt;&lt;endl;
              }
      }

      2、請編寫一個程序,從鍵盤上輸入n(n的范圍是1~20),求n的階乘。
      #include&lt;iostream.h&gt;

      int fun(int n);

      void main()
      {
              int n;

              cout&lt;&lt;"請輸入n:";
              cin&gt;&gt;n;
              while(n&gt;20||n&lt;1)
              {
                      cout&lt;&lt;"非法,請重新輸入:";
                      cin&gt;&gt;n;
              }
              cout&lt;&lt;"n的階乘為:"&lt;&lt;fun(n)&lt;&lt;endl;
      }

      int fun(int n)
      {
              int i,result=1;

              for(i=1;i&lt;=n;i++)
                      result*=i;
              return result;
      }

      3、從鍵盤上任意輸入一個長度不超過20的字符串,對所輸入的字符串,按照ASCII碼的大小從小到大進行排序,請輸出排序后的結果。
      #include&lt;iostream&gt;
      #include&lt;string&gt;

      using namespace std;

      void main()
      {
              char str[21];
              int i,j,len;
              char ch;

              cout&lt;&lt;"請輸入字符串:";
              cin.getline(str,20);
              len=strlen(str);
              for(i=0;i&lt;len-1;i++)
                      for(j=0;j&lt;len-1-i;j++)
                              if(str[j]&gt;str[j+1])
                              {
                                      ch=str[j];
                                      str[j]=str[j+1];
                                      str[j+1]=ch;
                              }
              cout&lt;&lt;"排序后的字符串為:"&lt;&lt;str&lt;&lt;endl;
      }

      2002年A
      1、某人有8角的郵票5張,1元的郵票4張,1元8角的郵票6張,用這些郵票中的一張或若干張可以得到多少中不同的郵資?
      說明:這道題真的找不到好的算法,希望有好算法的朋友發站短給我,多謝
      #include&lt;iostream.h&gt;

      void main()
      {
              int i,j,k;

              for(i=0;i&lt;=5;i++)
                      for(j=0;j&lt;=4;j++)
                              for(k=0;k&lt;=6;k++)
                                      cout&lt;&lt;i*0.8+j+k*1.8&lt;&lt;" ";
      }

      2、輸入n值,使用遞歸函數,求楊輝三角形中各個位置上的值,按照如下形式打印輸出圖形。例如:當n=6時。             1
      1 1
      1 2 1
      1 3 3 1
      1 4 6 4 1
      1 5 10 10 5 1
      說明:遞歸
      #include&lt;iostream.h&gt;

      int fun(int n,int k)
      {
              if(k==0||n==k)
                      return 1;
              else
                      return fun(n-1,k-1)+fun(n-1,k);
      }

      void main()
      {
              int n,i,j;

              cout&lt;&lt;"請輸入n:";
              cin&gt;&gt;n;
              for(i=0;i&lt;n;i++)
              {
                      for(j=0;j&lt;=i;j++)
                              cout&lt;&lt;fun(i,j)&lt;&lt;" ";
                      cout&lt;&lt;endl;
              }
      }

      2002年B
      1、打印所有不超過n(n&lt;256)的,其平方具有對稱性質的數。如11*11=121。
      #include&lt;iostream.h&gt;
      #include&lt;stdlib.h&gt;

      bool fun(int n)
      {
              int x,i,t;
              char str[10];

              x=n*n;
              i=0;
              while(x)
              {
                      t=x%10;
                      str[i++]=t+48;
                      x/=10;
              }
              str='\0';
              if(n*n==atoi(str))
                      return true;
              else
                      return false;
      }

      void main()
      {
              int n,i;

              cout&lt;&lt;"請輸入n:";
              cin&gt;&gt;n;
              for(i=1;i&lt;=n;i++)
                      if(fun(i))
                              cout&lt;&lt;i&lt;&lt;" ";
              cout&lt;&lt;endl;
      }

      2、編寫一個求菲波那奇數列的遞歸函數,輸入n值,使用該遞歸函數,輸出如下圖形。例如:當n=6時。        0
      0 1 1
      0 1 1 2 3
      0 1 1 2 3 5 8
      0 1 1 2 3 5 8 13 21
      0 1 1 2 3 5 8 13 21 34 55
      說明:遞歸
      #include&lt;iostream.h&gt;

      int fun(int n)
      {
              if(n==0)
                      return 0;
              else if(n==1)
                      return 1;
              else
                      return fun(n-2)+fun(n-1);
      }

      void main()
      {
              int n,i,j;
              int *p=new int[60];

              cout&lt;&lt;"請輸入n:";
              cin&gt;&gt;n;
              for(i=0;i&lt;2*n-1;i++)
                      p[ i ]=fun(i);
              for(i=0;i&lt;n;i++)
              {
                      for(j=0;j&lt;2*i+1;j++)
                              cout&lt;&lt;p[j]&lt;&lt;" ";
                      cout&lt;&lt;endl;
              }
      }


      2003年
      1、輸入球的中心點和球上某一點的坐標,計算球的半徑和體積。
      #include&lt;iostream.h&gt;
      #include&lt;math.h&gt;

      void main()
      {
              double r;
              int x1,x2,y1,y2,z1,z2;
              const double PI=3.1416;
              
              cout&lt;&lt;"請輸入中心點坐標:";
              cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;z1;
              cout&lt;&lt;"請輸入球上某一點的坐標:";
              cin&gt;&gt;x2&gt;&gt;y2&gt;&gt;z2;
              r=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
              cout&lt;&lt;"半徑為:"&lt;&lt;r&lt;&lt;endl;
              cout&lt;&lt;"體積為:"&lt;&lt;(4*PI*r*r*r)/3&lt;&lt;endl;
      }

      2、手工建立一個文件,文件種每行包括學號、姓名、性別和年齡。每一個屬性使用空格分開。文件如下: 01 李江 男 21 02 劉唐 男 23 03 張軍 男 19 04 王娜 女 19 根據輸入的學號,查找文件,輸出學生的信息。
      #include&lt;iostream&gt;
      #include&lt;fstream&gt;
      #include&lt;string&gt;
      #include&lt;stdlib.h&gt;
      using namespace std;

      void main()
      {
              const int LEN=100;
              char s[LEN],k[LEN],*temp;
              int num;

              cout&lt;&lt;"請輸入要查找學生的學號:";
              cin&gt;&gt;num;
              ifstream fin("myfile.txt";
              
              while(fin.getline(s,LEN))
              {
                      strcpy(k,s);
                      temp=strtok(k," ");
                      if(atoi(temp)==num)
                      {
                              cout&lt;&lt;num&lt;&lt;"號學生的信息為:"&lt;&lt;s&lt;&lt;endl;
                              break;
                      }
              }
      }

      3、輸入年月日,計算該填是本年的第幾天。例如1990年9月20日是1990年的第263天,2000年5月1日是2000年第122天。(閏年:能被400正除,或能被4整除但不能被100整除。每年1、3、5、7、8、10為大月)
      #include&lt;iostream.h&gt;

      void main()
      {
              int i,sum=0,year,month,day;
              const int num[12]={31,28,31,30,31,30,31,31,30,31,30,31};

              cout&lt;&lt;"請輸入年月日:";
              cin&gt;&gt;year&gt;&gt;month&gt;&gt;day;
              for(i=0;i&lt;month-1;i++)
                      sum+=num;
              sum+=day;
              if((year%4==0&&year%100!=0)||year%400==0)
                      sum+=1;
              cout&lt;&lt;year&lt;&lt;"年"&lt;&lt;month&lt;&lt;"月"&lt;&lt;day&lt;&lt;"日是"&lt;&lt;year&lt;&lt;"年的第"&lt;&lt;sum&lt;&lt;"天"&lt;&lt;endl;
      }


      2004年
      第一題是建立一個角類,在這個類中重載減號運算符,并實現求出角度的正弦值的函數。
      #include&lt;iostream.h&gt;
      #include&lt;math.h&gt;

      const double PI=3.1416;

      class angle
      {
      public:
              angle() {}
              angle(int x) {X=x;}
              angle operator - (angle c);
              void xsin();
      private:
              int X;
      };
      #include"angle.h"

      void angle::xsin()
      {

              double x;
              x=(X*PI)/180;
              cout&lt;&lt;"正弦值為:"&lt;&lt;sin(x)&lt;&lt;endl;
      }

      angle angle:perator - (angle c)
      {
              return angle(X-c.X);
      }
      #include"angle.h"

      void main()
      {
              angle c1(90),c2(60),c3;
              c3=c1-c2;
              c1.xsin();
              c2.xsin();
              c3.xsin();
      }

      第二題是建立一個求一元二次方程解的類(a*x^2+b*x+c=0),輸入系數a,b,c的值后打印出這個方程的解來,也比較簡單。需要注意的是系數a不能為零以及方程有無解,單解還是雙解的情況。
      #include&lt;iostream.h&gt;

      class equation
      {
      public:
              equation(float a,float b,float c):a(a),b(b),c(c) {}
              float D() {return b*b-4*a*c;}
              void fun();
      private:
              float a,b,c;
      };
      #include&lt;math.h&gt;
      #include"equation.h"

      void equation::fun()
      {
              float d=D();
              
              if(d==0)
                      cout&lt;&lt;"單解為:"&lt;&lt;-b/(2*a)&lt;&lt;endl;
              else if(d&gt;0)
                      cout&lt;&lt;"雙解為:"&lt;&lt;(-b+sqrt(d))/(2*a)&lt;&lt;","&lt;&lt;(-b-sqrt(d))/(2*a)&lt;&lt;endl;
              else
                      cout&lt;&lt;"復數解為:"&lt;&lt;-b/(2*a)&lt;&lt;"+"&lt;&lt;sqrt(-d)/(2*a)&lt;&lt;"i,"&lt;&lt;-b/(2*a)&lt;&lt;"+"&lt;&lt;-sqrt(-d)/(2*a)&lt;&lt;"i"&lt;&lt;endl;
      }
      #include"equation.h"

      void main()
      {
              float a,b,c;

              cout&lt;&lt;"請輸入(a b c):";
              cin&gt;&gt;a&gt;&gt;b&gt;&gt;c;
              while(a==0)
              {
                      cout&lt;&lt;"非法,請重新輸入(a b c):";
                      cin&gt;&gt;a&gt;&gt;b&gt;&gt;c;
              }
              equation e(a,b,c);
              e.fun();
      }

      第三道題是實現一個多項式的類(a+b*x+c*x^2+d*x^3+...+),要求輸入該多項式的系數和x的值后打印出這個多項式的值。這道題本身并不難,但他要求用好的算法(實際上就是遞歸)。
      #include&lt;iostream.h&gt;

      float fun(float s[],float x,int n,int N)
      {
              if(n==0)
                      return s[N];
              else
                      return s[N-n]+x*fun(s,x,n-1,N);
      }

      void main()
      {
              int i,N;
              float num[60],x;

              cout&lt;&lt;"請輸入最高項次數:";
              cin&gt;&gt;N;
              cout&lt;&lt;"請依次輸入系數:";
              for(i=0;i&lt;=N;i++)
                      cin&gt;&gt;num[ i ];
              cout&lt;&lt;"請輸入x:";
              cin&gt;&gt;x;
              cout&lt;&lt;"結果為:"&lt;&lt;fun(num,x,N,N)&lt;&lt;endl;
      }

      2005年
      第一題是給定一個程序,關于字符串的,要求輸入并調試,說出此程序的意圖。意圖是按字母順序對兩個字符串比較排序。第二問要求用盡可能少的語句對該程序進行修改,使其能夠對兩個字符串比較長度排序。本題滿分20。

      第二題是要求編寫一個日期類,要求按xxxx-xx-xx的格式輸出日期,實現加一天的操作,不考慮閏年問題,所有月份設為30天。本題黑盒測試時,輸入2004年3月20日,得到加一天后時間為2004-3-21,能得一部分分數。輸入2004年3月30日,得到加一天后時間為2004-4-1,能得一部分分數。輸入2004年12月30日,得到加一天后時間為2005-1-1,且有時間越界處理,能得全部分數。本題滿分30。
      #include&lt;iostream.h&gt;

      class date
      {
      public:
              date(int y,int m,int d):year(y),month(m),day(d){}
              void display();
              void addDay();
      private:
              int year;
              int month;
              int day;
      };
      #include"date.h"

      void date::display()
      {
              cout&lt;&lt;year&lt;&lt;"-"&lt;&lt;month&lt;&lt;"-"&lt;&lt;day&lt;&lt;endl;
      }

      void date::addDay()
      {
              day++;
              if(day&gt;30)
              {
                      day%=30;
                      month++;
                      if(month&gt;12)
                      {
                              month%=12;
                              year++;
                      }
              }
      }
      #include"date.h"

      void main()
      {
              int y,m,d;

              cout&lt;&lt;"請輸入(年 月 日):";
              cin&gt;&gt;y&gt;&gt;m&gt;&gt;d;
              while(y&lt;0||m&lt;0||m&gt;12||d&lt;0||d&gt;30)
              {
                      cout&lt;&lt;"非法,請重新輸入(年 月 日):";
                      cin&gt;&gt;y&gt;&gt;m&gt;&gt;d;
              }
              date d1(y,m,d);
              d1.addDay();
              d1.display();
      }

      第三題要求編寫一個復數類,要求有4條。一是有構造函數,能對復數初始化。二是對復數c1,c2,c3.....能實現連加運算,令c=c1+c2+c3+.....此處可以重載加法操作符。三是有函數實現兩個復數相加,并按照a+ib的形式輸出。四是能實現對一個復數c=a+ib,定義double x=c有效,使x的值為實部和虛部之和。本題滿分50。”
      #include&lt;iostream&gt;
      using namespace std;
      class complex
      {
      public:
              complex(double r=0.0,double i=0.0) {real=r;imag=i;}
              complex operator + (complex c2);
              void display();
              operator double ()                //重載類型轉換操作
              {
                      return  (real+imag);
              }
      private:
              double real;
              double imag;
      };
      #include"complex.h"

      complex complex:perator + (complex c2)
      {
              return complex(real+c2.real,imag+c2.imag);
      }

      void complex::display()
      {
              cout&lt;&lt;real&lt;&lt;"+"&lt;&lt;imag&lt;&lt;"i"&lt;&lt;endl;
      }
      #include"complex.h"

      void main()
      {
              complex c1(5,4),c2(2,10),c3(6,9),c4;

              c4=c1+c2+c3;
              c4.display();
              double x=c4;
              cout&lt;&lt;x&lt;&lt;endl;
      }


      2006年
      1.寫一個程序判斷字符串中數字的位置(不限制使用面向對象編程)
      例如: 輸入   a3b4c5
           輸出   2 4 6
      #include&lt;iostream&gt;
      #include&lt;ctype.h&gt;
      #include&lt;string&gt;
      using namespace std;

      void main()
      {
              string str;
              int i;

              cout&lt;&lt;"請輸入字符串:";
              getline(cin,str);
              for(i=0;str[ i ]!='\0';i++)
                      if(isdigit(str[ i ]))
                              cout&lt;&lt;i+1&lt;&lt;" ";
              cout&lt;&lt;endl;
      }

      2.寫一個類,能接受int型的變量,接收變量后能存儲原變量(譬如12345)和其反向變量(54321),最多處理數量為10個,當輸入達到10個或者輸入變量為0的時候停止。并且在類銷毀前輸出存儲的所有變量。
      例如: 輸入:12345,2234,0
                  輸出:12345   54321
                          2234  4322
      #include&lt;iostream.h&gt;
      #include&lt;stdlib.h&gt;

      class CInverse
      {
      public:
              CInverse();
              void inverse();
              ~CInverse();
      private:
              int num[10];
              int inverseNum[10];
              int countNum;
      };
      #include"CInverse.h"

      CInverse::CInverse()
      {
              int t,i;

              cout&lt;&lt;"請輸入整數,以0停止:";
              cin&gt;&gt;t;
              for(i=0;i&lt;10&&t!=0;i++)
              {
                      num[ i ]=t;
                      cin&gt;&gt;t;
              }
              countNum=i;
      }

      void CInverse::inverse()
      {
              char str[10];
              int t,i,j,x;
              
              for(i=0;i&lt;countNum;i++)
              {
                      x=num;
                      j=0;
                      while(x)
                      {
                              t=x%10;
                              str[j++]=t+48;                //加48
                              x/=10;
                      }
                      str[j]='\0';
                      inverseNum=atoi(str);
              }
      }

      CInverse::~CInverse()
      {
              int i;

              for(i=0;i&lt;countNum;i++)
                      cout&lt;&lt;num&lt;&lt;" "&lt;&lt;inverseNum&lt;&lt;endl;
      }
      #include"CInverse.h"

      void main()
      {
              CInverse c1;
              c1.inverse();
      }

      3.寫一個CTriangle類,要求可以接受 CTriangle(y,x)形式的構造,創建在坐標系中的直角三角形樣子如下
      三點的坐標分別是A(0,y) B(0,0) C(x,0)
      實現+運算,并且能夠處理鍵盤連續輸入若干個(少于十個)三角形,并且連加(相加時候三角形邊長長度相加,方向同第一個三角形)。輸入0后結束并輸出最后得出的三角形的三個坐標值。
      #include&lt;iostream.h&gt;

      class CTriangle
      {
      public:
              CTriangle(int y=0,int x=0) {Ay=y;Cx=x;}
              CTriangle operator + (CTriangle c2);
              void set(int y=0,int x=0) {Ay=y;Cx=x;}
              void display();
      private:
              int Ay;
              int Cx;
      };
      #include"CTriangle.h"

      CTriangle CTriangle:perator + (CTriangle c2)
      {
              return CTriangle(Ay+c2.Ay,Cx+c2.Cx);
      }

      void CTriangle::display()
      {
              cout&lt;&lt;"A(0,"&lt;&lt;Ay&lt;&lt;") B(0,0) C("&lt;&lt;Cx&lt;&lt;",0)"&lt;&lt;endl;
      }
      #include"CTriangle.h"

      void main()
      {
              int y,x,i,N;
              CTriangle c[10],sum;

              cout&lt;&lt;"請輸入坐標:";
              cin&gt;&gt;y;
              for(i=0;y!=0;i++)
              {
                      cin&gt;&gt;x;
                      c[ i ].set(y,x);
                      cin&gt;&gt;y;
              }
              N=i;
              sum.set();                //置0
              for(i=0;i&lt;N;i++)
                      sum=sum+c;
              sum.display();
      }


      2007年
      1。一個小球,從高為H的地方下落,下落彈地之后彈起高度為下落時的一半,
      比如第一次彈起高度為H/2,如此往復,計算從小球H高度下落到第n次彈地
      往返的總路程。
      要求:1。用遞歸的方法實現
            2。輸入H和n,輸出結果
            3。注意程序的健壯性
            4?梢杂肅或C++實現
      #include&lt;iostream.h&gt;
      #include&lt;math.h&gt;

      float fun(int n)
      {
              if(n==1)
                      return 1;
              else
                      return fun(n-1)+1/pow(2,n-2);
      }

      void main()
      {
              float H;
              int n;

              cout&lt;&lt;"請輸入H和n:";
              cin&gt;&gt;H&gt;&gt;n;
              cout&lt;&lt;"小球從"&lt;&lt;H&lt;&lt;"高度下落到第"&lt;&lt;n&lt;&lt;"次彈地往返的總路程為:"&lt;&lt;fun(n)*H&lt;&lt;endl;
      }

      2。創建一個CPoint類,代表平面直角坐標系中的點,創建構造函數和運算符重載函數,
      運算符重載為類重載(非友元重載),可以實現計算兩個點之間的距離。可以根據需要
      加入自己的成員變量或成員函數
      要求:1。輸入兩個點的坐標,輸出兩個點之間的距離
            2。重載運算符為“-”
      #include&lt;iostream.h&gt;

      class CPoint
      {
      public:
              CPoint(int x=0,int y=0) {X=x;Y=y;}
              float operator - (CPoint c2);
      private:
              int X;
              int Y;
      };
      #include"CPoint.h"
      #include&lt;math.h&gt;

      float CPoint:perator - (CPoint c2)
      {
              return sqrt((X-c2.X)*(X-c2.X)+(Y-c2.Y)*(Y-c2.Y));
      }
      #include "CPoint.h"

      void main()
      {
              int x1,y1,x2,y2;

              cout&lt;&lt;"請輸入兩個點的坐標:";
              cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;x2&gt;&gt;y2;
              CPoint c1(x1,y1),c2(x2,y2);
              cout&lt;&lt;"兩點間的距離為:"&lt;&lt;c1-c2&lt;&lt;endl;
      }

      3。創建一個CTriangle類,需要用到第二題中創建的類,即用3點來代表一個三角形,
      輸入三個點的坐標,實現判斷此三角形是不是直角三角形,并輸出此三角形的周長。
      可以根據需要加入自己的成員變量或成員函數
      要求:1。輸入三個點的坐標,輸出周長并給出是否直角三角形的信息
            2。注意程序的健壯性
      #include&lt;iostream.h&gt;

      class CPoint
      {
      public:
              CPoint(int x=0,int y=0) {X=x;Y=y;}
              float operator - (CPoint c2);
      private:
              int X;
              int Y;
      };

      class CTriangle
      {
      public:
              CTriangle(CPoint a,CPoint b,CPoint c):A(a),B(b),C(c)
              {
                      AB=A-B;
                      BC=B-C;
                      AC=A-C;
              }
              void display();
              bool fun();
      private:
              CPoint A,B,C;
              float AB,BC,AC;
      };
      #include"CTriangle.h"
      #include&lt;math.h&gt;

      float CPoint:perator - (CPoint c2)
      {
              return (float)sqrt((X-c2.X)*(X-c2.X)+(Y-c2.Y)*(Y-c2.Y));
      }

      void CTriangle::display()
      {
              cout&lt;&lt;"周長為:"&lt;&lt;AB+BC+AC&lt;&lt;endl;
      }

      bool CTriangle::fun()
      {
              float a=AB,b=BC,c=AC,t;

              if(a&gt;c)
              {
                      t=a;
                      a=c;
                      c=t;
              }
              if(b&gt;c)
              {
                      t=b;
                      b=c;
                      c=t;
              }
              if(fabs(a*a+b*b-c*c)&lt;10e-6)
                      return true;
              else
                      return false;
      }
      #include"CTriangle.h"

      void main()
      {
              int x1,y1,x2,y2,x3,y3;

              cout&lt;&lt;"請輸入三個頂點的坐標:";
              cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;x2&gt;&gt;y2&gt;&gt;x3&gt;&gt;y3;
              CPoint p1(x1,y1),p2(x2,y2),p3(x3,y3);
              CTriangle c(p1,p2,p3);
              if(c.fun())
              {
                      cout&lt;&lt;"是直角三角形"&lt;&lt;endl;
                      c.display();
              }
              else
                      cout&lt;&lt;"不是直角三角形"&lt;&lt;endl;
      }


      2008年
      1、存儲一組姓名,如 Apple,Tom,Green,Jack 要求能排序、按字母順序插入、并顯示。
      #include&lt;iostream&gt;
      #include&lt;string&gt;
      using namespace std;

      void main()
      {
              const int N=10;
              string s[N],temp;
              int i,j,K;

              cout&lt;&lt;"請輸入字符串個數:";
              cin&gt;&gt;K;
              cout&lt;&lt;"請輸入"&lt;&lt;K&lt;&lt;"個字符串:"&lt;&lt;endl;
              for(i=0;i&lt;K;i++)                //插入排序
              {
                      cin&gt;&gt;temp;
                      for(j=i;j&gt;0;j--)
                              if(temp&lt;s[j-1])
                                      s[j]=s[j-1];
                              else
                                      break;
                      s[j]=temp;
              }
              cout&lt;&lt;"排序后的結果為:"&lt;&lt;endl;
              for(i=0;i&lt;K;i++)
                      cout&lt;&lt;s&lt;&lt;endl;
      }       
      zz

      回復話題
      上傳/修改頭像

      北京在中國地圖的東南西北哪個方向?(答案為一個字)

      考研論壇提示:
      1、請勿發布個人聯系方式或詢問他人聯系方式,包括QQ和手機等。
      2、未經允許不得發布任何資料出售、招生中介等廣告信息。
      3、如果發布了涉及以上內容的話題或跟帖,您在考研網的注冊賬戶可能被禁用。

      網站介紹 | 關于我們 | 聯系方式 | 廣告業務 | 幫助信息
      ©1998-2015 ChinaKaoyan.com Network Studio. All Rights Reserved.

      中國考研網-聯系地址:上海市郵政信箱088-014號 郵編:200092 Tel & Fax:021 - 5589 1949 滬ICP備12018245號

      国产人片18禁免费看片_1024国产精品免费观看_一级特黄少妇自慰AAA_欧美欧美午夜AⅤ在线观看
    4. <video id="abmqw"><input id="abmqw"></input></video>
    5. <strong id="abmqw"><noscript id="abmqw"></noscript></strong>
    6. <i id="abmqw"><sub id="abmqw"></sub></i>
        <video id="abmqw"></video>
        <output id="abmqw"></output>

      1. <video id="abmqw"><ins id="abmqw"><table id="abmqw"></table></ins></video>

        <wbr id="abmqw"><input id="abmqw"></input></wbr>
      2. <thead id="abmqw"><span id="abmqw"></span></thead>
      3. 色先锋在线不卡2019 | 日本玖玖资源在线 | 午夜亚洲精品专区高潮日w 亚洲一区二区三区中文字幕网 | 日本精品一二区性爱区 | 亚洲无线观看国产高 | 色婷婷视频一区二区三区 |