# 東華資管程設實習題
week3 2024/09/25
---
[Medium-程式碼詳細解釋](https://medium.com/@11035032_19538/week3-程設實習題-db3ffaa37cef "Medium 程式碼解釋")
***Question.***
```
- 評估一間公司的存貨流動性可以參考「存貨周轉率」與「存貨周轉天數」這兩個財務指標。請撰寫一支完整的程式,程式當中先後讓使用者輸入一家公司的營業成本、期初存貨與期末存貨(假設皆為帶小數點的數字,單位為萬元),之後再輸出該公司的存貨周轉率與存貨周轉天數 。(讓使用者輸入數值之前請先印出提示字串)
- 存貨周轉率 = 營業成本 ÷ 平均存貨
- 平均存貨 = (期初存貨+期末存貨) ÷ 2
- 存貨周轉天數 = 365天 ÷ 存貨周轉率
```
***Output.***
```
參考執行畫面如下:(粗體字為使用者輸入的)
Please input the cost of sales, beginning inventory, ending inventory.
100
20
5
The inventory turnover is 8
The days sales in inventory is 45.625
```
***My code.***
```cpp=
#include <iostream>
using namespace std;
int main()
{
float cost_of_sales, beginning_inventory, ending_inventory, inventory_turnover, average, days_sales_in_inventory;
cout << "Please input the cost of sales, beginning inventory, ending inventory." << endl;
cin >> cost_of_sales >> beginning_inventory >> ending_inventory;
average = (beginning_inventory + ending_inventory) / 2;
inventory_turnover = cost_of_sales / average;
days_sales_in_inventory = 365 / inventory_turnover;
cout << "The inventory turnover is " << inventory_turnover << "\n";
cout << "The days sales in inventory is " << days_sales_in_inventory;
return 0;
}
```
***Reference answer.***
```cpp=
#include <iostream>
using namespace std;
int main()
{
double CostOfSales, BeginningInventory, EndingInventory;
double inventory_turnover, days_sales_in_inventory;
cout << "Please input the cost of sales, beginning inventory, ending inventory.\n";
cin >> CostOfSales >> BeginningInventory >> EndingInventory;
double AverageValueOfInventory = (BeginningInventory + EndingInventory) / 2;
inventory_turnover = CostOfSales / AverageValueOfInventory;
days_sales_in_inventory = 365 / inventory_turnover;
cout << "The inventory turnover is " << inventory_turnover << endl;
cout << "The days sales in inventory is " << days_sales_in_inventory << endl;
return 0;
}
```
week5 2024/10/09
---
[Medium-程式碼詳細解釋](https://medium.com/@11035032_19538/week5-程設實習題-d86451ef5acb "Medium 程式碼解釋")
***Question.1***
```
吉尼係數(Gini index)為衡量年所得分配公平程度的一個指標。以下圖為例,實際所得分配曲線(紅線)和所得分配絕對平等線(綠線)之間的面積為A,實際所得分配曲線(紅線)和所得分配絕對不平等線(藍
線)之間的面積為B,吉尼係數的算法為。A/(A+B)請撰寫一程式讓使用者輸入A與B的值Lorenz Curve接著計算吉尼係數後輸出於螢幕上。(A與B皆為實數,讓使用者輸入數值之前請先印出提示字串)
```
***Output.***
```
參考執行畫面如下:(粗體字為使用者輸入的)
Please input the areas A and B:
21.4
50.5
The Gini Index is 0.297636
```
***My code.***
```cpp=
#include <iostream>
using namespace std;
int main()
{
double A, B, Gini_index;
cout << "Please input the areas A and B:" << "\n";
cin >> A >> B;
Gini_index = A / (A + B);
cout << "The Gini index is " << Gini_index << "\n";
return 0;
}
```
<br/>
***
<br/>
***Question.2***
```
- 請撰寫一支完整的程式,程式當中先後讓使用者輸入身高、體重(假設皆為帶小數點的數字),之後再輸出其使用者的BMI值。(讓使用者輸入數值之前請先印出提示字串,請輸出至小數點後兩位。)
- BMI = weight / (height * height)
- 假設使用者輸入的身高單位為公尺,體重單位為公斤。
- 不用對輸出格式做限制。
```
***Output.***
```
參考執行畫面如下:(粗體字為使用者輸入的)
How tall are you?
1.81
How much do you weigh?
80.0
Your BMI is 24.42
```
***My code.***
```cpp=
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double height, weight, BMI;
cout << "How tall are you?" << "\n";
cin >> height;
cout << "How much do you weight?" << "\n";
cin >> weight;
BMI = weight / (height * height);
cout << fixed << setprecision(2);
cout << "Your BMI is " << BMI << "\n";
return 0;
}
```
<br/>
***
<br/>
***Question.3***
```
承上題,在輸出使用者的BMI值之後,若使用者的BMI小於18,就輸出 “You are slim.”若是大於或等於18,就輸出 “You are fit.”。
```
***Output.***
```
參考執行畫面如下:(粗體字為使用者輸入的)
How tall are you?
1.81
How much do you weigh?
80.0
Your BMI is 24.42
You are fit.
```
***My code.***
```cpp=
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double height, weight, BMI;
cout << "How tall are you?" << "\n";
cin >> height;
cout << "How much do you weight?" << "\n";
cin >> weight;
BMI = weight / (height * height);
cout << fixed << setprecision(2);
cout << "Your BMI is " << BMI << "\n";
if (BMI < 18)
{
cout << "You are slim.\n";
}
else if (BMI > 18 || BMI == 18)
{
cout << "You are fit.\n";
}
else
{
cout << "error\n";
}
return 0;
}
```
week6 2024/10/16
---
***Question.1***
```
- 請撰寫一支完整的程式,程式當中先後讓使用者輸入身高、體重( 假設皆為帶小數點的數字),之後再輸出其使用者的BMI值在輸出使用者的BMI值之後,若使用者的BMI介於18與24之間(包含18與24),就輸出 “You are fit.”,不然就輸出 “You are good.”。(讓使用者輸入數值之前請先印出提示字串,請輸出至小數點後兩位。)
- BMI = weight / (height * height)
- 假設使用者輸入的身高單位為公尺,體重單位為公斤。
```
***Output.***
```
參考執行畫面如下:(粗體字為使用者輸入的)
How tall are you?
1.81
How much do you weigh?
80.0
Your BMI is 22.89
You are fit. 。
```
***My code.***
```cpp=
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double height, weight, BMI;
cout << "How tall are you?" << "\n";
cin >> height;
cout << "How much do you weight?" << "\n";
cin >> weight;
BMI = weight / (height * height);
cout << fixed << setprecision(2);
cout << "Your BMI is " << BMI << "\n";
if (BMI < 18)
{
cout << "You are slim.\n";
}
else if (BMI >= 18 && BMI <= 24)
{
cout << "You are fit.\n";
}
else
{
cout << "You are good.";
}
return 0;
}
```
<br/>
***
<br/>
***Question.2***
```
請撰寫一支完整的程式以計算數年後的本利和,該程式一開始先讓使用者輸入目前本金多少,再讓使用者輸入欲知多少年後的本利和,接著輸出算得的本利和(輸出至小數點後兩位);假設本金及本利和皆可為帶小數的數字,年利率為2%,採複利計算。
```
***Output.***
```
Please input account balance and years to maturity:
100
5
Your final balance will be 110.41
```
***My code.***
```cpp=
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double account_balance, years, sum;
cout << "Please input account balance and years to maturity:" << "\n";
cin >> account_balance >> years;
sum = account_balance * pow(1 + 0.02, years);
cout << fixed << setprecision(2) << "Your final balance will be " << sum;
return 0;
}
```