Design a wage class (Salary) 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 payroll input), the wages are saved to the salary array, the actual number is saved to the numbers; void Add_salarys (int x) : Give everyone a raise x yuan pay void Sort_salarys (): Sort the wages by void Show_salarys (): Show payroll information (1) in the main function definition salary class of object, enter the salary, then give everyone up 500 yuan wages, sort after payroll data, And then output the results.
Reference Answer:
/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: March 28, 2015 * Version number: v1.0 * Problem Description: 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. * Input Description: * Output Result: */#include <iostream>using namespace Std;class salary{private:double salarys[50];//multi-person Payroll int number;//the actual number of public:void Set_salarys ();//input wage void Add_salarys (int x);//Give everyone a raise in pay void Sort_salarys ();//wage sort void Show_salarys ();//display salary Information};int main () {Salary s; S.set_salarys (); S.add_salarys (500); S.sort_salarys (); S.show_salarys (); return 0;} void Salary::set_salarys () {int n,i=0; while (cin>>n&&n>0) {salarys[i]=n; The payroll is saved to the data member array i++; } Number=i;//number is the number of employees, note the number of employees}void Salary::add_salarys (int x) {int i; for (i=0; i<number; i++) {salarys[i]+=x; }}void Salary::sort_salarys () {int i,j; Double T; For (i=0, i<number-1; i++) for (j=0; j<number-1-i; J + +) {if (sAlarys[j+1]>salarys[j]) {t=salarys[j]; SALARYS[J]=SALARYS[J+1]; salarys[j+1]=t; }}}void Salary::show_salarys () {int i; cout<< "Output salary increase after payroll data sort:" <<endl; for (i=0; i<number; i++) {cout<<i+1<< ' \ t ' <<salarys[i]<<endl; }}
Experience: According to the order of the main function and the topic requirements, can give some hints, relatively better, continue to refuel!
Learning is like building pipelines, slowly built, will be smooth road, refueling.
Item five of the third week-arrays as data members (1)