作者jamestin112 (刚丁)
看板NTU-Exam
标题[试题] 98下 魏宏宇 程式设计 期末考
时间Fri Jun 25 21:45:20 2010
课程名称︰程式设计
课程性质︰必修
课程教师︰魏宏宇
开课学院:管理学院
开课系所︰工管系
考试日期(年月日)︰98/06/23
考试时限(分钟):150分钟
是否需发放奖励金:是
(如未明确表示,则不予发放)
试题 :
Programming Design Final Exam Spring 2010
Duration: 2:20~4:50
Format: closed book(Total points=105)
Notice: Please write your C++ with "proper styles"
(程式写太乱是会被扣分的!)
1. Write C++ statements to do the following tasks: (Assume we
already have using statement) (15%)
(A)Declare a double array "x" with 3 elements. Initialize the
array as [1.1 2.2 3.3].
(B)Use for loop, and/or break, continue commands to display 1,2,
4,5,6(skip3) on the screen.
(C)Enumerate the 7 days of a week(Mon=1,Tue=2,Wed=3,Thur=4,Fri=5
Sat=6,Sun=7).
2.Write the functions.(Assume we already have using statement.And
libraries are included) (40%)
(A)Create a function called "Function1" that inputs a character
array "s1", copies the first half of "s1" into character array
"s2", and copies the second half of "s1" into character array
"s3". The function also has an interger inputs "s_size", which
is the size of "s1".
(B)Create a function called "Function2" that inputs an integer
"SCORE" and returns a character. If "SCORE" >=80, return A. If
80>SCORE>=70, return B. If 70>SCORE>=60, return C. Otherwise,
return F. You must use "switch" in this problem.
(C)Create a function called "Function3" that inputs an integer N.
The function returns N if 10<N<15 or 20<N<25. Otherwise the
function returns 0. You should not use nested if (Hint: use
logical operators).
(D)Create a function called "Function4" that returns an even integer
number Y. In the function, the program prompts the user to input
an even number. If the input is valid, the program will ask the
user to input until it has a valid input. You must use "do while"
in this problem.
(E)Create a fuction called "Function5" that returns a 10 by 15 2-D
array(10乘15的二维阵列). Fill in the array with non-duplicated
random numbers between 600~1000.
3.(24%)Selection Sort
(A)Implement a function "swap(double*,double*) that swaps two data
elements.(8%)
(B)Use "recursive" method to implement selection sorting with function
"selectionSort(int[],int)" and "swap(double*,double*). (Hint: the
selection sort in the textbook is NOT recursive, it's iterative).
With these 2 functions, write a complete program to sort [34,56,4
10,77] from the smallest to the largest.(16%)
4.(16%)Show the output
If you think there is a syntax error, just write 'ERROR' as your answer.
int x = 5;
inline void F1(void)
{
int x = 20;
x=x+1;
cout<<"(F1)x= "<<x<<endl;
}
inline void F2(void)
{
static int x = 25;
x=x+1;
cout<<"(F3)x="<<x<<endl;
}
inline void F3(void)
{
x=x+2;
cout<<"(F3)x="<<X<<endl;
}
int main()
{
int y = 10;
int&x=y;
cout<<"(A) x="<<x<<",y"<<y<<endl;
F1();
F2();
F3();
cout<<"(B) x="<<x<<",y="<<y<<endl;
{
int x=15;
cout<<"(C) x="<<x<<",y="<<y<<endl;
}
cout<<"(D) x="<<x<<",y="<<y<<endl;
F1();
F2();
F3();
cout<<"(E) x="<<x<<",y="<<y<<endl;
return 0;
}
5.(10%)Show the output
if you think there is a syntax error, just write 'ERROR' as your
answer. Assume the address of x is 600000. The size to store an address
is 4 bytes. The size to store an integer is 4 bytes.
int x[]={1,3,5,7};
int *y=x;
int i=1;
cout<<"\n(a1)="<<&x[3];
cout<<"\n(a2)="<<y;
cout<<"\n(a3)="<<*x+2;
cout<<"\n(a4)="<<=(y+1);
*(y++)=2;
x[2]=4;
x[3]=0;
cout<<"\n(a5)="<<x[++i];
cout<<"\n(a6)="<<*(x+1);
cout<<"\n(a7)="<<x;
cout<<"\n(a8)="<<*(*(&y));
cout<<"\n(a9)="<<*(&(*y));
cout<<"\n(a10)="<<++y;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.45.45.246
※ 编辑: jamestin112 来自: 114.45.45.246 (06/25 21:46)
※ 编辑: jamestin112 来自: 114.45.45.246 (06/25 21:47)
1F:推 wrane :原PO卷哥 06/26 00:22