问答题
下面程序的功能是生成具有n个元素的动态数组。
#include < iostream.h >
void main()
{ int n;
cin >> n;
int a[n];
a[0] =2;
cout << a[0] << endl;
}
【参考答案】
int a[n]; 生成具有n个元素的动态数组,要使用new,所以int a[n];错误。应改为int *a=new i......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
点击查看答案
<上一题
目录
下一题>
热门
试题
问答题
下面程序用于输出最小值,有一处错误。#include < iostream.h >class Test{ int a, b;int getmin(){return (a<b a:b);}public:int c;void setValue( int x1, int x2, int x3 ){ a =x1; b =x2; c =x3;}int GetMin();};int Test::GetMin(){ int d = getmin ();return (d=d<c d:c);}void main(){ Test t1;t1.setValue(34,6,2);cout << t1.getmin () << endl;}
点击查看答案
问答题
#include < iostream.h >#include < string.h >class Bas{ int m;static int n;public:Bas(int i =0) {n ++; m =i;}void show() { cout << n: <<n << endl; }};Bas::n =0;class Der:public Bas{ public:Der(int i=0):Bas(i) {}};void main(){ Der d(3);d.show();}
点击查看答案
相关试题
写一个程序,定义一个抽象类Shape,由它派...
给出下面程序的输出结果。#include < i...
给出下面程序的输出结果。#include < i...
#include < iostream.h >class AA...
#include < iostream.h >class Sam...