北电——又一份没有用到的笔试题2

 
发信人: FenceKing (小强), 信区: Job
标 题: 下午北电比试题(2)——M-Tree
发信站: 武汉白云黄鹤站 (2005 年10月21日16:22:03 星期五)
 
大致如下:
要求读入形如a(b,c(d,e,f),g(h,i))的字符串,构建3叉树,然后遍历输出原字符串
a
/ | /
b c g
/ | / | /
d e f h i
=======================
我的5空:
(1) s->subTree[k]=makeTree();
(2) *str==","
(3) k<3 && *str!=")"
(4) t->subTree[0]!=NULL
(5) i<2 && t->subTree[i+1]!=NULL
 
 
虚函数
// hello.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
class Base
{
protected:
       int int_i;
protected:
       double dbl_x;
 
public:
       Base() { int_i = 1, dbl_x = 1.5; };
 
       virtual void foo(int i) {
              cout << "Base::i= " << i << endl;
       };
 
       virtual void foo(double x) {
              cout << "Base::x= " << x << endl;
       };
 
       virtual void foo() {
              cout << "Base::int_i= " << int_i
                     << ", Base::dbl_x= " << dbl_x << endl;
       };
};
 
class Derived: public Base
{
protected:
       int int_i;
 
public:
       Derived() {
              int_i = 2;
              dbl_x = 2.5;
       }
 
       void foo(int i) {
              cout << "Derived::i= " << i << endl;
       }
 
       void foo() {
              cout << "Derived::int_i= " << int_i
                     << ", Derived::dbl_x= " << dbl_x << endl;
       }
 
};
 
class Derived2: public Derived
{
protected:
       int dbl_x;
 
public:
       Derived2() {
              int_i = 3;
              dbl_x = 3.5;
       }
 
       void foo(double x) {
              cout << "Derived2::x= " << x << endl;
       }
 
       void foo() {
              cout << "Derived2::int_i= " << int_i
                     << ", Derived2::dbl_x= " << dbl_x << endl;
       }
};
 
void main() {
       Derived d;
       Derived2 d2;
       Base b, * p;
       p = &d2; p->foo(6); p->foo(6.5); p->foo();
       p = &d; p->foo(7); p->foo(7.5); p->foo();
       p = &b; p->foo(8); p->foo(8.5); p->foo();
 
       return;
}
Derived ::i= 6
Derived2::x= 6.5
Derived2::int_i= 3, Derived2::dbl_x= 3
Derived::i= 7
Base::x= 7.5
Derived::int_i= 2, Derived::dbl_x= 2.5
Base::i= 8
Base::x= 8.5
Base::int_i= 1, Base::dbl_x= 1.5
Press any key to continue
 
程序改错
大概这样:
main()
{
int score[3][3] = {{89,89,89},{90,91,92},{78,78,79}};
search(*score, 2);
return 0;
}
void search(int* p, int n)
{
printf("...%d:/n",n);
for(i=0;i<3;i++)
printf("%6.2f",*(p+n-1)+i);//这个记不清了,这里肯定是要改正的,欢迎补充
return;
}
 
现在我认为的错误:
printscore(score,2);//2 改成 3 ?;
i 没有声明
printf("%6.2f", *(*(p+n-1)+i));
整型?浮点?
还有函数定义在 main ()之前,前面没有声明,应该 debug 不通,的确是个错误,可惜我也
没有发现,找到 3 个就没有再找了
 
发信人: hubert (努力学好弧圈), 信区: Job
标 题: re: 北电笔试题型(OOP题)
发信站: 武汉白云黄鹤站 (2005 年10月21日12:17:04 星期五), 站内信件
 
4。说是一个银行用户算利息的程序,主要是:
class person{...};//用户还是什么的;
algrith1();//算法函数
algrith2();//同上
algrith3();//同上
 
class personcounter
{
public:
personcounter(const person&, const person&);
computeinsterest() {algith1()};
...
}
class depoitcounter:public personcounter
{
public:
personcounter(const person&, const person&);
computeinsterest() {algith2()};
...
}
class ?????counter:public personcounter
{
public:
personcounter(const person&, const person&);
computeinsterest() {algith3()};
...
}
 
main()
{
personcounter * a[100];
for(int i= 0; i<100; i++)
a[i]->computeinterest();
 
...
}
 
我认为主要错误应该是:
1 。算利息在 personcounter 中应该是 virtual ,这样才可以多态,根据对象的不同算利息。
2 。算法函数应该是对应类的友元,不然应该对类的成员没有操作能力(至少私有成员是如
此,共有的我还要看看书先)
别的东西是程序里面一些只有 declare 而没有 definition 的,应该不是考察中的错误
 
呵呵,几天前北电笔试了一把,汗!
一共4题,1个小时完成:
1.英译汉  
  做完花了15分钟,英语菜就一个字!
2.中序遍历一个二叉树,不能用递归
地球上的人都知道要压栈,但平时根本就是在用递归解决。当时现场比划,花了近30分钟才勉强写到试卷上,汗颜!如果后序更麻烦。
思路:所有节点两次进栈,
先将根节点进栈,然后进入 while 循环,循环条件为栈不为空。
循环内:退栈, tag 自增 1
tag 1 ,则再将这个节点进栈,并将其左节点进栈
Tag 2 ,则访问这个节点,将其右节点进栈
 
同理后序遍历
先将根节点进栈,然后进入 while 循环,循环条件为栈不为空。
循环内:退栈, tag 自增 1
tag 1 ,则再将这个节点进栈,并将其左节点进栈
Tag 2 ,则再将这个节点进栈,并将其右节点进栈
Tag 3 ,则访问这个节点
 
3.双向冒泡程序改错--3个错误
  看来看去,只发现了2个错误。
4.回答程序所完成的功能-共5问
  题目有3页纸,都还没来的急看完,更别说写字了,收卷!
 
试卷一共13页纸,出来晕倒一大片!真不知道他在考什么。
 
发信人: jamsir (风间苍月), 信区: Job
标 题: 北电05年笔试试题(大致题目)
发信站: 逸仙时空 Yat-sen Channel (Thu Oct 20 17:00:02 2005), 站内信件
 
 
2005年10月20日下午的北电笔试题目(地点在中山大学的冼为坚堂),分为四大部分?
 
 
一. 一大段中文要求译成英文。内容大概是北电为英国电信提供了一个IP语音电话的
     解决方案,然后就是一大堆带来的好处什么的。
 
二. 一道编程题目,确定一个输入的字符串含有什么字符和各个字符的个数。
 
三. 改错题,有两道。
     1. 找出下面程序的错误:
        #include<iostream.h>
        class A
        {
            private:
               int aa;
            public:
               setA(int a) { aa = a; };
               showA() { cout<<"aa "<<aa; };
        };
 
        class B:private A
        {
            private:
                int bb;
 
            public:
                setB( int b ) { bb = b; };
                showB() { cout<<"bb "<<bb; };
        };
 
        void main()
        {
            B obj;
            obj.setA(3);
            obj.showA();
            obj.setB(5);
            obj.showB();
            return;
        };
            obj.setA(3);
            obj.showA(); 出错,不能访问
这两个函数已经成为 B 的私有函数
 
    2.下面是一个复数类,程序想输出4+3i,请问哪里有错?
        #include<iostream.h>
        class complex
        {
            private:
                int realPart,virtualPart;
 
            public:
                complex(int r, int v){ realPart = r; virtualPart = v; };
                ~complex();
                complex& operator++(){
                    realPart++;
                    return *this;
                };
                void print(){ cout<<realPart<<'+'<<virtualPart<<'i'; };
        };
 
        void main()
        {
            complex c(2,3);
            ++++c;
            c.print();
            return;
        };
正确
class complex
{
private:
    int realPart,virtualPart;
 
public:
    complex(int r, int v){ realPart = r; virtualPart = v; }
    ~complex(){}
    complex& operator++(){
       realPart++;
       return *this;
    }
    complex operator++(int){
       complex tmp = *this;
       ++realPart;
       return tmp;
    }
    void print(){ cout<<realPart<<'+'<<virtualPart<<'i'<<endl; }
};
 
void main()
{
    complex c(2,3);
    c++++;
    c.print();
    complex b(2,3);
    ++++b;
    b.print();
    return;
}
3+3i
4+3i
四 逻辑题,有两道,都是要求写出输出。
    1.
        #include<iostream.h>
        #include<string.h>
        void main()
        {
            char* array[5] = { "student", "worker", "p...",
                               "c...", "p..." };        //忘了的省略掉了
            char *p1,*p2;
            int i;
 
            p1 = p2 = array[0];
            for( i = 0; i < 5; i++ ){
                if( strcmp( p1,array[i] ) > 0 ) p1 = array[i];
                if( strcmp( p2,array[i] ) < 0 ) p2 = array[i];
            };
            cout<<p1<<" "<<p2<<endl;
 
            return;
        };
c…worker
    2.
        #include<iostream.h>
        class A
        {
           private:
                int a;
 
           public:
                A(int aa) { a = aa; };
                ~A()    { cout<<"Destructor A!"<<a<<endl; };
        };
 
        class B:public A
        {
          private:
                int b;
 
          public:
                B( int aa = 0, int bb = 0 ):A(aa) { b = bb; };
                ~B(){ cout<<"Destructor B!"<<b<<endl; };
        };
 
        void main()
        {
            B obj1(5), obj2( 6, 7 );
            return;
        };
Destructor B!7
Destructor A!6
Destructor B!0
Destructor A!5
上面所写可能会有一些错漏,特此声明。
 
2. 一个国王热衷于杀奴隶,有37个奴隶围成一圈,国王从1开始数,数到5就杀掉一个,
然后再从1开始数,直到只剩下一个奴隶为止,要你打印出最后一个奴隶的编号。
程序结构:
奴隶结构体:编号,是否被杀死标志,下一个奴隶的指针;
初始化奴隶函数(就是编号编为1到37,开始都是活的,循环链表的某一奴隶,程序执行的
时候给的是编号为1的奴隶的指针);
杀奴隶函数(便表一个元素的指针,执行数数杀奴隶操作,将所有要杀掉的奴隶的杀死标
志为杀死状态);
打印幸存者函数(给一个元素指针,打印出来幸存者);
主函数(创建37个奴隶,初始化、杀奴隶、打印幸存者)
 
循环链表问题,很 easy
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值