第四周實驗報告(四)

來源:互聯網
上載者:User
01.#include <iostream>     02.using namespace std;    03.class Salary       04.{    05.public:             06.    void set_salarys( );        07.    void add_salarys();        08.    void sort_salarys();    09.    void show_salarys( );          10.private:    11.    double salarys[50];      12.    int number;                13.};    14.    15.void Salary::set_salarys( )    //輸入工資的函數    16.{    17.    int x,i=0;    18.    cin>>x;     19.    while(x>0)    20.    {    21.        salarys[i]=x;    22.        ++i;    23.        cin>>x;    24.    }    25.    number=i;    26.}    27.    28.void Salary::add_salarys()    //增加100元的函數  29.{    30.    int i;    31.    for (i=0;i<number;i++)    32.        salarys[i]+=100;    33.}    34.    35.void Salary::sort_salarys()   //冒泡法排序   36.{    37.    int i,j;    38.    double t;    39.    for (i=0;i<number-1;i++)    40.        for(j=0;j<number-i-1;j++)    41.            if (salarys[j]>salarys[j+1])    42.            {    43.                t=salarys[j];    44.                salarys[j]=salarys[j+1];    45.                salarys[j+1]=t;    46.            }    47.}    48.    49.void Salary::show_salarys( )    // 顯示函數  50.{    51.    int i;    52.    for (i=0;i<number;i++)    53.        cout<<salarys[i]<<" ";    54.}    55.    56.int main( )    57.{    58.    Salary s;      59.    s.set_salarys( );        60.    s.add_salarys();      61.    s.sort_salarys();        62.    s.show_salarys( );     63.    system("PAUSE");    64.    return 0;    65.}    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.