人数不定的工资类

#include<iostream>
using namespace std;
class Salary
{
public:
    Salary(int n);
    ~Salary();
    void inputsalary();
    void showsalary();
private:
    double *salary;
    int number;

};
Salary::Salary(int n)
{
    salary=new double[n];
    number=n;
}
Salary::~Salary()
{
    delete []salary;
}
void Salary::inputsalary()
{
    int i;
    for(i=0;i<number;i++)
        cin>>salary[i];
}
void Salary::showsalary()
{   int i;
    for(i=0;i<number;i++)
        cout<<salary[i]<<endl;
}


int main(){
    Salary s(10);
    s.inputsalary();
    s.showsalary();
    return 0;
}



运行结果:

人数不定的工资类_第1张图片

你可能感兴趣的:(人数不定的工资类)