"Item 3-the variable wage category"
Design a wage class (Salary), in which the data members include the number of employees (number, variable) and the salary Salary of numbers of employees, the input of staff wages and output.
Tip: Storing the salary of a number of employees with a fixed size array may result in wasted space and may not be able to handle too many employees due to lack of space. Declare salary as a member of a pointer type by dynamically allocating space and allocating exactly the size of space to store the data.
Class Salary{public: Salary (int n); n is the number of employees, and the allocation of space is ~salary () when the initialization is completed; The Space void input_salary () allocated when initializing is released in the destructor; void Show_salary ();p rivate: double *salary; int number;};/ /The following defines the member functions of the class ...//The following is the test function int main () { Salary s (); S.input_salary (); S.show_salary (); return 0;}
#include <iostream>using namespace Std;class salary{public:salary (int n); Salary (const Salary &s); ~salary (); void Input_salary (); void Show_salary ();p rivate:double *salary; int number;}; Salary::salary (int n) {number=n; Salary=new double[n];} Salary::salary (const Salary &s) {number=s.number; Salary=new Double[number]; for (int i=0; i<number; ++i) {* (salary+i) =* (s.salary+i); }}salary::~salary () {delete []salary;} void Salary::input_salary () {cout<< "Please enter this" <<number<< "Employee's salary" <<endl; for (int i=0;i<number;i++) {cin>>* (salary+i); } cout<<endl; return;} void Salary::show_salary () {cout<< "This" <<number<< "Employee's payroll list:" <<endl; for (int i=0;i<number;i++) {cout<<* (salary+i) << ""; }}int Main () {Salary S1 (10); S1.input_salary (); Salary S2 (S1); S2.show_salary (); return 0;}
Item 3-the variable wage category