一、    选择题:
1、C++源程序文件的扩展名是:a
A) .CPP        B) .C        C) .DLL         D) .EXE2、将小写字母n赋值给字符变量one_char,正确的操作是:b
A) one_char = ‘\n’;      B) one_char = “n”;
C) one_char = 110;      D) one_char = ‘N’;3、整型变量i定义后赋初值的结果是:b
   int i=2.8*6;
A) 12     B) 16     C) 17    D) 184、下列表达式的值为false的是:c
A) 1<3 && 5<7      B) !(2>4)     C) 3&0&&1    D) !(5<8)||(2<8)5、设int a=10, b=11, c=12;表达式(a+b)<c&&b==c的值是:B
A) 2       B) 0       C) –2      D) 16、下列程序执行完后,x的值是:c
  int x=0;
  for (int k=0;k<90; k++)
if (k)  x++;
A) 0         B) 30      C) 89     D) 907、下列程序段循环次数是:d
  int x = -10;
  while (++x)  cout<<x<<endl;
A) 9        B) 10      C) 11         D) 无限8、表示“大于10而小于20的数“,正确的是:c
A) 10<x<20   B) x>10||x<20   C) x>10&x<20     D) !(x<=10||x>=20)9、若整型变量x=2,则表达式x<<2的结果是:d
A) 2        B) 4     C) 6      D) 810、设a=1, b=2,则(a++)+b与a+++b这两个表达式的值分别为:c
A) 3, 3    B) 3, 4     C) 4, 3    D) 4,4二、程序填空题。
1、下列程序计算1000以内能被3整除的自然数之和。
#include <iostream.h>
void main( )
{   int x=1, sum;
sum=0_______;
while (true)
{   if (x>1000)  break;
    if (x%3==0) sum+=x;
    x++;
}
cout<<sum<<endl;
}
三、假定输入10个整数:32,64,53,87,54,32,98,56,98,83。下列程序的输出结果是?
#include <iostream.h>
void main( )
{   int a,b,c,x;
   a=b=c=0;
   for (int k=0; k<10; k++)
   {   cin>>x;
switch(x%3)
{   case 0:  a+=x; break;
    case 1:  b+=x; break;
    case 2:  c+=x; break;
}
   }
cout<<a<<”,”<<b<<”,”<<c<<endl;
}
32,32,32
64,64,0
53,53,53
87,0,0
54,0,0
32,32,32
98,98,98
56,56,56 
98,98,98
83,83,83 四、写出下列程序运行结果。
#include <iostream.h>
void main( )
{   int j,k;
for (j=5; j>0; j--)
{  for (k=j; k>0; k--)
     cout<<”*”;
  cout<<endl;
}
}
*五、写出下列程序的运行结果。
#include <iostream.h>
#include <iomanip.h>
void main()
{   
cout<<”x_width=”<<cout.width()<<endl;
cout<<”x_fill=”<<cout.fill()<<endl;
cout<<”x_precision=”<<cout.precision()<<endl;
cout<<123<<” ”<<123.45678<<endl;
cout<<”***x_width=10,x_fill=&,x_precision=8***”<<endl;
cout.width(10);
cout.fill(‘&’);
cout.precision(8);
cout<<123<<” “<<123.45678<<endl;
cout.setf(ios::left);
cout<<123<<” “<<123.45678<<endl;
cout.width(10);
cout<<123<<” “<<123.45678<<endl;
cout<<”x_width=”<<cout.width()<<endl;
cout<<”x_fill=”<<cout.fill()<<endl;
cout<<”x_precision=”<<cout.precision()<<endl;
}
六、程序题。
1、    编写程序,求解方程ax2+bx+c=0的根。
2、    编写程序输出所有的水仙花数。所谓水仙花数是指一个三位数,其各位数的立方和等于该数。例如:153=13+53+33。
main()
{
 Int x=0,y=0,z=0,k=0;
for(x=0;x<10;x++)
{for(y=0;y<10;y++)
{for(z=0;z<10;z++)
}}if(x*x*x+y*y*y+z*z*z=100*x+10*y+z)k=100*x+10*y+z;
cout<<k<<endl
}3、    编写程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值。4、某百货公司为了促销,采用购物打折的办法。
(1)    在1000元以上者,按九五折优惠;
(2)    在2000元以上者,按九折优惠;
(3)    在3000元以上者,按八五折优惠;
(4)    在5000元以上者,按八折优惠。
编写程序,输入购物款数,计算并输出优惠价。(要求用switch语句编写)
main()
{
   Int   x ,y=0
cin>>x;
if(x<1000) case=0;
if(x=>1000&&x<2000)case=1;
if(x=>2000&&x<3000)case=2;
if(x=>3000&&x<5000)case=3;
if(x=>5000)case=4;
swith()

case=0: y=x; break;
case=1: y=0.95*x; break;
case=2: y=0.9*x; break;
case=3: y=0.85*x; break;
      case=4: y=0.8*x; break;
}
cout<<y<<endl;
}5、    将一张一元纸币兑换成一分、二分和五分的硬币,假定每种至少一枚,计算共有多少种兑换法并打印出各种兑换法。
main()
{
int x,y,z,k=0;
for(x=1;x<99;x++)
{for(y=1;y<99;y++)
{for(z=1;z<99;z++)if(x+2*y+5*z=100){k++;
}
}
}
}6、“同构数”是指这样的整数:它恰好出现在其平方数的右端。如:376*376=141376。请找出10000以内的全部“同构数”。

