我想编写一个打开以前创建的文件“out.dat”的c ++程序。并计算agaatacaccaacgacta中字母'c'的相对频率...请帮助我填补空白点。 [英] I want to write a c++ program that open a previously created file "out.dat" and count relative frequencies of the letter 'c' in agaatacaccaacgacta...please help me fill the dots.

查看:149
本文介绍了我想编写一个打开以前创建的文件“out.dat”的c ++程序。并计算agaatacaccaacgacta中字母'c'的相对频率...请帮助我填补空白点。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<.........>
#include <fstream>
#include<........>
int main()
{
    ........a;
    ........count=0;
    ........myFile("out.dat");
    while(myFile >> a)
    {
        if(a ............'C')
            Count=count.....;
    }
    cout<< ........ <<"\n";
    getchar();
    return 0;
}





我的尝试:



我试过Cpp.sh ......无法运行它..因为我不明白如何完成程序......我发现计数很难理解



What I have tried:

I tried Cpp.sh ... Couldn't run it .. Because I didn't understand how to complete the program... I find counting is hard to understand

推荐答案

这是纯粹的家庭作业。请参阅您的课程笔记或询问您的老师。这是一个非常简单的练习。所以试试吧。计数并不困难。不要告诉自己,我不能这样做!这将使其更加困难。学习你的课程笔记,这将相对容易。
This is pure homework. Please refer to your course notes or ask your teacher. This is a really easy exercise. So give it a try. Counting is not difficult at all. Don't tell yourself, "I can't do this"! This will make it even more difficult. Study your course notes and it will be relatively easy.


看看 std :: count std :: iostream_iterator std :: ifstream 。使用标准库的这三个块,您可以在两行代码中执行所需的操作 - 如果您希望在文件无法打开时抛出异常,则可以执行三行。
Have a look at std::count, std::iostream_iterator and std::ifstream. Using these three chunks of the standard library you can do what you want in two lines of code - three if you want to have an exception thrown if the file failed to open.


这篇关于我想编写一个打开以前创建的文件“out.dat”的c ++程序。并计算agaatacaccaacgacta中字母'c'的相对频率...请帮助我填补空白点。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