程序的结果为______。
include"iostream.h"
template<typename T>
T total(T*data)
{
Ts=0;
while(*data)
{
S+=*data++;
}
return S;
}
int main()
{int x[]={2,4,6,8,0,12,14,16,18};
cout<<total(x);
retum 0;
cout<<endl;}
第1题:
下列程序的输出结果是【 】
include<iOStream>
using namespace std;
template <typename T>
T total (T*datA)
{
T s=0;
while(*datA)
{
s+=*data++;
}
return s;
}
int main()
{
int x[]={2,4,6,8,0,12,14,16,18};
cout<<total(x)<<end1;
return 0;
}
第2题:
有如下程序:
include<iostream>
using namespace std;
template<typename T>
T total(T * data) {
T s=0;
While(* data)s+ = *data + +;
return s;
}
int main(){
int x[]:{2,4,6,8, 10, 12, 14, 16, 18};
cout<<total(x);
第3题:
有以下程序 #include<iostream.h> void ss(char*s,char t) { while(*s) { if(*S==t)*s=t-'a'+'A'; s++;} } void main( ) { char strl[100]="abcddfefdbd",c='d': ss(strl,c) ;cout<<strl;} 程序运行后的输出结果是
A.ABCDDEfEBD
B.abcDDfefDbD
C.abcAAfefALbA
D.Abcddfefdbd
第4题:
阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。
【说明】设单链表的结点类和链表类的定义如下,链表不带有表头结点。请填空:
include<iostream.h>
include<assert.h>
template<class T>class List;
template<class T>class ListNOde{
friend (1);
private:
T data;
ListNode<T> *link;
public:
ListNode():link(NULL)()
ListNOde(const T& item,ListNOde<T>*next=NULL)
:data(item),link(next){}
};
template<class T>class List{
private:
ListNode<T>*first;
void createList(T A[],int n,int i,ListNOde<T>*&p);
void printList(ListNOde<T>*p);
public:
List();
~List();
friend ostream& operator<<(ostream& ost,List<T>&L);
friend istream& operator>>(istream& ist,List<T>&L);
};
template<class T>
istream& operator>>(istream& ist,List<T>&1){
int i,n; ist>>n;
T A[n];
for(i=0;i<n;i++) (2);
createList(A,n,0,first);
}
template<class T>
void List<T>::createList(TA[],int n,int i,ListNOde<T>*& p){
//私有函数:递归调用建立单链表
if(i==n)p=NULL;
else{
p=new ListNode<T>(A[i]);
assert(p !=NULL);
createList((3));
}
}
template<class T>
ostream& operator<<(ostream& ost,List<T>& L){
(4);
}
template<class T>
void List<T>::printList(ostream& ost,ListNode<T>*p){
if(p!=NULL){
ost<<p->data;
(5);
}
}
第5题:
有以下程序
#include <stdio.h>
void fun(char *t,char *s)
{ while(*t!=0) t++;
while((*t++=*s++)!=0);
}
main( )
{ char ss[10]="acc",aa[10]="bbxxyy";
fun(ss,aa); printf("%s,%s\n",ss,aa);
}
程序的运行结果是
A.accxyy,bbxxyy
B.acc,bbxxyy
C.accxxyy,bbxxyy
D.accbbxxyy,bbxxyy