Poor local Tadoku

Posts 1–3 of 3 · Page 1 of 1
Poor local Tadoku
So I got this Idea from the guy at readmod.word press.com who held competitions or so of reading in another language, and 2 days ago the contest ending, but I liked the Idea so I created my own version in C++, a long with some additions that I made.
There were some semi functional features that I had to remove due to problems, but it supports graphs for progress now yayy

So far it will only work on Linux if you compile the source, but i will port it to windows tomorrow. Sorry for the source being in Japanese btw
gnuplot was a fegget so the graphing switch does not work as I wanted to, but it is fine, only takes about 2 more seconds to get the graph xD

It was also for practice because I have never used command line args before, but now they fully work yay. If there are better ways tell me please xD
If you cannot tell it is completely command line argument based. If you do not use them youll only get a parameter missing error

Edit: Fuck. Realized there is a typo in the program. 別に should be 別の sorry
too lazy to recompile though






Code:
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <fstream>
#include <time.h>

using namespace std;

string error1 = "エラー1:コマンドが見つかりません、-help を参照して下さい";
string error2 = "エラー2: コマンドを入力して下さい、 -help を参照して下さい";
string error3 = "エラー3: 有効な値ではありません。";
string help = "多読リスト\t\t多聴リスト\n本:-book\t\tアニメ:-anime\n漫画:-manga\t\t映画:-eiga\nウェブサイト:-web\t音楽:-ongaku\n和文:-sent\t\t手動で時間を入力する(分):-f\n字幕:-jimaku\n";
string clarg;   //端末で入力するコマンド
string about = "Patrick Clandという偉い人に作られたアプリです。2013年2月2日";
string about2 = "多読リスト\n本:1点/頁\n漫画:.2点/頁\nウェブサイト:1点/頁\n和文:.05点/文\n字幕:.2点/分";
string about3 = "\n多聴リスト\nアニメ:20点/話\n映画:100点/映画\n音楽:3.5点/曲\n手動で時間を入力する:1点/分";

ofstream outread ("read.txt",ios::app);
ofstream outhear ("hear.txt",ios::app);
ofstream outgraphread ("graphread.dat",ios::app);
ofstream outgraphhear ("graphhear.dat",ios::app);
ifstream inread ("read.txt");
ifstream inhear ("hear.txt");

float read_value=0;
float hear_value=0;

void textToDat()
{
    float x=0,y=0,i; //temp

    if((!inread)||(!inhear))
    {
        cout << "read.txtとhear.txtを読み込めません\n";
        exit(1);
    }
    while(inread >> i)
    {
        x+=i;
    }
    cout << "多読:" << x << "点\n";
    while(inhear >> i)
    {
        y+=i;
    }
    cout << "多聴:" << y << "点\n";

    cout << "スコアを別にファイルにエクスポートしますか?(Y/N)";
    char choice;
    cin >> choice;
    if(choice == 'y')
    {
        time_t rawtime;
        struct tm * timeinfo;
        char buffer [3];

        time ( &rawtime );
        timeinfo = localtime ( &rawtime );

        strftime (buffer,3,"%d",timeinfo);
        outgraphread << buffer << " " << x << '\n';
        outgraphhear << buffer << " " << y << '\n';
        outgraphread.close();
        outgraphhear.close();

        cout << "エクスポートしました\n";
    }
    else
    {
        cout << "エクスポートしませんでした\n";
    }

}


int main(int argc, char* argv[])
{


    switch (argc)
    {
    case 1: //コマンドが無い
        cout << error2 << '\n';
        return 0;
    case 2:
        clarg = argv[1];
        if (clarg == "-help")
        {
            cout << help << '\n';
        }
        else if (clarg == "-about")
        {
            cout << about << '\n' << about2 << '\n' << about3 << '\n';
        }
        else if (clarg == "-reset")
        {
            cout << "ファイルを完全に削除します。続行しますか? (Y/N)...";
            char choice;
            cin >> choice;
            if(choice == 'y')
            {
                cout << "ファイルを削除しています…\n";
                system("rm hear.txt read.txt");
                cout << "ファイルを完全に削除しました!\n";
            }
            else
            {
                return 0;
            }
        }
        else if (clarg == "-stats")
        {
            textToDat();
        }
        else if (clarg == "-graph")
        {
            cout << "plot 'ファイル名' with lines と入力して下さい\n見終わったらウィンドウを閉じて'exit'と入力して下さい\n";
            system("gnuplot");
        }
        else
        {
            cout << error1 << '\n';
        }
        break;
    case 3:
        clarg = argv[1];
        //多読リスト
        if (clarg == "-book")//本
        {
            read_value = atof(argv[2]);
            read_value*=1.0;
            outread << read_value << '\n';
        }
        else if (clarg == "-manga")//漫画
        {
            read_value = atof(argv[2]);
            read_value*=0.2;
            outread << read_value << '\n';
        }
        else if (clarg == "-web")//ウェブサイト
        {
            read_value = atof(argv[2]);
            read_value*=1.0;
            outread << read_value << '\n';
        }
        else if (clarg == "-sent")//和文
        {
            read_value = atof(argv[2]);
            read_value*=0.05;
            outread << read_value << '\n';
        }
        else if (clarg == "-jimaku")//字幕
        {
            read_value = atof(argv[2]);
            read_value*=0.2;
            outread << read_value << '\n';

        }
        //==================================
        //多聴リスト
        //==================================
        else if (clarg == "-anime")
        {
            hear_value = atof(argv[2]);
            hear_value*=20.0;
            outhear << hear_value << '\n';

        }
        else if (clarg == "-eiga")
        {
            hear_value = atof(argv[2]);
            hear_value*=100.0;
            outhear << hear_value << '\n';

        }
        else if (clarg == "-ongaku")
        {
            hear_value = atof(argv[2]);
            hear_value*=3.5;
            outhear << hear_value << '\n';

        }
        else if (clarg == "-f")
        {
            hear_value = atof(argv[2]);
            hear_value*=1.0;
            outhear << hear_value << '\n';

        }
        else
        {
            cout << error1 << '\n';
            exit(1);
        }
        outread.close();
        outhear.close();
        break;
    default:
        break;
    }
    return 0;
}
Yu no paste english?! .
Didn't think anybody would want it
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us