源程序:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream infile("salary.txt",ios::in);
if(!infile)
{
cerr << "open error!!!";
exit(0);
}
double a[500], t;
int i, j;
for(i = 0; i < 500; ++ i)
{
infile >> a[i];
a[i] = a[i] + 100;
}
infile.close();
for(j = 0; j <499 ;++ j)
{
for(i = 0; i < 499 - j; ++ i)
{
if(a[i] > a[i + 1])
{
t = a[i];
a[i] = a[i + 1];
a[i + 1] = t;
}
}
}
ofstream outflie("ordered_salary.txt",ios::out);
if(!outflie)
{
cerr << "open error!!!";
exit(0);
}
cout << "涨工资后的工资为(升序排列):" << endl;
for(i = 0; i < 500; ++ i)
{
outflie << a[i] << " ";
}
for(i = 0; i < 500; ++ i)
{
cout << setw(8) << a[i] << setw(8);
if(((i + 1) % 10) == 0)
{
cout << endl;
}
}
system("pause");
return 0;
}
截图:
涨工资后的工资为(升序排列):
634.43 644.67 648.71 653.65 654.3 660.24 672.72 673.1 685.25 689.43
689.97 692.22 696.16 699.77 711.29 713.3 714.22 719.54 722.48 734.22
740.75 743.84 748.86 766.83 778.67 780.8 781.29 788.48 794.8 795.48
799.68 805.92 810.45 823.49 828.13 829.15 841.9 846.5 848.5 857.65
863.77 871.3 873.56 878.31 879.92 882.3 891.95 892.32 902.77 904.2
917.2 925.9 928.64 931.11 931.39 932.11 933.42 944.49 945.14 950.4
950.81 951.57 953.4 958.74 962.27 962.48 962.85 964.92 972.61 976.95
981.12 995.16 997.91 999.71 1001.26 1002.29 1006.43 1009.41 1009.68 1028.37
1038.28 1040.34 1049.99 1050.45 1055.17 1055.71 1062.11 1062.4 1062.57 1072.81
1072.92 1075.23 1078.89 1080.55 1085.94 1093.84 1098.22 1103.34 1103.43 1105.34
1105.61 1105.74 1106.2 1111.89 1113.89 1124.76 1126.28 1134.7 1145.9 1150.54
1161.66 1166.63 1168.69 1169.9 1172.8 1182.87 1191.62 1191.78 1199.51 1203.17
1212.86 1215.36 1215.57 1215.63 1218.11 1219.57 1232.66 1236.91 1243.64 1245.24
1245.34 1247.89 1263.87 1266.78 1268.84 1270.91 1280.6 1281.16 1287.33 1290.11
1294.68 1294.8 1294.94 1297.41 1299.42 1307.1 1313.95 1320.87 1322.8 1328
1328.94 1331.26 1331.82 1336.46 1339.96 1345.72 1354.24 1354.64 1365.45 1367.37
1368.82 1380.23 1387.69 1390.2 1396.38 1397.42 1398.99 1406.81 1409.49 1411.32
1413.75 1424.28 1426.54 1426.63 1427.6 1429.64 1432.45 1436.68 1446.39 1448.9
1449.45 1458.76 1460.18 1485.12 1487.96 1499.35 1501.49 1504.53 1523.2 1532.14
1540.24 1546.58 1549.49 1557.61 1559.25 1588.51 1589.57 1595.6 1596.64 1606.61
1615.47 1622.4 1625.74 1629.11 1629.37 1658.9 1662.86 1664.16 1668.5 1676.12
1678.49 1679.13 1691.71 1697.74 1699.24 1704.15 1705.55 1708.52 1708.76 1713.66
1721.71 1728.1 1736.8 1738.25 1739.24 1741.16 1746.79 1746.94 1748.4 1752.41
1758.92 1759.35 1763.38 1764.4 1775.24 1779.8 1780.9 1787.41 1788.42 1796.38
1807.64 1807.79 1811.96 1818.82 1829.38 1841.93 1848.4 1855.86 1860.42 1860.89
1863.34 1865.32 1868.74 1882.77 1884.22 1892.99 1895.2 1900.54 1910.6 1910.68
1921.47 1922.32 1926.21 1935.38 1942.54 1943.52 1948.4 1948.92 1954.94 1964.86
1969.9 1970.13 1972.97 1974.49 1985.23 1986.45 1986.9 1987.33 1992.87 1993.97
1995.55 2000.77 2000.84 2003.66 2004.57 2004.86 2006.4 2034.49 2038.33 2039.63
2042.62 2046.62 2046.68 2052.96 2055.57 2071.24 2074.22 2080.74 2084.87 2090.25
2090.59 2101.91 2109.47 2111.1 2119.3 2126.19 2127.8 2129.45 2137.31 2141.49
2147.84 2148.96 2152.36 2165.6 2171.62 2180.98 2184.51 2185.27 2192.66 2202.52
2202.63 2206.57 2212.3 2218.2 2221.39 2224.58 2238.85 2243.46 2244.4 2245.1
2245.54 2245.99 2249.21 2252.35 2252.61 2258.61 2261.6 2262.98 2270.71 2278.65
2283.8 2287.4 2292.81 2294.15 2303.48 2306.63 2311.9 2321.71 2326.63 2333.84
2340.99 2349.5 2352.79 2358.94 2365.7 2377.5 2392.48 2392.62 2406 2408.74
2410.37 2425.6 2434.86 2440.57 2441.73 2444.9 2446.91 2449.14 2459.26 2459.4
2460.12 2469.1 2475.89 2476.48 2483.71 2484.95 2486.22 2490.4 2491 2498.59
2500.2 2509.58 2510.92 2516.17 2524.46 2534.65 2534.72 2539.71 2541.1 2546.31
2550.49 2557.61 2578.74 2587.88 2591.6 2595.5 2597.9 2604.25 2607.35 2613.58
2620.23 2621.74 2630.81 2636.18 2638.14 2640.76 2644.43 2650.13 2651.5 2654.82
2660.7 2664.65 2680.97 2700.42 2707.83 2720.15 2720.87 2726.1 2727.47 2727.62
2729.71 2738.86 2740.22 2741.32 2748.55 2750.92 2756 2766.2 2769.59 2773.31
2800.53 2802.7 2804.35 2805.8 2808.74 2809.33 2811.12 2814.84 2816.12 2817.51
2835.2 2838.9 2839.34 2841.95 2843.18 2845.52 2867.94 2872.59 2872.85 2873.98
2877.54 2887.2 2892.31 2898.32 2909.58 2909.59 2914.89 2915.13 2916.2 2922.33
2927.11 2931.31 2932.47 2935.94 2936.74 2938.8 2939.73 2941.68 2946.23 2951.86
2954.6 2957.6 2961.65 2974.9 2975.25 2979.14 2985.38 2986.68 2990.26 3004.98
3005.76 3006.75 3006.93 3009.22 3012.41 3014.69 3019.21 3030.51 3034.8 3040.78
3045.1 3047.46 3058.17 3058.93 3062.72 3068.97 3081.5 3082.7 3084.95 3085.84
请按任意键继续. . .
很不好意思说···这个任务上个学期贺老有交代过····可是似乎没有做···以至于这次有点摸不着头脑了···
好久没做面向过程的任务了···有点手生了····格式也没有太注意····也没用函数的声明····额····惭愧啊····