プロジェクト4.マルチファイル給与
アップロード内容:C++プログラムの作成と実行
搭乗目的:簡単なC++プログラムの編集、コンパイル、接続と運行の一般的な過程を掌握する
マイプログラム:
main.cpp
Salary.h
salary.cpp
実行結果:略
心得体得:一度やってたくさん熟知しました
知識点まとめ:略
搭乗目的:簡単なC++プログラムの編集、コンパイル、接続と運行の一般的な過程を掌握する
マイプログラム:
main.cpp
/*
Copyright (c) 2013,
* All rights reserved.
* :
* :2014 3 23
* :v1.0
* :
* : (1)
* :
* :
* :
*/
#include <iostream>
#include <fstream>
#include "Salary.h"//
using namespace std;
Salary sa;
int main()
{
sa.set_salary();
sa.add_salary(500);
sa.sort_salary();
sa.show_salary();
return 0;
}
Salary.h
#ifndef SALARY_H_INCLUDED
#define SALARY_H_INCLUDED
class Salary
{
public:
void set_salary();
void add_salary(int x);
void sort_salary();
void show_salary();
private:
double *salary;
int number;
};
#endif // SALARY_H_INCLUDED
salary.cpp
#include <iostream>
#include <fstream>
#include "Salary.h"
using namespace std;
void Salary::set_salary()
{
int i=0;
cout<<" :"<<endl;
cin>>number;
salary=new double[number];
cout<<" ..."<<endl;
ifstream infile("salary.txt",ios::in);
while(i!=number)
{
infile>>salary[i++];
}
infile.close();
cout<<" !"<<endl;
}
// 500
void Salary::add_salary(int x)
{
for(int i=0;i<number;i++)
{
salary[i]+=x;
}
}
//
void Salary::sort_salary()
{
int i=0,j=0;
double t;
for(i=0; i<number-1; i++)
{
for(j=0; j<number-i-1; j++)
{
if (salary[j]<salary[j+1])
{
t=salary[j];
salary[j]=salary[j+1];
salary[j+1]=t;
}
}
}
}
//
void Salary::show_salary()
{
ofstream outfile("sortsalary.txt",ios::out);//
cout<<" ! 500 !
..."<<endl;
for(int i=0; i<number; i++)
{
outfile<<salary[i]<<endl;// outfile, cout
}
outfile.close();
}
実行結果:略
心得体得:一度やってたくさん熟知しました
知識点まとめ:略