首页 > 试题广场 >

下列程序中缺少若干条语句,每条下划线只填一条语句

[问答题]
下列程序中缺少若干条语句,每条下划线只填一条语句

1 、下面是类fraction定义,其中重载的运算符<<以分数形式输出结果,例如将三分之二输出为2/3

class fraction{

int den;   // 分子

int num;   // 分母

friend ostream& operator<< (ostream&, fraction&);

};

ostream& operator <<(ostream& os, fraction &fr)

{

os<<fr.den<< 1 <<endl;

return 2 ;

}

3 、链表结点的结构如下,完成使链表逆置函数 reverse head 为链表头结点

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


struct node* reverse(struct node *head)

{
struct node *p,*temp1,*temp2;
if(head==NULL 5 )

return head;
p=head->next;

head->next=NULL;
while(p !=NULL)
{
temp1=head;

6 ;

temp2=p;

p=p->next;

7 ; //

}
return head; // 返回逆置后的头结点
}

2 、函数模板,用于计算两个向量的和。

# include <iostream.h>

template<class T>

T* f(T* a, T* b,int n)

{

T* c=_ 3 _ __ ;

for(int i=0;i<n;i++)

c i = 4 ;

return c;

}

void main()

{  int a[5]={1,2,3,4,5}, b[5]={1,5,2,5};

int * p=f(a,b,5);

}

1、 1 ”/ ”<< fr.num 2 os

2、 3 new T[n] 4 a[i]+b[i]

3、 5 ||head->next==NULL 6 head=p 7 temp2->next=temp1 head->next=temp1

发表于 2017-05-14 23:07:39 回复(0)