Week five-arrays Do data members (i)

Source: Internet
Author: User

/* Copyright (c) 2015, Yantai University School of Computer * All rights reserved. * File name: Test.cpp *    Creator: Lenkidong * Completion Date: March 19, 2015 * version number: v1.0*/

Problem


Design a Payroll class (Salary), where the data members of the class are as follows:

Class Salary{private:    double salarys[50];//multi-person wage    int number;  Actual number};

The member functions to be designed are:

    • void Set_salarys (): Enter the employee's salary (input-1 marks the end of the wage input), the wages are saved to the salary array, and the actual number is saved in numbers;
    • void Add_salarys (int x): Give everyone an X-dollar raise
    • void Sort_salarys (): Sort wages
    • void Show_salarys (): Show payroll information

(1) In the main function to define the object of the salary class, enter the salary, and then give everyone a 500 yuan salary, sort after the payroll data, and then output the results.

#include <iostream>using namespace Std;class salary{private:    int salarys[50];    int number;public:    void Set_salarys ();    void Add_salarys (int);    void Sort_salarys ();    void Show_salarys ();}; void Salary::set_salarys () {    int x=0,i=0;    while (X!=-1)    {        salarys[i]=x;        cin>>x;        i++;    }    Number=i;} void Salary::add_salarys (int a) {for    (int i=0;i<number+1;i++)    {        salarys[i]+=a;    }} void Salary::sort_salarys () {    int A;    for (int i=0;i<number;i++) for        (int j=0;j<number;j++)    {        if (salarys[j]>salarys[j+1])        { A=salarys[i];        SALARYS[I]=SALARYS[I+1];        Salarys[i+1]=a;}}}    void Salary::show_salarys () {for    (int i=0;i<number+1;i++)        Cout<<salarys[i]<<endl;} int main () {    Salary s;    S.set_salarys ();    S.add_salarys (666);    S.sort_salarys ();    S.show_salarys ();}

Operation Result:

Summary of Knowledge points:

Class set member functions

Learning experience:

Good study Day Day up

Week five-arrays Do data members (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.