作者qazwsxerdfcv ()
看板NTU-Exam
標題[試題] 96上 魏宏宇 計算機程式 期中考
時間Tue Nov 20 23:27:12 2007
課程名稱︰計算機程式
課程性質︰系必修
課程教師︰魏宏宇
開課學院:理學院
開課系所︰物理系
考試日期(年月日)︰96.11.20
考試時限(分鐘):120
是否需發放獎勵金:是
(如未明確表示,則不予發放)
試題 :
Computer Programming Midterm Exam 2007
Duration: 120 minutes
Format: close book
Notice: Please write your C++ with "Proper styles"(程式寫太亂是會被扣分的!)
1.(6%) What are the benefits of separating interface from implementation?
2.(20%) Write the complete function (do NOT write the whole main program)
Write a function check_prime() to check prime numbers.
● Use nested control statement to check prime numbers that are less than
upper bound integer up_b and greater than lower bound integer low_b
●Use for loop first and then do...while
●Inputs of the function are up_b and low_b
●The function return the number of prime numbers
3.(26%) Write C++ statements to do the following tasks:
● You can assume that all variables are declared
● You can assume that we already have 'using' statement
● You should include all required standard library
(a)[5%]Use one-line statement to input variables x,y, and z from keyboard
(b)[5%]Display string named s1 on screen if the length of s1 is even(偶數)
(c)[6%]Compute x/y with 四捨五入 (x,y are integer)
(d)[10%]Use switch and while to help counting if input character 3 or X or
neither.(X and x are considered the same). The input from keyboard will
stop when you enter 0. Assume count3, countX, countOther are all
declared and initialzed to 0.
4.(30%) Define and implement a new class 'ntuGrade'. You should write the
whole C++ program(寫完整的程式)
● You should write your codes with ntuGrade.h, ntuGrade.cpp, and main.cpp.
● These are 2 private data members PhysicsGrade and CalculusGrade
(representing grade in Physics and Calculus)
● Use get and set methods to read and write the value of 2 private data
members
● There is 1 public data member ID, which store the NTU student ID
● You can read or write the value of the public data member directly
● The class should be initialized with the constructor. PhysicsGrade and
CalculusGrade are set to 0 initially for all object.
● When an object is created, the program should automatically initialize the
NTU student ID through constructor.
(a) Create the class interface in a separate file
(b) Create the class implementation in a separate file
(c) Create the main file. The main function does the following things:
■ Create two objects Jay(student ID = 22), and Jolin(student ID = 66)
■ Jay's Physics grade is 80. Jolin's Calculus grade is 95.
■ Display Jay's average grade.
■ Display Jolin's student ID.
5.(18%) Show the output
● If you think there is error, just write 'ERROR' in your answer.
----------------------------------------------------------------
....some codes....
int a=1,b=3,c=6;
float x=3,z=100;
cout << a++ << endl; //(a)
cout << (z *= ++a) << endl; //(b)
cout << (c ++ == 6) << endl; //(c)
x=pow(++x,b);
cout << --x << endl; //(d)
z/=6;
cout << static_cast<int>(z)%5 << endl; //(e)
z>=50? cout << 'a': cout << 'b' << endl; //(f)
....some more codes....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.242.66
推 spiral1226:XD 這麼多字辛苦你了 貪吃鬼(笑) 11/21 00:03
推 ga014528:辛苦了~ 11/21 00:06
推 spiral1226:大家一起歡樂的浮出來了?(笑) 11/21 00:18
推 li042127054:噗噗~~~=ˇ= 11/21 00:40