阿摩線上測驗 登入

申論題資訊

試卷:101年 - 101 地方政府特種考試_四等_資訊處理:資料處理概要(第1題)#12229
科目:資料處理
年份:101年
排序:0

申論題內容

一、某公司欲對薪資低於5萬元的員工調增薪資3%,但調薪後薪資上限5萬元,原薪資已達5萬元的員工不調薪。請用C/C++、C#或Java: (1)寫一程式片段,可供不斷輸入一位員工的薪資,計算其調薪後薪資。所有員工處理完後輸入A~Z之任一字元結束。(10分) (2)寫一程式片段,可供不斷輸入一位員工的薪資,所有員工處理完後輸入A~Z之任一字元結束。計算調薪後公司總薪資之增幅。(10分)

詳解 (共 3 筆)

詳解 提供者:Angus Yang
/*使用C++喔,可在Dev-C++ 4.9.9執行*/
#include
using namespace std;
main()
{
float old_t,new_t;
float old_m,new_m,final;
old_t=0;
new_t=0;
char key_in;
key_in = 'a';
new_t=0;
old_t=0;
cout << "press any key" << endl;
cout << "請按A~Z鍵結束,或按任何鍵繼續:" << endl;
cin >> key_in;
while( (key_in < 'A') || (key_in > 'Z') )
{
old_m = 0;
new_m = 0;
cout << "請輸入員工薪資" << endl;
cin >> old_m;
old_t = old_t + old_m;
if (old_m >= 50000)
{
cout << "薪資已大於或等於50000,不調薪" << endl;
new_t = new_t + old_m ;
}
else
{
new_m = old_m * 1.03;
if(new_m >= 50000)
{
new_m = 50000;
cout << "調薪後薪資已大於或等於50000以50000計" << endl;
new_t = new_t + new_m;
}
else
{
printf("調薪後薪資是 %.1f\n",new_m);
new_t = new_t + new_m;
}
cout << "請按A~Z鍵結束,或按任何鍵繼續:"
<< endl;
cin >> key_in;

}
}
final = ((new_t - old_t)/old_t) * 100 ;
printf( "員工薪資總調幅為:%.0f %%\n ",final );

system("PAUSE");
return 0;
}
詳解 提供者:Eggplant Lu
import java.util.Scanner;

public class 員工調增薪資 {

public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Scanner sc = new Scanner(System.in);
System.out.println("請輸入一位員工的薪資或輸入A~Z之任一字元結束。:");
String st = sc.nextLine();

String[] str_inc = st.split(" ");
int total = 0;
for (int i = 0; i < str_inc.length; i++) {
int income = Integer.valueOf(str_inc[i]);
double per_total = income * (1 + 0.03);
double increase = income * 0.03;
if (per_total <= 5000) {
System.out.println("調整後薪資為: " + (int) (per_total));
total += increase;
}

}
System.out.println("調薪後公司總薪資之增幅為: "+(int)(total));
sc.close();
}

}

詳解 提供者:Yu Chu Chu
(1)class