精華區beta NTU-Exam 關於我們 聯絡資訊
課程名稱︰計算機程式 課程性質︰大一必修 課程教師︰魏宏宇 開課學院:理學院 開課系所︰物理系 考試時間︰95.11.21 是否需發放獎勵金:是 (如未明確表示,則不予發放) 試題 : 1.(8%)When you write a C++ program with OOP,what do the following files do,and how are they related? (a)header file (b)source file (c)object file (d)executable file 2.(20%)Write C++ statements to do the following tasks: ●You should include all required stantard library ●You can assume that all variables declared ●You can assume that we already have 'using' statement (a)Input a whole sentence from keyboard and store the input into a string named s1. (b)Cut the 8 characters(3rd~10th)of string s1 and store them in a string named s2. (c)Display all positive odd number(奇數)between 100~200 in descending order (遞減). (d)Without using nested structure,check whether 10<x<30 is true.(寫一行程式碼 就可以了) 3.(25%)Define and implement a new class 'Triangle'.You should write the whole C++ program(寫完整的程式) ●You should 'seperate interface from implementation'. ●The 'Triangle'class has 3 data members 'side1','side2','side3'.These data members represent the 3 sides(邊) of the triangle.The data members should be protected from outside access. ●The 'Triangle'class has a member functions 'checkSides' that check if the 3 sides of the triangle are valid(檢查是否兩邊和大於第三邊).The member functions 'checkSides' will display 'A valid triangle!' on the screen,if it's a valid triangle.If it's not valid,display 'Error!!!'. ●The class should be initialized with the constructor ●When an object is created,the program should automatically check the validity of the triangle sides. (a)In main function,declare a Triangle object named 't1' with initial value [3.1 4.2 5] (b)Create the class interface in a seperate file (c)Create the class implementation in a seperate file 4.(18%)Programming with loops (a)Display the following sequence '10 9 8 7 6 5 4 3 2 1 0' using 'for' loop (b)Modify (a) with 'break' and 'continue' statements to diplay '10 7 6 5 4 3 2' (c)Display '10 7 6 5 4 3 2' using 'do...while' statement and the sentinel- controlled technique(Hint:use two sentinel/flag/signal values for displaying and looping) 5.(15%)Assume x and y are declared as integer.Compute and display the following results on the screen. (a)x/y with 無條件進入 (b)x/y with 四捨五入 (c)x/y with 小數點(實數的除法) 6.(14%)What are the output of the following program when y value in Line 5 is changed ●If you think there is error,just write 'ERROR' in your answer. (a)y=5 (b)y=4 (c)y=3 (d)y=2 (e)y=1 (f)y=0 (g)y=-1 ---------------------------------------------------------------------------- ......some codes...... int x,y,z; y=5; //Line5 z=2; x=y; switch(x) { z*=2; case 5: y++; ++x; cout<<"Cout1:"<<x<<endl; case 4: y=(x==4) cout<<"Cout2:"<<y<<endl; break; case 3: case 2: cout<<"Cout3:"<<z<<endl; break; case 1: cout<<"Cout4:"<<++x<<endl; break; case 0; break; default: cout<<"Cout5:"<<z<<endl; break; } ......some more codes...... ---------------------------------------------------------------------------- -- ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ ★☆ http://www.wretch.cc/album/treva ☆★ ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.229.12.233