tags: 作業-進階 大一程設 東華大學 東華大學資管系 基本程式概念 資管經驗分享

HW2-1

Description

請寫一程式,當中包含兩個名稱為Area的function,第一個Area function計算圓的面積並回傳,參數為半徑。第二個Area function計算矩形的面積並回傳,參數為長與寬。在main function中首先讓使用者輸入欲計算圓的面積或是矩形的面積(若使用者輸入1則算圓的面積,若是2則算矩形面積,若輸入其他值則出現一個錯誤訊息並結束程式),接著讓使用者輸入相關的參數並呼叫相對應的Area function,最後將求得的面積輸出於螢幕上。請以一個const變數宣告PI,其值為3.14。

Please design a program that has two Area functions. The first Area function, having a parameter called radius, calculates the area of a circle and returns it. The second Area function, having two parameters called width and length, calculates the area of a rectangle and returns it. The main function first allows the user to enter the area of the circle or rectangle to be calculated. (If the user enters 1, the circle area is calculated, if 2, the rectangle area is calculated, if other values are entered, an error message appears, and the program ends.) Then the user enters the relevant parameters and calls the corresponding Area function, and finally, the resulting area is output on the screen. Please declare PI with a global const variable whose value is 3.14.

sample input and output 1

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

sample input and output 2

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →