您的位置:首页 > 职场人生

*电商and*公司面试

2016-03-16 09:40 267 查看
概述

题目

总结

一.概述

概述:总结一下近几日面试题目(与以前公司面试非重复题目),不断反思,才能稳中求进

二.题目

c/c++部分:

1.虚函数性质

class Parent{
public:
virtual void eat(){...}
}
class Child:public Parent{
public:
virtual void eat(){...}
}


①虚函数可以被重载也可以不被重载

②Child new_child;

Parent *p=&new_child;

p->eat();

当重载时:会覆盖父类的虚函数,调用子类的eat函数;非重载时:调用父类的函数

③C++的虚基类  在派生类继承基类时,加上一个virtual关键词则为虚拟基类继承,如:

  class derive:virtual public base
  {
  };


作用:虚基类主要解决多重继承问题

  classB
  {
  };
  class D1:virtual public B
  {
  };
  class D2:virtual publicB
  {
  };
  class C:public D1,public D2


④当Parent虚函数有多个时,其大小也只为4个字节

⑤类的虚继承多了一个4个字节指针的偏移量,目的是:虚继承利用一个“虚基类偏移量表指针”来使得虚基类即使被重复继承也只会出现一次

参考链接:

http://blog.chinaunix.net/uid-26851094-id-3327323.html

http://www.jizhuomi.com/software/374.html

2.字符串拷贝、赋值

给定字符串的头:

class MyString{
public:
MyString(char*p=NULL);
MyString(const char&str);
~Mystring();
private:
char*data;
}


拷贝构造函数:

Mystring::Mystring(const char*p)
{
if(!p)
{
data=new char[1];
data='\0';
}
else
{
data=new char[strlen(p)+1];
strcpy(data,p);
}
}


析构函数:

Mystring:~Mystring()

{

delete []data;

}

赋值运算符:

初级:

Mystring::Mystring &operator=(const char&p)
{
if(this==&p)
return this;
delete [] data;
data=NULL:
data=new char[strlen(p)+1];
strcpy(data,p);
return this;
}


高级:

Mystring::Mystring &operator=(const char&p)
{
if(this==&p)
return this;
Mystring temp(p);
char*q=p.data;
p.data=temp.data;
temp.data=q;
return this;
}


参考:《剑指offer》

算法部分:

3.有两个数组,将其数组放到指定位置,使其差值最小



提供两种思路:[标准答案未找到,欢迎大家讨论提供!]

①先进性排序(9,8,8,7,6,6,5,4,3,1);设置两个指针first,second(指向两个数组的首地址),sum1=first+num[i],sum2=second+nums[i];判断条件:

if(sum1>sum2)sum1=first+num[i];else sum2=second+num[i];将数值填入数组的顺序为依次相加



②求出平均值,进行数值修正

平均值为:28.5。分别找两个数组当中的数值进行修正,令其接近均值



shell部分:

4.写一段代码,找出文件夹中含有某个关键字的文件

参考链接:

http://wukui127.blog.51cto.com/2866802/1092364/

代码如下:

#!/bin/bash
#find files contains a keyword
#write by xiaojing.zhao
#2012.12.14

echo -e "\nThis is a script to find all the files in a specified path contains a keyword!"

echo -e "\nPlease input a keyword:"
read key
if [ "$key" == "" ]; then
echo -e "keyword can not be null!\n"
exit 0
fi
keyword=$key

echo -e "\nPlease input your specified path:"
read dir
#判断该路径是否存在,并且是目录,不存在输出提示
test ! -d $dir && echo -e "The $dir is not exist in your system.\n\n" && exit 0

echo -e "\n---------------You find files are:---------------\n"

#keyword=JAVA_OPTS
#dir=/jboss/jboss-eap-4.3/jboss-as/

#统计文件个数
file_count=0
#递归查看所有目录,即最深路径,不显示空行
file_list=`ls -R $dir 2> /dev/null | grep -v '^$'`
for file_name in $file_list
do
#临时文件变量temp,将ls -R即file_list中的文件名中所有匹配:后接一个或多个任意字符(.代表任意字符,*代表0个或多个$代表行尾结束符)全局替换为无
#简单的说,就是把file_name变量中的匹配:的行,将:后内容替换为空
temp=`echo $file_name | sed 's/:.*$//g'`
#如果临时文件变量temp是一个目录,而非文件,就将该目录赋值给cur_dir变量
if [ "$file_name" != "$temp" ]; then
cur_dir=$temp
#echo "-"$cur_dir #临时显示,调试用
else
#用file命令查看文件真身是否为ASCII text类型
file_type=`file $cur_dir/$file_name | grep "text"`
if [ "$file_type" != "" ]; then
temp=`grep $keyword $cur_dir/$file_name 2> /dev/null`
#echo "--"$cur_dir/$file_name #临时显示,调试用
if [ "$temp" != "" ]; then
echo $cur_dir/$file_name
#文件个数加1
let file_count++
fi
fi
fi
done

echo -e "\n-------------------------------------------------"
echo -e "\n\nFiles Total: $file_count"
echo -e "\nFind Finished!\n"


操作系统:

5.进程与线程,写一段相关调用代码片

三.总结

I.题目考察的范围包含了语言基础,算法,操作系统,shell等还是很广泛的,要注意从这几个角度系统的复习.II.让我们一同努力,明天会更好!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: