|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2007-11-19, 04:34 PM | #1 |
註冊會員
|
疑問 - 有關陣列的程式問題
-------------------- 閱讀本主題的最佳解答 -------------------- 看到陣列兩個字我投就要昏了 根本不知道該如何下手.............. Write a menu-driven program that allows the user to fill an array of 50 integers with random numbers in the range of 0 to 1000. The program has the following functions: (1) Fill the array with random numbers in the range of 0 to 1000. Each time this function is chosen the new random numbers is filled into the array. (2) Print the array. (3) Find the maximum and minimum value of the array. (4) Calculate the mean deviation of the numbers in the array. The mean deviation is defined as Σ|x - x|/n where x = Σx/n. Ex: x1 = 124, x2 = 234, x3 = 562, x4 = 12 → x = (124 + 234 + 562 + 12)/4 = 233 mean deviation = (|124 - 233| + |234 - 233| + |562 - 233| + |12 - 233|)/4 = 165 (5) Count the value distributions. A possible run may look like: ====================== Array Operation Menu ================== 1. Fill the array with random numbers in the range of 0 to 1000. 2. Print the array. 3. Find the maximum and minimum value of the array. 4. Calculate the mean deviation of the numbers in the array. 5. Count the value distributions for each consecutive 100 numbers. 6. Exit. ========================================================== => 1 50 random numbers in the range of 0 to 1000 has been filled into the array. ====================== Array Operation Menu =================== 1. Fill the array with random numbers in the range of 0 to 1000. 2. Print the array. 3. Find the maximum and minimum value of the array. 4. Calculate the mean deviation of the numbers in the array. 5. Count the value distributions for each consecutive 100 numbers. 6. Exit. ========================================================= => 2 The array is shown as follows: 578 984 630 927 146 917 369 922 598 550 101 51 481 230 901 82 669 759 395 639 42 930 34 576 374 448 359 659 692 705 521 978 303 938 877 18 24 530 487 302 416 186 496 71 667 386 542 877 338 615 ====================== Array Operation Menu =================== 1. Fill the array with random numbers in the range of 0 to 1000. 2. Print the array. 3. Find the maximum and minimum value of the array. 4. Calculate the mean deviation of the numbers in the array. 5. Count the value distributions for each consecutive 100 numbers. 6. Exit. ========================================================= => 5 The value distributes are shown as follows: Range Count 0 - 99 7 100 - 199 3 200 - 299 1 300 - 399 8 400 - 499 5 500 - 599 7 600 - 699 7 700 - 799 2 800 - 899 2 900 - 1000 8 ====================== Array Operation Menu ================== 1. Fill the array with random numbers in the range of 0 to 1000. 2. Print the array. 3. Find the maximum and minimum value of the array. 4. Calculate the mean deviation of the numbers in the array. 5. Count the value distributions for each consecutive 100 numbers. 6. Exit. ========================================================== => 6 Bye! 有高手可以寫一下 借我參考嗎 感恩捏ˊˋ" |
送花文章: 5,
|
2007-11-19, 07:33 PM | #2 (permalink) |
註冊會員
|
語法:
#include<iostream> using namespace std; int main(){ int i,j,d[50],m=0,n=1000,x,a[10]; srand(time(NULL)); cout <<"The array is shown as follows:"<<endl; for(i=0;i<10;i++) a[i]=0; for(i=0;i<50;i++){ if(i%10==0) cout <<endl; x=0; while(x==0){ x=1; d[i]=rand()%1001; for(j=0;j<i;j++) if(d[i]==d[j]) x=0; } if(n>d[i])n=d[i]; if(m<d[i])m=d[i]; if(d[i]<1000)a[d[i]/100]++; else a[9]++; cout <<d[i]<<" "; } cout <<endl<<endl<<"the maximum is : "<<m<<" ,and the minimum is : "<<n<<endl; x=m=0; for(i=0;i<50;i++) x+=d[i]; x/=50; for(i=0;i<50;i++) m+=abs(d[i]-x); cout <<endl<<"the mean deviation is : "<<(m/50)<<endl<<endl; cout <<"The value distributes are shown as follows:"<<endl<<"Range Count"<<endl<<endl; for(i=0;i<10;i++){ if(i!=0&&i!=9) cout<<i<<"00-"<<i<<"99 "; else{ if(i==0) cout <<"0-99 "; else cout <<"900-1000 "; } cout <<a[i]<<endl; } system("pause"); return 0; } 看不懂你題目所規定的輸出,只好階段性輸出那5項要求 |
送花文章: 15,
|
向 joebin 送花的會員:
|
rang0419 (2007-11-19)
感謝您發表一篇好文章 |
|
|
相似的主題 | ||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
請問如何在xp完dos game | dia700911 | 軟體應用問題討論區 | 4 | 2004-05-22 03:03 PM |
請問諾頓2004的問題 | andymail | 軟體應用問題討論區 | 8 | 2004-01-20 07:40 PM |