c笔试Word文件下载.docx
《c笔试Word文件下载.docx》由会员分享,可在线阅读,更多相关《c笔试Word文件下载.docx(15页珍藏版)》请在冰点文库上搜索。
有一个文件(名为a.txt)如下,每行有4项,第一项是他们的名次,写一个c程序,将五个人的名字打印出来.并按名次排序后将5行数据仍然保存到a.txt中.使文件按名次排列每行.
2,07010188,0711,李镇豪,
1,07010154,0421,陈亦良,
3,07010194,0312,凌瑞松,
4,07010209,0351,罗安祥,
5,07010237,0961,黄世传,
8.写一个函数,判断一个unsignedchar字符有几位是1.
写一个函数判断计算机的字节存储顺序是升序(little-endian)还是降序(big-endian).
9.微软的笔试题.
ImplementastringclassinC++withbasicfunctionalitylikecomparison,concatenation,inputandoutput.Pleasealsoprovidesometestcasesandusingscenarios(samplecodeofusingthisclass).
PleasedonotuseMFC,STLandotherlibrariesinyourimplementation.
10.有个数组a[100]存放了100个数,这100个数取自1-99,且只有两个相同的数,剩下的98个数不同,写一个搜索算法找出相同的那个数的值.(注意空间效率时间效率尽可能要低).
这十道题还是能够看出自己的水平如何的.如果你能不假思索地做出这10道题,估计去国外大公司是没有问题了,呵呵.
答案我在整理中,以后陆续发布.................
下面有些题也不错,可以参考.
1.下面的代码输出是什么,为什么?
voidfoo(void)
{
unsignedinta=6;
intb=-20;
(a+b>
6)?
puts("
>
6"
):
<
=6"
);
//puts为打印函数
}
输出>
6.
就是考察隐式转换.int型变量转化成unsignedint, b成了正数.
2.b)运行下面的函数会有什么结果?
charstring[10],str1[10];
inti;
for(i=0;
10;
str1[i]='
a'
;
strcpy(string,str1);
printf("
%s"
string);
首先搞清strcpy函数的实现方法,
char*strcpy(char*strDest,constchar*strSrc)
{
if((strDest == NULL) || (strSrc == NULL))
throw"
Invalidargument(s)"
char*strDestCopy = strDest;
while((*strDest++ = *strSrc++) !
= '
\0'
returnstrDestCopy;
}
由于str1末尾没有'
\0’结束标志,所以strcpy不知道拷贝到何时结束.
printf函数,对于输出char*类型,顺序打印字符串中的字符直到遇到空字符('\0')或已打印了由精度指定的字符数为止.
下面是微软的两道笔试题....
3.ImplementastringclassinC++withbasicfunctionalitylikecomparison,concatenation,inputandoutput.Pleasealsoprovidesometestcasesandusingscenarios(samplecodeofusingthisclass).
我的实现方案如下,这道题真地对c++的主要特性都进行了较好地考察.
String.h:
#ifndefSTRING_H
#defineSTRING_H
#include<
iostream>
usingnamespacestd;
classString{
public:
String();
String(intn,charc);
String(constchar*source);
String(constString&
s);
//String&
operator=(char*s);
String&
operator=(constString&
~String();
char&
operator[](inti){returna[i];
constchar&
operator[](inti)const{returna[i];
}//对常量的索引.
operator+=(constString&
intlength();
friendistream&
operator>
(istream&
is,String&
//搞清为什么将>
设置为友元函数的原因.
//friendbooloperator<
(constString&
left,constString&
right);
friendbooloperator>
left,constString&
//下面三个运算符都没必要设成友元函数,这里是为了简单.
friendbooloperator==(constString&
friendbooloperator!
=(constString&
private:
char*a;
intsize;
};
#endif
String.cpp:
#include"
String.h"
cstring>
cstdlib>
String:
:
String(){
a=newchar[1];
a[0]='
size=0;
String(intn,charc){
a=newchar[n+1];
memset(a,c,n);
a[n]='
size=n;
String(constchar*source){
if(source==NULL){
a=newchar[1];
a[0]='
size=0;
else
{
size=strlen(source);
a=newchar[size+1];
strcpy(a,source);
String(constString&
s){
size=strlen(s.a);
//可以访问私有变量.
//if(a==NULL)
strcpy(a,s.a);
String&
String:
operator=(constString&
if(this==&
s)
return*this;
delete[]a;
size=strlen(s.a);
~String(){
//
operator+=(constString&
intj=strlen(a);
intsize=j+strlen(s.a);
char*tmp=newchar[size+1];
strcpy(tmp,a);
strcpy(tmp+j,s.a);
a=tmp;
intString:
length(){
returnstrlen(a);
main.cpp:
booloperator==(constString&
right)
inta=strcmp(left.a,right.a);
if(a==0)
returntrue;
returnfalse;
booloperator!
=(constString&
return
!
(left==right);
ostream&
operator<
(ostream&
os,String&
intlength=s.length();
for(inti=0;
i<
length;
//os<
s.a[i];
这么不行,私有变量.
os<
s[i];
returnos;
Stringoperator+(constString&
a,constString&
b){
Stringtemp;
temp=a;
temp+=b;
returntemp;
booloperator<
(constString&
right){
intj=0;
while((left[j]!
='
)&
&
(right[j]!
)){
if(left[j]<
right[j])
if(left[j]==right[j]){
j++;
continue;
if((left[j]=='
))
booloperator>
inta=strcmp(left.a,right.a);
if(a>
0)
istream&
delete[]s.a;
s.a=newchar[20];
intm=20;
charc;
inti=0;
while(is.get(c)&
isspace(c));
if(is){
do
{s.a[i]=c;
i++;
/*if(i>
=20){
cout<
"
Inputtoomuchcharacters!
"
<
endl;
exit(-1);
}*/
if(i==m-1){
s.a[i]='
char*b=newchar[m];
strcpy(b,s.a);
m=m*2;
s.a=newchar[m];
strcpy(s.a,b);
delete[]b;
isspace(c));
//如果读到空白,将其放回.
if(is)
is.unget();
s.size=i;
s.a[i]='
returnis;
intmain(){
Stringa="
abcd"
Stringb="
www"
//Stringc(6,b);
这么写不对.
Stringc(6,'
l'
Stringd;
Stringe=a;
//abcd
Stringf;
cin>
f;
//需要输入...
Stringg;
g=a+b;
//abcdwww
if(a<
b)
cout<
a<
b"
a>
=b"
if(e==a)
e==a"
e!
=a"
b+=a;
a<
b<
c<
d<
e<
f<
g<
g[0]<
return0;
4.Implementasingle-directionlinkedlistsortingalgorithm.Pleasefirstdefinethedatastructureoflinkedlistandthenimplementthesortingalgorithm.
5.编写一个函数,返回两个字符串的最大公串!
例如,“adbccadebbca”和“edabccadece”,返回“ccade”
联想笔试题
1.设计函数intatoi(char*s)。
intatoi(constchar*nptr);
函数说明
atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('
)才结束转换,并将结果返回。
返回值返回转换后的整型数。
stdio.h>
ctype.h>
intmyAtoi(constchar*s){
intresult=0;
intflag=1;
while(isspace(s[i]))
i++;
if(s[i]=='
-'
){
flag=-1;
+'
)
while(s[i]!
if((s[i]>
'
9'
)||(s[i]<
0'
break;
intj=s[i]-'
result=10*result+j;
result=result*flag;
returnresult;
char*a="
-1234def"
char*b="
+1234"
inti=myAtoi(a);
intj=myAtoi(b);
%d\n"
i);
%d"
j);
2.inti=(j=4,k=8,l=16,m=32);
printf(“%d”,i);
输出是多少?
3.解释局部变量、全局变量和静态变量的含义。
4.解释堆和栈的区别。
5.论述含参数的宏与函数的优缺点。
普天C++笔试题
1.实现双向链表删除一个节点P,在节点P后插入一个节点,写出这两个函数。
2.写一个函数,将其中的\t都转换成4个空格。
3.Windows程序的入口是哪里?
写出Windows消息机制的流程。
4.如何定义和实现一个类的成员函数为回调函数?
5.C++里面是不是所有的动作都是main()引起的?
如果不是,请举例。
6.C++里面如何声明constvoidf(void)函数为C程序中的库函数?
7.下列哪两个是等同的
intb;
Aconstint*a=&
b;
Bconst*inta=&
Cconstint*consta=&
Dintconst*consta=&
8.内联函数在编译时是否做参数类型检查?
voidg(base&
b.play;
}
voidmain(){
sons;
g(s);
return;
华为笔试题
1.请你分别画出OSI的七层网络结构图和TCP/IP的五层结构图。
2.请你详细地解释一下IP协议的定义,在哪个层上面?
主要有什么作用?
TCP与UDP呢?
3.请问交换机和路由器各自的实现原理是什么?
分别在哪个层次上面实现的?
4.请问C++的类和C里面的struct有什么区别?
5.请讲一讲析构函数和虚函数的用法和作用。
6.全局变量和局部变量有什么区别?
是怎么实现的?
操作系统和编译器是怎么知道的?
7.8086是多少位的系统?
在数据总线上是怎么实现的?
Sony笔试题
1.完成下列程序
*
*.*.
*..*..*..
*...*...*...*...
*....*....*....*....*....
*.....*.....*.....*.....*.....*.....
*......*......*......*......*......*......*......
*.......*.......*.......*.......*.......*.......*.......*.......
#include<
#defineN8
intmain()
{
inti;
intj;
intk;
---------------------------------------------------------
||
return0;
2.完成程序,实现对数组的降序排序
voidsort();
intarray[]={45,56,76,234,1,34,23,2,3};
//数字任//意给出
sort();
voidsort()
____________________________________
|-----------------------------------------------------|
3.费波那其数列,1,1,2,3,5……编写程序求第十项。
可以用递归,也可以用其他方法,但要说明你选择的理由