联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2018-08-16 03:54


填充下面的划线部分,使其完成所要求的功能。答案卷只要写题号与填充的答案,不要题目:如:1. xxxxxxx 2.xxxxxxx…。将答案卷直接粘贴到作业栏。

下列程序打印出1000以内的所有“完全数”。“完全数”是指一个正整数,其所有

小于该数的因子之和等于该数本身。例如:6=1+2+3,又如:28=1+2+4+7+14。



#include“iostream.h”

#include”iomanip.h”

voidmain()

{int i,j,s;

 for (j=2; j<=1000; j++)

 { s=0;

    for (i=1; i<="" p="">

       if (___1____)s+=i;

    if (___2____) cout<<<setw(5)<<j;<>"     "<<j;<setw(5)<<j;<></j;<setw(5)<<j;<></setw(5)<<j;<>

 }                                                

}

10.在下面程序的横线处填上适当的语句,使该程序执行结果为10。

#include

class MyClass

{

public:

          ___3____         //为x置值

          ___4____         //取x值

private:

          int x;

};

void main()

{

      MyClass my(10)

cout << my.GetNum() << endl;

}


?

字数统计

2.(16.0分)

填充下面的划线部分,使其完成所要求的功能。答案卷只要写题号与填充的答案,不要题目:如:1. xxxxxxx 2.xxxxxxx…。将答案卷直接粘贴到作业栏。(2)


下面的类定义了拷贝构造函数,请完成该类的定义和实现。

class MyClass

{

public:

MyClass(int xx = 0, int yy = 0) {M = xx; N = yy;}

____1_______;    //拷贝构造函数

private:

          int M, N;

};

myClass::______2______          //拷贝构造函数的实现

{

M=____3______;

_____4 ______;

   }


?

字数统计

3.(20.0分)

填充下面的划线部分,使其完成所要求的功能。答案卷只要写题号与填充的答案,不要题目:如:1. xxxxxxx 2.xxxxxxx…。将答案卷直接粘贴到作业栏。(4)


以下程序是用来输出如下图形:

       


#include"iostream.h"

main()

{

 int i, j;

 for( i=1;  i<=5;  i++ )

 {

    for( j=1;  j<=5-i; j++ )  cout<< " "

    for( j=1;  j<=2*i-1;  j++ )

      if (____1____ ) cout<< "*" ;

      else cout<< "#" ;

   cout<< ""

 }

}



以下程序是用来输入5个整数,并存放在数组中,找出最大数与最小数所在的下标位置,并把二者对调,然后输出调整后的5个数。

#include"iostream.h"

main()

{

 int a[5], t, i, maxi, mini;

 for( i=0; i<5;  i++)

    cin>> a[i];

 mini=maxi=___2____;

 for( i=1; i<5;  i++)

 {

   if (___3____)  mini=i;

   if( a[i]>a[maxi] ) ___4____;

  }

  cout<< "最小数的位置是:"<< mini<<””;

  cout<< "最大数的位置是:"<< maxi<<””;

  t=a[maxi];

  ____5______;

a[mini]=t;

cout<< "调整后数的数为:"

for( i=0;  i<5; i++ )

      cout<<a[i]<<="" p=""></a[i]<

cout<<""

}






?

字数统计

4.(24.0分)

填充下面的划线部分,使其完成所要求的功能。答案卷只要写题号与填充的答案,不要题目:如:1. xxxxxxx 2.xxxxxxx…。将答案卷直接粘贴到作业栏。(3)


以下程序显示如下所示的矩阵,矩阵中每个元素形成的规律是:右上三角阵(含

   对角线)元素值为1,其它元素值为:行下标—列下标+1。

       1   1    1    1   1

       2   1    1    1   1

       3   2    1    1   1

       4   3    2    1   1

       5   4    3    2   1


#include”iostream.h”

main()

{inti,j, a[5][5];

  for( i=0; i<=4; i++ )

    for(j=0; j<5; j++ )

     if(___1____)a[i][j] = 1;

      else __2___=i-j+l;

 for(i=0; i<5; i++)

 { for(j=0; j<5; j++)cout<<setw(3)<<a[i][j];< p=""></a[i][j];<>

    cout<< "\n"


 }

}


以下scat函数将字符串str2连接到字符串strl之后。运行时,

   若输入:li ming,回车

   good morning!回车

   则输出:li ming,good morning!

请填空完成程序。

#include "iostream.h"

#include”stdio.h”

scat( char *strl, char *str2)

{ while(*strl !=___3_____)  strl++;

  while( *strl++ =___4______)      / *将str2连接到strl的后而*/


}

main()

{  char a[500],b[300];

  gets( a )  //从键盘输入一字符串放入a,

  gets( b )  //字符串中可包含空格

  scat( a, b )

  cout<<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">}

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">下列程序打印出1000以内的所有“完全数”。“完全数”是指一个正整数,其所有

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">小于该数的因子之和等于该数本身。例如:6=1+2+3,又如:28=1+2+4+7+14。

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">#include“iostream.h”

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">#include”iomanip.h”

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">voidmain()

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">{int i,j,s;

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;"> for (j=2; j<=1000; j++)

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;"> { s=0;

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">    for (i=1; i<="" p="">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">       if (___5____)s+=i;

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">    if (___6____)cout<<setw(5)<<j;<>  }          <setw(5)<<j;<></setw(5)<<j;<></setw(5)<<j;<>

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

<="" p="" target="_blank" style="font-size: 12px; text-decoration: none; cursor: pointer;">

?

字数统计

<="" p="" style="font-size: 12px; text-decoration: none; cursor: pointer;">

5.(24.0分)

填充下面的划线部分,使其完成所要求的功能。答案卷只要写题号与填充的答案,不要题目:如:1. xxxxxxx 2.xxxxxxx…。将答案卷直接粘贴到作业栏。(1)


invert()函数的功能是将一个字符串str的内容倒序存放

例如: 字符串str原内容为:abcde,函数调用后变为:edcba。

#include

#include

void invert (char str[ ])

    {int i,j, k;

    j=_____1_____;

      for(i=0; i<="" p="">

       {k=str[i];

        str[i]=str[j];

         str[j]=__2______;

       }

     }

    void main()

    { char test[]="abcde"

      invert (test)

      cout<<test;<><test;<></test;<><test;<></test;<><test;<></test;<><test;<></test;<></test;<>

}

完成下面的类定义。

class MyClass

{

public:

          MyClass( ) { x = 0; }

          ___3___ int GetNum(______4____ my)

private:

          int x;

};

int GetNum(____4____ my)

{

      return my.x;

}


计算下列分段函数,x由键盘输入。

       0 (x<=-15.0)

    y=   x (-15.0< x )<x<=10.0)<><x<=10.0)<></x<=10.0)<></x<=10.0)<>

       2x-3 (x>20.0)

#include"stdio.h"

main()

{

 float x,y;

 if(x<=-15.0)y=0;

  else if (   5    )y=x;

  else __6____;

  printf(“%f”,x)

}


编写一个程序求2/1+3/2+5/3+8/5+13/8+21/13……的前15项之和。

?

字数统计

2.(35.0分)

编写一个程序求一元二次方程的解并打印解。

 讨论下述情形:

(1)a=0,不是二次方程。

 (2)b^2-4ac=0,有两个相等实根。

 (3) b^2-4ac>0,有两个不等实根。

 (4) b^2-4ac<0<>,有两个复根(表示成x+yi,x-yi)。



?

字数统计

3.(35.0分)

定义一个Point类来处理三维点points(x,y,z).该类有一默认的constructor,一copy constructor, 一negate()成员函数将point的x,y和z值各乘-1, 一norm()成员函数返回该点到原点(0,0,0)的距离,一个print()成员函数显示x,y,和z的值。


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp