期末

#include<stdio.h>
main()
{
    int x=1,a=0,b=0,c,d;
    switch(x)
    {
    case 0: b++;
    case 1: a++;
    case 2: c=a++;d=b++;
    }
printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
}
class complex
{
    public:
        complex(){real=0;imag=0;}
        complex(double r){real=r;imag=0;}
        complex(double r,double i){real=r;imag=i;}
        friend istream & operator >> (istream &,complex &);
        friend ostream & operator << (ostream &,complex &);
         
    private:
        double real;
        double imag;
};
istream & operator >>(istream &input,complex &c)
{
    cout<<"please input real part and imaginary part of complex number:";
    input>>c.real>>c.imag;
    return input;
}
ostream&operator<<(ostream&output,complex &c)
{
    if(c.imag>0)
                               if(c.real==0)
                                   output<<c.imag<<"i";
                                else output<<c.real<<"+"<<c.imag<<"i";
    else
        if(c.imag<0)
                                if(c.real==0)
                                    output<<"-"<<c.imag<<"i";
                                else output<<c.real<<"-"<<c.imag<<"i";
                  else             output<<c.real;
                 return output;
}
#include "stdio.h"
#include "string.h"
main()
{
    int i;
    char* a[5]={"student","worker","cadre","soldier","peasant"};
    char *p1, *p2;
    p1=p2=a[0];
    for(i=0;i<5;i++)
    {
     if(strcmp(a[i],p1)>0) p1=a[i];
     if(strcmp(a[i],p2)<0) p2=a[i];
    }
    printf("%s %s\n",p1,p2);
}
char*strcpy(char*dest,const char*source)
{
   int i;
   for (i=0;source[i];i++) dest[i]=source[i];
   dest[i]='\0';
   return dest;
}

 

posted @ 2013-07-09 22:58  herizai  阅读(230)  评论(0编辑  收藏  举报