C++程序设计:从考试文件夹下的文件“data.txt ”中读入一个字符串,过滤此串,只保留串中的字母字符

从考试文件夹下的文件“data.txt ”中读入一个字符串,过滤此串,只保留串中的字母字符,并统计新生成串中包含的字母个数,并将新生成的字符串写入。例如:输入的字符串为ab234$df4,新生成的串为abdf 。
源程序存盘文件名:example1.cpp

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
    fstream file1("data.txt", ios::in), file2("example1.cpp", ios::out);
    string data ;
    string result;
    file1 >> data;
    for(int i = 0; i < data.size(); i++)
        if(isalpha(data[i]))
            result += data[i];
    cout << result << "  size :" << result.size() << endl;
    file1.close();
    file2 << result;
    file2.close();
}

追问

请编写一个函数void fun(int tt[M][N],int pp[N]),tt指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入pp所指一维数组中。二维数组中的元素值在主函数中随机产生(值域范围[1, 9])。

麻烦你帮我解决一下这个问题吧,一起算分给你阿,麻烦了

追答#include <iostream>
#include <cstdlib>
#define M 10
#define N 10
using namespace std;
void fun(int tt[M][N], int pp[N])
{
    int i, j, max;
    for(j = 0; j < N; j ++)
    {
        max = tt[0][j];
        for(i = 1; i < M; i++)
            if(tt[i][j] > max)
                max = tt[i][j];
        pp[j] = max;
    }
}

void print(int pp[N])
{
    int i;
    for(i = 0; i < N ; i++)
        cout << pp[i] << " ";
    cout << endl;
}
int main()
{

    int tt[M][N], pp[N];
    int i, j;
    for(i = 0; i < M; i++)
        for(j = 0; j < N; j++)
            tt[i][j] = rand() % 9 + 1;

    fun(tt, pp);
    print(pp);
}

温馨提示:答案为网友推荐,仅供参考