史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2007-11-19, 04:34 PM   #1
rang0419
註冊會員
榮譽勳章

勳章總數
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設 疑問 - 有關陣列的程式問題



--------------------
閱讀本主題的最佳解答
--------------------


看到陣列兩個字我投就要昏了

根本不知道該如何下手..............


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!


有高手可以寫一下 借我參考嗎 感恩捏ˊˋ"
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
舊 2007-11-19, 07:33 PM   #2 (permalink)
註冊會員
 
joebin 的頭像
榮譽勳章

勳章總數
UID - 270712
在線等級: 級別:2 | 在線時長:16小時 | 升級還需:5小時級別:2 | 在線時長:16小時 | 升級還需:5小時
註冊日期: 2007-06-06
住址: 過去*現在*未來
文章: 42
精華: 0
現金: 58 金幣
資產: 118 金幣
預設



語法:
#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項要求
joebin 目前離線  
送花文章: 15, 收花文章: 18 篇, 收花: 28 次
回覆時引用此帖
向 joebin 送花的會員:
rang0419 (2007-11-19)
感謝您發表一篇好文章
舊 2007-11-19, 07:44 PM   #3 (permalink)
註冊會員
榮譽勳章

勳章總數
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設

不好意思


因誤我收到的題目也就只有這樣了 囧


所以我也不知道 有沒有錯 今害.......
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
舊 2007-11-21, 04:17 PM   #4 (permalink)
註冊會員
榮譽勳章

勳章總數
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設

對了 忘了講要用 C來寫捏 囧


你是不是用C++阿
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用

相似的主題
主題 主題作者 討論區 回覆 最後發表
資訊 - Longhorn 嶄新的驅動程式架構 psac 作業系統操作技術文件 0 2006-07-17 05:13 PM
反病毒引擎設計之既時監控篇 psac 應用軟體使用技術文件 0 2004-08-11 03:48 PM
請問如何在xp完dos game dia700911 軟體應用問題討論區 4 2004-05-22 03:03 PM
請問諾頓2004的問題 andymail 軟體應用問題討論區 8 2004-01-20 07:40 PM
Windows 2000/Xp 錯誤編號詳解(收集整理) psac 作業系統操作技術文件 9 2003-08-03 03:27 PM


所有時間均為台北時間。現在的時間是 03:55 PM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1