1.a.POINT *p;
b.POINT **p;
c.POINT p[16];
d.POINT **p;
e.POINT *p = new POINT[16];
2.
#include
<
iostream
>
using namespace std;
// 判断是否为偶数的函数
// 是偶数,则返回1,否则返回0
int isEven( int n)
... {
/**//*if(n%2==0)
return 1;
else
return 0;
*/
//采用位运算,速度很快~!
if(n&1)
return 0;
else
return 1;
}
void main()
... {
int i,j;
cin>>i;
j = isEven(i);
if(j)
cout<<i<<" 是偶数"<<endl;
else
cout<<i<<" 是奇数"<<endl;
getchar();
}
using namespace std;
// 判断是否为偶数的函数
// 是偶数,则返回1,否则返回0
int isEven( int n)
... {
/**//*if(n%2==0)
return 1;
else
return 0;
*/
//采用位运算,速度很快~!
if(n&1)
return 0;
else
return 1;
}
void main()
... {
int i,j;
cin>>i;
j = isEven(i);
if(j)
cout<<i<<" 是偶数"<<endl;
else
cout<<i<<" 是奇数"<<endl;
getchar();
}
3.
#include
<
iostream
>
#include < string >
using namespace std;
/**/ /*
*思路:遍历字符串得到数字的第一个出现的位置firstNum
* 遍历字符串然后将字母出现在firstNum之后的插入到firstNum之前
* 遍历字符串得到数字的最后一个出现的位置lastNum
* 倒序遍历字符串然后将字符出现在lastNum之前的插入到lastNum之后
*/
int strlength( char * pstr)
... {
int k =0 ;
while(true)
...{
//遇到终结符则退出
if(pstr[k] == '
#include < string >
using namespace std;
/**/ /*
*思路:遍历字符串得到数字的第一个出现的位置firstNum
* 遍历字符串然后将字母出现在firstNum之后的插入到firstNum之前
* 遍历字符串得到数字的最后一个出现的位置lastNum
* 倒序遍历字符串然后将字符出现在lastNum之前的插入到lastNum之后
*/
int strlength( char * pstr)
... {
int k =0 ;
while(true)
...{
//遇到终结符则退出
if(pstr[k] == '
4.
#include
<
iostream
>
using namespace std;
void parseBary( int n)
... {
int i=0;
int a[100];
while(true)
...{
if(n==0)
break;
a[i] = n%2;
n = n/2;
i++;
}
int temp[10];
int count[10];
for(int k=0;k<10;k++)
...{
count[k]=1;
}
//计数器
int x = 0;
for(int j=0;j<i;j++)
...{
if(a[j]==a[j+1])
...{
count[x]++;
}
else
...{
temp[x] = a[j];
x++;
}
}
for(int z=0;z<x;z++)
...{
cout<<temp[z]<<": "<<count[z]<<endl;
}
}
void main()
... {
cout<<"请输入您要验证的十进制数字:";
int a;
cin>>a;
cout<<"结果如下:"<<endl;
parseBary(a);
}
using namespace std;
void parseBary( int n)
... {
int i=0;
int a[100];
while(true)
...{
if(n==0)
break;
a[i] = n%2;
n = n/2;
i++;
}
int temp[10];
int count[10];
for(int k=0;k<10;k++)
...{
count[k]=1;
}
//计数器
int x = 0;
for(int j=0;j<i;j++)
...{
if(a[j]==a[j+1])
...{
count[x]++;
}
else
...{
temp[x] = a[j];
x++;
}
}
for(int z=0;z<x;z++)
...{
cout<<temp[z]<<": "<<count[z]<<endl;
}
}
void main()
... {
cout<<"请输入您要验证的十进制数字:";
int a;
cin>>a;
cout<<"结果如下:"<<endl;
parseBary(a);
}
5.
#include
<
iostream
>
using namespace std;
class Student
... {
private:
char name[20];
int year;
int month;
int day;
public:
Student();
Student(char *n,int y,int m,int d);
Student(Student &s);
~Student();
Student &operator > (Student &s);
void display()
...{
cout<<"姓名:"<<name<<endl
<<"生日:"<<day<<"/"<<month<<"/"<<year<<endl;
}
} ;
Student::Student()
... {
strcpy(name,"zcg");
this->year = 1984;
this->month = 8;
this->day = 21;
}
Student::Student(Student & s)
... {
strcpy(name,s.name);
year = s.year;
month = s.month;
day = s.day;
}
Student::Student( char * n, int y, int m, int d)
... {
strcpy(name,n);
this->year = y;
this->month = m;
this->day = d;
}
Student:: ~ Student()
... {
}
Student & Student:: operator > (Student & s)
... {
if(this->year>s.year)
return s;
else if(this->year<s.year)
return *this;
else if(this->month>s.month)
return s;
else if(this->month<s.month)
return *this;
else if(this->day>s.day)
return s;
else
return *this;
}
void main()
... {
Student s1("test1",1985,2,20);
Student s2("test2",1985,3,8);
Student s = s1>s2;
cout<<"年龄大的是: "<<endl;
s.display();
getchar();
}
using namespace std;
class Student
... {
private:
char name[20];
int year;
int month;
int day;
public:
Student();
Student(char *n,int y,int m,int d);
Student(Student &s);
~Student();
Student &operator > (Student &s);
void display()
...{
cout<<"姓名:"<<name<<endl
<<"生日:"<<day<<"/"<<month<<"/"<<year<<endl;
}
} ;
Student::Student()
... {
strcpy(name,"zcg");
this->year = 1984;
this->month = 8;
this->day = 21;
}
Student::Student(Student & s)
... {
strcpy(name,s.name);
year = s.year;
month = s.month;
day = s.day;
}
Student::Student( char * n, int y, int m, int d)
... {
strcpy(name,n);
this->year = y;
this->month = m;
this->day = d;
}
Student:: ~ Student()
... {
}
Student & Student:: operator > (Student & s)
... {
if(this->year>s.year)
return s;
else if(this->year<s.year)
return *this;
else if(this->month>s.month)
return s;
else if(this->month<s.month)
return *this;
else if(this->day>s.day)
return s;
else
return *this;
}
void main()
... {
Student s1("test1",1985,2,20);
Student s2("test2",1985,3,8);
Student s = s1>s2;
cout<<"年龄大的是: "<<endl;
s.display();
getchar();
}
6.
#include
<
....
>
.....
.....
/**/ /*
*HANDLE FindFirst(char* lpFileName);//用于查找给定目录下是否有指定文件。若无则返回0,若有则返回一个句柄。例如:FindFirst("D:/data/*.txt")
*BOOL FindNext(HANDLE hFindFile); //继续查找该目录下是否有其他匹配文件。
*BOOL FindClose(HANDLE hFindFile);//用于结束查找。
*/
int NumOfPicFiles( char * lpszfolder);
main()
... {
int jpg = NumOfPicFiles("D:/*.JPG");
int bmp = NumOfPicFiles("D:/*.BMP");
cout<<"一共有 "<<jpg<<" 个JPG文件"<<endl;
cout<<"一共有 "<<bmp<<" 个BMP文件"<<endl;
}
int NumOfPicFiles( char * lpszfolder)
... {
int count = 0;
HANDLE handle = FindFirst(lpszfolder);
if(handle!=0)
return count;
else if(FindFirst(handle))
...{
count++;
}
FindClose(handle);
}
.....
.....
/**/ /*
*HANDLE FindFirst(char* lpFileName);//用于查找给定目录下是否有指定文件。若无则返回0,若有则返回一个句柄。例如:FindFirst("D:/data/*.txt")
*BOOL FindNext(HANDLE hFindFile); //继续查找该目录下是否有其他匹配文件。
*BOOL FindClose(HANDLE hFindFile);//用于结束查找。
*/
int NumOfPicFiles( char * lpszfolder);
main()
... {
int jpg = NumOfPicFiles("D:/*.JPG");
int bmp = NumOfPicFiles("D:/*.BMP");
cout<<"一共有 "<<jpg<<" 个JPG文件"<<endl;
cout<<"一共有 "<<bmp<<" 个BMP文件"<<endl;
}
int NumOfPicFiles( char * lpszfolder)
... {
int count = 0;
HANDLE handle = FindFirst(lpszfolder);
if(handle!=0)
return count;
else if(FindFirst(handle))
...{
count++;
}
FindClose(handle);
}