解决方案 »

  1.   

    美女徒弟...........羡慕ing ~~~~~~~~~~~~~~
    LZ估计是看美女看的大脑短路了,所以来求帮助~~~~~~~~~~
    挖卡卡~~~~~~~~~~
      

  2.   

    //把没做的做一下五、写出下列程序的运行结果。
    #include <iostream.h>
    #include <iomanip.h>
    void main()
    {   
    cout<<”x_width=”<<cout.width()<<endl;
    cout<<”x_fill=”<<cout.fill()<<endl;
    cout<<”x_precision=”<<cout.precision()<<endl;
    cout<<123<<” ”<<123.45678<<endl;
    cout<<”***x_width=10,x_fill=&,x_precision=8***”<<endl;
    cout.width(10);
    cout.fill(‘&’);
    cout.precision(8);
    cout<<123<<” “<<123.45678<<endl;
    cout.setf(ios::left);
    cout<<123<<” “<<123.45678<<endl;
    cout.width(10);
    cout<<123<<” “<<123.45678<<endl;
    cout<<”x_width=”<<cout.width()<<endl;
    cout<<”x_fill=”<<cout.fill()<<endl;
    cout<<”x_precision=”<<cout.precision()<<endl;
    }x_width=0
    x_fill=
    x_precision=6
    123 123.457
    ***x_width=10,x_fill=&,x_precision=8***
    &&&&&&&123 123.45678
    123 123.45678
    123&&&&&&& 123.45678
    x_width=0
    x_fill=&
    x_precision=8六、程序题。
    1、    编写程序,求解方程ax2+bx+c=0的根。
    #include<stdio.h>
    #include<math.h>
    float x1,x2,p,q,d;
    float great_than_zero(float,float);
    float equql_to_zero(float,float);
    float smaller_than_zero(float,float);
    main()
    {
    float a,b,c;
    printf("Enter a,b,c:");
    scanf("%f%f%f",&a,&b,&c);
    d=b*b-4*a*c;
    if(d>0)
    {
     great_than_zero(a,b);
     printf("x1=%5.2f\tx2=5.2f\n",x1,x2);
       }
    else if(d==0)
       {
        equal_to_zero(a,b);
        printf("x1=x2=%6.2f\n",x1);
          }
        else
          {
            smaller_than_zero(a,b);
            printf("x1=%5.2f+i%5.2f\n",p,q);
            printf("x2=%5.2f-i%5.2f\n",p,q);
               }
         return 0;
    }
    float great_than_zero(float x,float y)
    {
      x1=(-y+sqrt(d))/(2*x);
      x2=(-y-sqrt(d))/(2*x);
      return ;
       }float equql_to_zero(float x,float y)
    {
     x1=(-y)/(2*x);
     return;
    }float smaller_than_zero(float x,float y)
    {
     p=-y/(2*x);
     q=sqrt(-d)/(2*x);
      return;
       } 
    6、“同构数”是指这样的整数:它恰好出现在其平方数的右端。如:376*376=141376。请找出10000以内的全部“同构数”。int isomorphic(int a)
    {
    int b,n=0,temp,square;
        temp=a;
    square=a*a;
    do{
       n++;
      }while(a/=10);
    b=square%(int)pow(10,n); if(temp==b)
    return 1;
    return 0;
    }
      

  3.   

    laiwusheng(一箫一剑走江湖)好同志 ..
    声明一下,那小女子仅仅是我徒弟...没有任何其他的关系..我把她的题放上来,是因为我最近实在没空...也顺便给那些单身的兄弟们提供点机会....既然你们不珍惜..我也没有办法...laiwusheng(一箫一剑走江湖)这是唯一一个做了几道题的好同志 ,我决定把我徒弟的QQ号码给他..至于是否是美女,他自己鉴定了.请这位兄弟到社区短信中接收QQ号码..
      

  4.   

    第2题错了,原因:
    cannot convert from 'char [2]' to 'char'
      

  5.   

    7、下列程序段循环次数是:d
      int x = -10;
      while (++x)  cout<<x<<endl;
    A) 9        B) 10      C) 11         D) 无限==================================================第7题明显也错了,应选 A
      

  6.   

    7、下列程序段循环次数是:d
      int x = -10;
      while (++x)  cout<<x<<endl;
    A) 9        B) 10      C) 11         D) 无限
    ==================================================
    明显错了,应选 A
      

  7.   

    8、表示“大于10而小于20的数“,正确的是:c
    A) 10<x<20   B) x>10||x<20   C) x>10&x<20     D) !(x<=10||x>=20)==================================================
    明显错了,应选 D
      

  8.   

    我把前些题一点一点的发到C/C++的版上了,请各位帮忙,我刚刚学C语言,谢谢
      

  9.   

    10、设a=1, b=2,则(a++)+b与a+++b这两个表达式的值分别为:c
    A) 3, 3    B) 3, 4     C) 4, 3    D) 4,4============
    错了,应该选 A
      

  10.   

    /*6、“同构数”是指这样的整数:
    它恰好出现在其平方数的右端。
    如:376*376=141376。
    请找出10000以内的全部“同构数”。*/
    # include "iostream.h"
    void main()
    {
     long int x;
     int y=0;
    for (int i=1;i<10000;i++)
     {
      x=i*i;
      if ( i-(x%10)==0)
      y=1;
       else if ( i-(x%100)==0)
      y=1;
       else if (( i-(x%1000) )==0)
      y=1;
       else if (( i-(x%10000) )==0)
      y=1;
    if (y==1)
      {
      cout<<i<<"x"<<i<<"="<<x<<endl;
      }
      y=0; }
    初学者更容易理解些~~
      

  11.   

    三、假定输入10个整数:32,64,53,87,54,32,98,56,98,83。下列程序的输出结果是?
    #include <iostream.h>
    void main( )
    {   int a,b,c,x;
       a=b=c=0;
       for (int k=0; k<10; k++)
       {   cin>>x;
    switch(x%3)
    {   case 0:  a+=x; break;
        case 1:  b+=x; break;
        case 2:  c+=x; break;
    }
       }
    cout<<a<<”,”<<b<<”,”<<c<<endl;
    }=================
    输出应该为:141,64,452
      

  12.   

    谢谢laiwusheng(一箫一剑走江湖),loomman(一剑),wysbk002()    3位大哥,
    点名表扬,哈哈,不过,我还是有的题没懂。有谁能继续帮忙。
      

  13.   

    四、写出下列程序运行结果。
    #include <iostream.h>
    void main( )
    {   int j,k;
    for (j=5; j>0; j--)
    {  for (k=j; k>0; k--)
         cout<<”*”;
      cout<<endl;
    }
    }
    =================
    输出应该为:*****
    ****
    ***
    **
    *
      

  14.   

    五、写出下列程序的运行结果。
    #include <iostream.h>
    #include <iomanip.h>
    void main()
    {   
    cout<<”x_width=”<<cout.width()<<endl;
    cout<<”x_fill=”<<cout.fill()<<endl;
    cout<<”x_precision=”<<cout.precision()<<endl;
    cout<<123<<” ”<<123.45678<<endl;
    cout<<”***x_width=10,x_fill=&,x_precision=8***”<<endl;
    cout.width(10);
    cout.fill(‘&’);
    cout.precision(8);
    cout<<123<<” “<<123.45678<<endl;
    cout.setf(ios::left);
    cout<<123<<” “<<123.45678<<endl;
    cout.width(10);
    cout<<123<<” “<<123.45678<<endl;
    cout<<”x_width=”<<cout.width()<<endl;
    cout<<”x_fill=”<<cout.fill()<<endl;
    cout<<”x_precision=”<<cout.precision()<<endl;
    }
    =================
    输出应该为:
    x_width=0
    x_fill=
    x_precision=6
    123 123.457
    ***x_width=10,x_fill=&,x_precision=8***
    &&&&&&&123 123.45678
    123 123.45678
    123&&&&&&& 123.45678
    x_width=0
    x_fill=&
    x_precision=8
      

  15.   

    2、将小写字母n赋值给字符变量one_char,正确的操作是:b
    A) one_char = ‘\n’;      B) one_char = “n”;
    C) one_char = 110;      D) one_char = ‘N’;这个题选B???
      

  16.   

    这是我的题,我不会做,有事找我好了,谢谢loomman(一剑),但是你能给怎么做出来的解释一下吗?我没懂是怎么来的。谢谢哈
      

  17.   

    看了選擇題,終於理解:給美女做題,不能全對,要不拿100分,不就讓人知道這有問題了麼?2、将小写字母n赋值给字符变量one_char,正确的操作是:b
    A) one_char = ‘\n’;      B) one_char = “n”;
    C) one_char = 110;      D) one_char = ‘N’;
    要選C 。 A B D  明顯錯誤 就算背不了ASCII碼也要選 C 7、下列程序段循环次数是:d (A) x = 0 時終止
      int x = -10;
      while (++x)  cout<<x<<endl;                      
    A) 9        B) 10      C) 11         D) 无限10、设a=1, b=2,则(a++)+b与a+++b这两个表达式的值分别为:c(B) a+++b = a+(++b)
    A) 3, 3    B) 3, 4     C) 4, 3    D) 4,4如果誰能剛好做出60分,那才是高手。
      

  18.   

    這樣的C++題目,真該放到C++論壇去。樓主的第一手答案或許也就是剛好得到60分吧
    4、某百货公司为了促销,采用购物打折的办法。
    (1)    在1000元以上者,按九五折优惠;
    (2)    在2000元以上者,按九折优惠;
    (3)    在3000元以上者,按八五折优惠;
    (4)    在5000元以上者,按八折优惠。
    编写程序,输入购物款数,计算并输出优惠价。(要求用switch语句编写)
    double getmoney(double x) 
    {
    double y ;   
    int Type = x /1000 ; 
    if(Type > 4)  
      Type = 4 ; 
    swith(Type)

    case 1: y=0.95; break;
    case 2: y=0.9; break;
    case 3: y=0.85; break;
    case=4: y=0.8; break;
    default :y=1; break; 
    }
      return  x*y;
    }
    #include <stdio.h>
    main()
    {
    double x ; 
    cout<<"請輸入購物金額 : ";
    cin>>x ;  
    cout<<"折扣後實際金額是:"<<getmoney(x)<<endl;
    }