当前位置:文档之家› 北航软件学院研究生一级工程实践2004届考试试题绝密

北航软件学院研究生一级工程实践2004届考试试题绝密

北航软件学院研究生一级工程实践2004届考试试题绝密
北航软件学院研究生一级工程实践2004届考试试题绝密

软件学院2004级第一学期《一级实践》期末试题学号姓名分数

注:所有答案必须写在答题纸上,否则无效。

一、简答题(共50分)

1.简述进程和线程的异同点。(5分)

2.列举三种进程间的通信方式,并分别说明其应用场合。(5分)

3.简述设置C++虚拟继承的目的是什么?(3分)

4.简述C/C++堆和堆栈两种内存使用方式的异同。(4分)

5.简述传输层和应用层协议的主要功能,请各举两例并比较TCP和UDP

的异同。(5分)

6.简述new和malloc的异同。(3分)

7.简述进程(线程)间的同步和互斥的作用,请列举三种Winodws的同步

和互斥对象,并分别说明其应用场合。(5分)

8.简述你所知道的const的各种用法。(5分)

9.简述异质链表的特点,给出一种实现方法(包括节点增删操作函数)并

简要说明你采用这种实现方法的原因。(10分)

10.简述采用socket通信时服务器端和客户端的主要工作过程。(5分)

二、读程序写结果,并简述产生各输出结果的原因(每小题4分,共20分)1.#include

int main(int argc, char* argv[])

{

char str1[] = "abc";

char str2[] = "abc";

const char str3[] = "abc";

const char str4[] = "abc";

const char* str5 = "abc"; //指向常量的指针

const char* str6 = "abc";

cout << ( str1==str2 ) << endl;

cout << ( str3==str4 ) << endl;

cout << ( str5==str6 ) << endl; 比较的是地址

}

2. #include

class Point

{

public:

Point(double i, double j) { x=i; y=j; }

virtual double Area() const { return x*y; }

private:

double x, y;

};

class Rectangle:public Point

{

public:

Rectangle(double i, double j, double k, double l);

virtual double Area() const { return w*h; }

private:

double w, h;

};

Rectangle::Rectangle(double i, double j, double k, double l):Point(i, j) {

w=k; h=l;

}

void fun(Point &s)

{

cout<

}

void main()

{

Rectangle rec(1.0, 2.0, 3.0, 4.0);

Point *pt;

fun(rec);

pt = (Point *)&rec;

fun(*pt);

}

3. #include

class Test;

void fun1(Test t);

Test fun2();

class Test

{

public:

Test(int n=1) {val=n; cout<<"Con."<

Test(const Test& t) {val=t.val; cout<<"Copy con."<

Test& operator = (Test& t)

{

val=t.val;

cout<<"Assignment."<

return *this;

}

private:

int val;

};

void main()

{

Test t1(1);

Test t2=t1;

Test t3;

t3=t1;

fun1(t2);

t3=fun2();

}

void fun1(Test t){}

Test fun2()

{

Test t;

return t;

}

4. # include

struct Point {

int *x, *y;

};

void move ( Point &q )

{

--*q.x;

++*q.y;

}

int main()

{

Point p;

int a = 5, b = -12, t;

p.x = &a;

p.y = &b;

move( p );

t = a;

a = b++;

b = t++;

cout << “p.x = “ << *p.x << endl;

cout << “p.y = “ << *p.y << endl;

return 0;

}

5. #include

#include

class string

{

public:

string(char *s);

string(string &s1);

string(int size=80);

~string() { delete sptr; }

int getlen() { return length; }

void print() { cout<

char *sptr;

int length;

};

string::string(char *s)

{

length = strlen(s);

sptr = new char[length+1];

strcpy(sptr, s);

}

string::string(string &s1)

{

length = s1.length;

sptr = new char[length+1];

strcpy(sptr, s1.sptr);

}

string::string(int size)

{

length = size;

sptr = new char[length+1];

*sptr = '\0';

}

void main()

{

string str1("This is an Orange.");

str1.print();

cout<

char *s1 = "That is a program.";

string str2(s1);

string str3(str2);

str3.print();

cout<

}

三、查错并说明错误原因,无需改正(每小题6分,共12分)

1. int& fun(int *i)

{

int j = 2 * i;

return j;

}

int main()

{

int j = 10;

int &n ;

n = j;

n = fun(&j);

cout << “The value of n is: “ << n << endl;

}

2.class K

{

public:

virtual K(){};

virtual K( int i){};

virtual ~K();

void m( const K& obj ){ this = &obj; };

static void s() { this -> count = 0; };

private:

static int count;

};

四、编程题:(共18分)

1. 根据下面的要求一步步写出正确的C++语句,注意:各个步骤之间是有先后顺序的。(每小题0.5分,共5分)

(1)定义两个整型变量value1,value2;

(2)定义一个指向整型变量的指针pValue,将该指针初始化为指向value1;

(3)将指针pValue改为指向变量value2;

(4)通过pValue指针来间接地改变变量value2的值为20;

(5)申请三个连续的整数空间,并将申请到空间的首地址赋值给pValue;

(6)用cout输出所申请到的首地址值;

(7)给第二个地址空间赋值10;

(8)用cout输出第二个地址空间的地址;

(9)释放所申请到的三个整数空间;

(10)将指针pValue设置为不指向任何地址空间;

2. 中序遍历二叉树(5分)

struct Node

{

int Data;

Node *Left, *Right;

};

void Through(Node *Root)

{

}

3. 实现二分法查找(8分)

int DicFind( int *Array, int Count, int Value )

{

}

五、意见和建议(本题不记分!)

本课程中你有没有迟到或缺课,如果有,原因是什么?如果你对“一级实践”的教学有意见和建议,请告诉我们(不要写赞扬的语句)。

相关主题
文本预览
相关文档 最新文档