};
}
~A() {if(p) delete p;} A (A &a) { }
void Print()
{cout<<*p<      (2)                           ;   void main() {    A a(10); A b(a); b.Print();  }  2. 以下程序的功能是求2个集合的差:对于数组a中的每个元素,如果该元素不在数组b中,则放到第3个数组c中,程序最后输出数组c中的内容。其中In函数是判断x是否在指定数组中,如果不在数组中则返回1,否则返回0。请完善程序,使该程序的运行结果是:    1    4    5    8    10    11  注:当数组元素的值为0时,不作为数据处理。 #include void main() {              int a[9]={1,2,4,5,7,8,10,11,0}; int b[5]={2,3,7,9,0}; int c[9]={0},*p1=a,*p2=c; while(*p1) {    }        (5)                                      ; while(*p2)   cout<<   (6)                       <<'\\t'; if(     (4)                                     )   *p2++=*p1; p1++; while(*a)   if(      (3)                         )return 0; return 1;   }  cout<<'\\n';  3. 下面是一个继承与派生的程序,基类学生类Student派生一个成绩类。Sort()函数是一个按学生总成绩升序排列的排序程序。要求该程序的输出结果为:  学号:2      姓名:张浩    性别:男    英语:85    C++:67    总成绩:152 学号:1      姓名:李力    性别:男    英语:78    C++:83    总成绩:161 学号:3      姓名:李莉    性别:女    英语:90    C++:82    总成绩:172 请完善程序。  #include class Student{                       //学生类            };  class Grade     (7)                         //成绩类 {        };  void Sort(Grade *g,int n) {  Grade t;       (9)                                    ;  float Eng,Cpp,Sum;  Grade(int i=0,char *n=\ (8)          {Eng=e;Cpp=c;Sum=Eng+Cpp;} void Show()  {cout<<\英语:\总成public:  int Id;  char Name[20]; char Sex[4];  Student(int i=0,char *n=\{    }  void Print()  {cout<<\学号:\姓名:\性别:\ Id=i;  strcpy(Name,n); strcpy(Sex,s);  public:  绩:\      }  int i,j;  for(i=0;i for(j=i+1;j if(         (10)                                             ) {t=g[i];g[i]=g[j];g[j]=t;}  void main() {        }  4. 下面是一个二维坐标类,该程序运行后输出的结果是: (11,21) (10,20) 请完善程序。  #include Point operator++(      (14)                                   ) {   }  void main() {   Point p1(10,20),p2; p2=p1++; Point t=a; a.X++;a.Y++; return t; float X,Y;  Point(       (12)                                   ) {X=x;Y=y;} void Print()  {cout<<'('< friend Point operator++(     (13)                                   ); public:  Grade s[]={Grade(1,\李力\男\张浩\男\  Grade(3,\李莉\女\ Sort(     (11)                            ); for(int i=0;i<3;i++) {   }  s[i].Print(); s[i].Show();    }  p1.Print(); p2.Print();  5. 下面是一个链表处理函数,该函数的功能是把链表中指定数据的结点,移到链表头部成为链表的第一个结点,如果没指定结点,则链表保持不变。请完善该函数。 链表中结点的数据结构如下: struct node{   };  node *Move_one_node(node *head, int num) {node *p1,*p2;  if(head==NULL){     cout<<\链表为空!\\n\  }   if(head->data==num){       cout<<\不需移动!\\n\ else{  p1=head;        p2=head->next;        while( p2->data!=num && p2->next!=NULL ){         p1=p2;       }  p2=     (15)                      ; return(NULL); int data; node *next;       if(p2->data==num){          p1->next=    (16)                     ;         p2->next=head;      }  cout<  }   return(head); }  head=    (17)                        ;         cout<<\移动了一个结点!\\n\     else    
相关推荐: