1. 結構POINT定義如下:
typedef struct tagPOINT {
int x;
int y;
} POINT
用變量var給出下面的定義
例:一個POINT 變量
答案:POINT var;
a. 一個指向POINT的指針;
b. 一個指向指針的指針,它指向的指針是指向一個POINT;
c. 一個有16個POINT的數組;
d. 一個有16個指針的數組,每個指針指向一個POINT;
e. 一個指向數組的指針,該數組有16個POINT
2. 實作函數IsEven,用于判斷一個給定的整數是否為偶數
3. 寫一個函數,實作對給定的字元串(字元串裡面包括:英文字母,數字,符号)的處理。經過處理後的字元串其内容按字母,數字,符号的順序存放。函數聲明如下:
void ParseString(char* pstr);
要求:
a. 不能改函數聲明;
b. 不改變字母數字等在字元串中原有的出現順序;
c. 直接使用pstr所值指緩沖區,不允許另開緩沖區。
例如:給定的字元串為:A,2.d?3!e4r87we79...
輸出結果為:Aderwe2348779,.?!...
4. 寫一個函數,對給定整數的二進制表示進行描述
如:給定整數131,其二進制表示為10000011,要求函數輸出以下結果:
1: 2
0: 5
1: 1
表示從最低位開始,包含2個1,5個0,1個1。
參考上一題,确定本函數的名字,入口出口及傳回值,并實作本函數
5. 定義一個student類,成員變量包含學生姓名、出生年月日。要求重載“>”運算符,實作以出生年月日為依據比較兩個學生年齡大小的功能。
6. 有如下3個API:
HANDLE FindFirst(char* lpFileName);//用于查找給定目錄下是否有指定檔案。若無則傳回0,若有則傳回一個句柄。例如:FindFirst("D:\\data\\*.txt")
BOOL FindNext(HANDLE hFindFile); //繼續查找該目錄下是否有其他比對檔案。
BOOL FindClose(HANDLE hFindFile);//用于結束查找。
利用上述API實作函數NumOfPicFiles,找出給定目錄下有多少個JPG及BMP檔案(不考慮子目錄)。
int NumOfPicFiles(char*lpszfolder);
Lpszfolder表示指定目錄。
傳回值表示找到的檔案個數。
//此試題是金山在我學校招實習學生出的。
個人做的
2.vc6.0做的
#include<iostream>
using namespace std;
bool IsEven(int i);
int main()
{
int n;
cout<<"偶數傳回1,其他傳回0"<<endl;
cout<<"input a int number:";
cin>>n;
cout<<IsEven(n)<<endl;
}
bool IsEven(int i)
if(i>0)
{
if(i%2==0)
return true;
else
return false;
}
else
cout<<"你輸入的為負數"<<endl;
return false;
3.//我用vs2005做的
bool checkzm(char zm); //判斷是不是字母
bool checksz(char sz); //判斷是否為數字
void out(char* pstr);
cout<<"請輸入字元串"<<endl;
char str[50];
cin>>str;
/*int n=(sizeof(str))/(sizeof(str[0]));*/
cout<<"排序前"<<endl;
out(str);
ParseString(str);
cout<<"排序後"<<endl;
/*for(int i=0;i<n;i++)
cout<<str[i];
cout<<endl<<"排序後"<<endl;
ParseString(str);
for(int i=0;i<n;i++)
cout<<endl;*/
void ParseString(char* pstr)
int zmnum=0; //字母個數,也可以看作是已經排好序的字元個數
int n=0; //跟蹤掃描的字元個數
char*pstr1=pstr;
for(;*pstr1;pstr1++) //掃描字元串,第一個for循環完成字母靠前
{
n++;
if(checkzm(*pstr1))
{
zmnum++;
char current=*pstr1; //擷取目前的字母
for(int i=n-2;i>=zmnum-1;i--) //找到一個字母,就把它移動到前面去
{
*(pstr+i+1)=*(pstr+i); //向後移動其他字元
}
*(pstr+zmnum-1)=current;
}
}
pstr1=pstr;
n=zmnum; //不再從第1個開始掃描了,字母已經放好了,從字母後面的字元開始掃描字元串
for(pstr1=pstr1+zmnum;*pstr1;pstr1++) //第二個for循環完成數字在字母後面
if(checksz(*pstr1))
{
zmnum++; //在這裡不在指字母了,指排好序的字元個數
char current=*pstr1;
for(int i=n-2;i>=zmnum-1;i--)
*(pstr+i+1)=*(pstr+i); //向後移動其他字元
}
bool checkzm(char zm) //判斷是不是字母
if((zm>='A' && zm<='z') || (zm>='a' && zm<='z'))
return true;
bool checksz(char sz) //判斷是否為數字
if(sz>='0' && sz<='9')
void out(char* pstr)
while(*pstr !='\0')
cout<<*pstr;
pstr++;
cout<<endl;
4.//vs2005做的
void ParseBinary(int);
ParseBinary(n);
void ParseBinary(int n)
int num=1; //計數
int current; //目前位
int pre; //目前的前一位
for(int i=0;i<=7;i++)
if(n & (1 << i))
{
if(i==0)
{
pre=current=1;
}
current=1;
// cout<<"1 ";
}
else if(!(n & (1<<i)))
{
pre=current=0;
current=0;
// cout<<"0 ";
if(i!=0)
if(pre==current)
num++;
else
cout<<pre<<" : "<<num<<endl;
num=1;
pre=current;
cout<<pre<<" : "<<num<<endl;
5.
//頭檔案 stu.h
#ifndef STU_H
#define STU_H
#include<string>
class student
private:
string name;
int year;
int month;
int day;
public:
student(string name1,int year1,int month1,int day1)
name=name1;
year=year1;
month=month1;
day=day1;
void operator > (const student&student2)
if(year>=student2.year) //比較年
if(year>student2.year)
cout<<name<<",你年齡小于 "<<student2.name<<endl;
else //出生年相同
if(month>=student2.month) //比較月
{
if(month>student2.month)
{
cout<<name<<",你年齡小于 "<<student2.name<<endl;
}
else //出生月相同
if(day>=student2.day)
{
if(day>student2.day)
{
cout<<name<<",你年齡小于 "<<student2.name<<endl;
}
else //同一天出生,年齡相等
cout<<name<<",你年齡等于 "<<student2.name<<endl;
}
}
cout<<name<<",你年齡大于 "<<student2.name<<endl;
};
#endif
//.cpp檔案,student.cpp
#include "stu.h"
student stu1("stu1",1985,6,7);
student stu2("stu2",1986,6,5);
stu1>stu2;
本文轉自夏雪冬日部落格園部落格,原文連結:http://www.cnblogs.com/heyonggang/archive/2012/12/12/2814494.html,如需轉載請自行聯系原作者