| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 777 人关注过本帖
标题:C++ 编程
取消只看楼主 加入收藏
helloworldll
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-1
结帖率:100%
收藏
 问题点数:0 回复次数:0 
C++ 编程
#include <iostream>
#include <fstream>
#include <string>
 
using namespace std;
 
int main() {
    ifstream fin;
    int sumtime[50] = {0};
    int themax;
    string name[50];
    int time[50][50];
     
    fin.open("d:\\fish.txt");
     
    fin >> themax;
    for(int i=0; i<themax; i++) {
        fin >> name[i];
        for(int j=0; j<7; j++) {
            fin >> time[i][j];
            sumtime[i] += time[i][j];
        }
    }
    fin.close();
     
     
    for(i=0; i< themax; i++) {
        cout << name[i] << " ";
        for(int j=0; j<7; j++) {
            cout << time[i][j] << " ";
        }
        cout << sumtime[i] << endl;
    }
     
    for (i = 0; i<themax-1; i++) {
        int k = i;
        int minnum;
        for (int j=i+1; j<themax; j++) {
            minnum = sumtime[i];            
            if (sumtime[j] < sumtime[k]) {
                k = j;
            }
        }
        if(i != k) {
            swap(name[i], name[k]);
            swap(sumtime[i], sumtime[k]);
            for (int n=0; n<7; n++) {
                swap(time[i][n], time[k][n]);
            }
        }
    }
     
    cout << "******************" << endl;
    for(i=0; i< themax; i++) {
        cout << name[i] << " ";
        for(int j=0; j<7; j++) {
            cout << time[i][j] << " ";
        }
        cout << sumtime[i] << endl;
    }
     
    return 0;
}
 这是我自己写的一个程序,请问我如何把这个程序分为三个自己定义的函数,然后再主函数中直接调用。分为1:读入文件,将数据存储在数组;2:冒泡排序。3:输出结果。请在我程序的基础上修改一下,谢谢了。
搜索更多相关主题的帖子: include 
2014-12-04 17:35
快速回复:C++ 编程
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011777 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved