您的位置:首页 > 其它

重庆理工大学软件工程创新实验室卓越工程师班 招收新生笔试题 开卷

2012-05-16 14:39 302 查看
重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 1 页 共 6 页 2012年5月11日



试卷说明:①本试卷的专门为理工大学软件工程专业2011级中自愿申请加入软件工程创新实验室的学生而设;②本试卷

为课外开卷测试,本试卷要求独立完成,不许讨论性完成;③考试时间为10天,交卷时间为5月21日中午12:30-1:00,

交卷地点为第一实验楼B306;④试卷请同学们自行打印,或在答卷纸张上写清答题的对应题号,不需要抄写原题,答卷纸张请

学生自己选用A4尺寸的纸张,建议手写,并在每张试卷中留下姓名、学号;⑤本试卷涉及38专业一年级的相关课程内容,

侧重于用计算机语言解决实际的问题,C语言和J***A语言各50%;⑥本考试提倡诚实考试,拒绝抄袭,对疑点问题在后

续答辩中,指导老师将现场质询,如果试卷评阅小组确认属于作弊、抄袭等,都将“成双成对”的取消抄袭或被抄袭试卷的

学生申请资格,所以,请管好自己的试卷,以防“误伤”。



一、C语言部分(共50分)

1.用变量a给出下面的定义(4分)

a) 一个整型数

b)一个指向整型数的指针

c)一个指向指针的的指针,它指向的指针是指向一个整型数

d)一个有10个整型数的数组

e) 一个有10个指针的数组,该指针是指向一个整型数的。

f) 一个指向有10个整型数数组的指针

g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数

h) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数

2.全局变量和局部变量在内存中是否有区别?如果有,是什么区别? (2分)

3.某32位系统下,程序如下,请计算sizeof 的值(5分)

char str[] = “http://www.ibegroup.com/”;

char *p = str ;

int n = 10;

请计算

sizeof (str ) = ?

sizeof ( p ) = ?

sizeof ( n ) = ?

void Foo ( char str[100])

{

sizeof( str ) = ?

}

void *p = malloc( 100 );

sizeof ( p ) = ?

4.回答下面的问题

(1)头文件中的 ifndef/define/endif 干什么用?(2分)

(2)#include <filename.h>和 #include “filename.h” 有什么区别? (2分)

5.编写strcat函数(5分)

不调用字符串库函数,请编写函数strcat。原型是:char *strcat (char *strDest, const char *strSrc);

其中strDest 是目的字符串,strSrc 是源字符串,把strSrc的内容连接到strDest。

6.请写出下列代码的输出内容 (5分)

#include<stdio.h>

int main()

{

int a,b,c,d;

a=10;

b=a++;

printf("b,c,d:%d, %d,%d",b,c,d);

重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 2 页 共 6 页 2012年5月11日



c=++a;

d=10*a++;

printf("b,c,d:%d, %d,%d",b,c,d);

return 0;

}

7.请找出下面代码中的错误,并说明为什么。(说明:以下代码是把一个字符串倒序,如“abcd”倒序后

变为“dcba”) (5分)

#include"string.h"

int main()

{

char*src="hello,world";

char* dest=NULL;

int len=strlen(src);

dest=(char*)malloc(len);

char* d=dest;

char* s=src[len];

while(len--!=0)

d++=s--;

printf("%s",dest);

return 0;

}

8.写出程序运行结果并解释(5分)

void main()

{

int s;

for(s=10000;s != -100;s++)

{

printf("%d,", s);

}

}

9.写出程序运行结果并解释(5分)

int sum(int a)

{

auto int c=0;

static int b=3;

c+=1;

b+=2;

return(a+b+c);

}

void main()

{

int I;

int a=2;

for(I=0;I<5;I++)

{

printf("%d,", sum(a));

}

}

10.写出程序运行结果并解释(5分)

void main()

{

int s=1;

int x[5];

int a=2;

int sum;

重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 3 页 共 6 页 2012年5月11日



for(s=0;s<=5;s++)

{

x[s] = 2*s;

}

sum = a+s;

for(s=0;s<5;s++)

{

sum += x[s];

}

printf("%d", sum);

}

11.编写程序计算





100

1

!

k

k

k

x

。(5分)

二、J***A语言部分(共50分)

12.在java中数组是一个对象或一个基本类型值吗?数组可以包含对象类型和基本类型的元素吗?描述数

组元素的默认值。(5分)

13.设计一个名为Location的类,定位二维数组中的最大值及其位置。这个类包括公共的数据域row、

column和maxValue,二位数组中的最大值及其下标用int型的row和column以及double型的maxValue

存储。(5分)

编写下面的方法,返回一个二位数组中最大值的位置。

public static Location locateLargest(double[][] a)

返回值是一个Location的实例。编写一个测试程序,提示用户输入一个二位数组,然后显示这个数组中

的最大元素。

14.描述传递基本类型参数和传递引用类型参数的区别。(5分)

给出下面程序的输出:



public class Test {

public static void main(String[] args) {

Count myCount = new Count();

int times = 0;



for (int i = 0; i < 100; i++)

increment(myCount, times);



System.out.println("count is " + myCount.count);

System.out.println("times is " + times);

}



public static void increment(Count c, int times) {

c.count++;

times++;

}

}





