/* 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)