24.Assignment 2: Picture Processing
Use C++, Java, or similar languages or/and any middleware such as EJB and J2EE
to process a picture with a high resolution (3 Mega Pixels for example). Use
some methodologies to degrade the resolution of the picture to make it quick
er for browsing. Then divide the degraded picture into 9 sectors equally. Cli
ck any of the 9 sectors will result a detailed picture for this sector with t
he same resolution as that of the original picture. This assignment is design
ed for you to demonstrate your ability to handle pictures.
25.用<<,>>,|,&实现一个WORD(2个字节)的高低位交换!!
int main()
{
unsigned short a = 0xABCD;
unsigned short b ;
unsigned short c ,d;
b = (a << 8)&0xff00;
c = (a >> 8)&0x00ff;
d = b | c;
printf(“n%x”,b);
printf(“n%x”,c);
printf(“n%x”,d);
return 0;
}
结果是 CDAB
2俩个字节是16位 前八位为高位 后八位为低位 然后结合
26.要开辟P1,P2,P3,P4内存来做缓冲,大小自定,但这四个缓冲的大小要一样,并且是连续的
27.有一浮点型数组A,用C语言写一函数实现对浮点数组A进行降序排序,并输出结果,要求要
以数组A作为函数的入口.(建议用冒泡排序法)
void BubbleSort(double arr[], int n)
{ int i,j;
int exchange = 1; //交换标志
for(i=1;i<n;i++){ //最多做n-1趟排序
exchange=0; //本趟排序开始前,交换标志应为假
for(j=n-1;j>=i;j–) //对当前无序区R[i..n]自下向上扫描
if(arr[j+1] > arr[j]){//交换记录
arr[0]=arr[j+1]; //R[0]不是哨兵,仅做暂存单元
arr[j+1]=arr[j];
arr[j]=arr[0];
exchange=1; //发生了交换,故将交换标志置为真
}
if(!exchange) //本趟排序未发生交换,提前终止算法
return;
} //endfor(外循环)
}
28.找错:
#include <string.h>
#include <stdio.h>
class Base
{ private:
char * name;
public:
Base(char * className)
{
name = new char[strlen(className)];
strcpy(name, className);
}
~Base()
{delete name;}
char * copyName()
{
char newname [256];
strcpy(newname, name);
return newname;
}
char * getName()
{return name;}
static void print(Base base)
{printf(“name: %sn” , base.name);}
};
class Subclass : public Base
{
public:
Subclass(char * className) : Base(className)
{ }
};
int main()
{
Base * pBase = new Subclass(“test”);
Base::print(*pBase);
printf(“name: %sn”, pBase->getName());
printf(“new name: %sn”, pBase->copyName());
return 0;
}
29.编写一个函数,函数接收一个字符串,是由十六进制数组成的一组字符串,函数的功能是
把接到的这组字符串转换成十进制数字.并将十进制数字返回.
答案:
BOOL HexToDec( LPCTSTR shex,int& idec )
{
int i,mid;
int len = lstrlen( shex );
if( len>8 )
return FALSE;
mid = 0; idec = 0;
for( i=0;i<len;i++ )
{
if( shex[i]>=’0’&&shex[i]<=’9′ )
mid = shex[i]-‘0′;
else if( shex[i]>=’a’&&shex[i]<=’f’ )
mid = shex[i] -‘a’ +10;
else if( shex[i]>=’A’&&shex[i]<=’F’ )
mid = shex[i] -‘A’ +10;
else
return FALSE;
mid <<= ((len-i-1)<<2); // 移位表示变为2的n次方倍
idec =idc+mid;
}
return TRUE;
}
30.编写一个函数将一条字符串分成两部分,将前半部分按ASCII码升序排序,后半部分不
变,(如果字符串是奇数则中间的字符不变,)最后再将前后两部分交换,然后将该字符
串输出,
测试字符串“ADZDDJKJFIEJHGI”