public class Count {

public int count;



Count(int c) {

count = c;

}



Count() {

count = 1;

}

}



15.如何将一个char值、一个字符数组或一个数值转换为一个字符串?(5分)

16.使用下面的语句创建File对象时,错在哪里?

new File("d:\book\test.txt");

写一个文本编辑器,可以实现文件的创建、浏览、字体设置,保存等功能,要求每个功能都可以用

右键实现。(5分)

17.分析下面程序是否有错,若有错请分析错误原因。(2分)

public class Something {

void doSomething () {

private String s = "";

重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 4 页 共 6 页 2012年5月11日



int l = s.length();

}

}

18.分析下面程序是否有错,若有错请分析错误原因。(2分)

abstract class Something {

private abstract String doSomething ();

}

19.分析下面程序是否有错,若有错请分析错误原因。(2分)

class Something {

final int i;

public void doSomething() {

System.out.println("i = " + i);

}

}

20. (6分)An online store allows customers to customize office tables, based on the following input fields: table

length in metre, width in metre, type of wood and number of drawers. The price of a table is computed as

follows:

• If the surface area is more than 2 square metres, add $20 for every additional square metre of surface area.

• Add $300 if the table is made of teak wood.

• Add $325 if the table is made of oak wood.

• Add $50 for every drawer, up to a maximum of 4 drawers.

(1)Write the OfficeTable class. The OfficeTable class should have the attributes table length (float type),

table width( float type), type of wood(String type) and number of drawers (int type), a constructor to initialize all

the attributes and a method calculatePrice to calculate and return the price of the table.

(2)Write a driver program to test the class. The test program will create an OfficeTable object made of

teak, with a dimension of 2.5 x 3.5 metre and 3 drawers, (all the information will be entered into program

through the keyboard), then call the calculatePrice method of OfficeTable object to calculate the total price and

print out the price of this table.

21.设计3个类,分别是学生类Student,本科本类Undergraduate,研究生类Postgraduate,其中Student

类是抽象类,它包含一些基本的学生信息如姓名、所学课程、成绩等,而Postgraduate和Undergraduate

都是Student的子类,它们之间的主要区别是计算课程成绩等级的方法有所不同,研究生的标准比本科生

的标准高一些,具体如下:

本科生标准 研究生标准

80-100 优秀 90-100 优秀

70-80 良好 80-90 良好

60-70 一般 70-80 一般

50-60 及格 60-70 及格

50以下 不及格 60以下 不及格

假设现在既有研究生也有本科生,请统计出成绩等级并显示出来。(8分)

22.请完善类TestSerializable中writeBooks方法的代码。(5分)

import java.io.*;

//keyboard 类

class Keyboard{

static BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in));

public static int getInteger(){

try{

重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 5 页 共 6 页 2012年5月11日



return(Integer.valueOf(inputStream.readLine().trim()).intValue());

}catch(Exception e){

e.printStackTrace();

return 0;

}

}

public static String getString(){

try{

return(inputStream.readLine());

}catch(IOException e){

return "0";

}

}

}

class Book implements Serializable{

transient int id;

String bookName;

double price;

public static int nextId = 1;

public Book(){

this("", 0.0);

this.id = nextId++;

}

public Book(String bookName, double price){

this.bookName = bookName;

this.price = price;

}

public void writeToFile(FileOutputStream out) throws IOException{

ObjectOutputStream oos = new ObjectOutputStream(out);

oos.writeObject(this);

oos.flush();

}

public void readFromFile(FileInputStream in)

throws IOException, ClassNotFoundException{

ObjectInputStream ois = new ObjectInputStream(in);

Book temp = (Book)ois.readObject();

this.bookName = new String(temp.bookName);

this.price = temp.price;

}

public String toString(){

return id + "\t" + bookName + "\t" +price;

}

}

public class TestSerializable{

public static void main(String[] args) {

TestSerializable test = new TestSerializable();

test.writeBooks(2, "d:\\hello.dat");

test.readBooks("d:\\hello.dat");

}

private void writeBooks(int number, String fileName){

//请完善该方法代码

}//writeBooks方法结束

private void readBooks(String fileName){

try{

FileInputStream in = new FileInputStream(fileName);

try{

重庆理工大学软件工程创新实验室卓越工程师班

招收新生笔试题(开卷)

班级: 学号: 姓名:

第 6 页 共 6 页 2012年5月11日



System.out.println("书籍列表");

System.out.println("ID" + "\t" + "书名" + "\t" + "价格");

while(true){

Book book = new Book();

book.readFromFile(in);

System.out.println(book);

}

}catch(EOFException eof){

}finally {

in.close();

}//内部try/catch/finally 结束

}catch(FileNotFoundException e){

System.out.println("文件" + fileName + "找不到" + e.getMessage() + "\n");

}catch(ClassNotFoundException e){

System.out.println("找不到Book类" + e.getMessage() + "\n");

}catch(IOException iox){

System.out.println("IO错误" + iox.getMessage() + "\n");

}//外部try/catch 块结束

}//readRecords()方法结束

}//类TestSerializable结束
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: