⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.cpp

📁 graph是一款linux/unix下绘制数据曲线图形的程序
💻 CPP
字号:
/* * function.cpp - класс функция, их создание/удаление * Copyright (C) 2007 lester *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA *  */#include "function.h"FunctionList functions;FunctionList &functions_get_function_list(){    return functions;}voidgraph_render_to_pixbuf();Function *functions_add_function_with_dims1 (gdouble xmin, gdouble xmax, gdouble res){    Function *f = new Function();    f->xmin = xmin;    f->xmax = xmax;    f->step = res != 0? res : 0.10;    int size = static_cast<int>((xmax - xmin) / f->step);    f->data_x = mgl_create_data_size(size, 0, 0);    f->data_y = mgl_create_data_size(size, 0, 0);    mgl_data_fill(f->data_x, xmin, xmax, 'x');    functions.push_back(f);    return f;}inline voidreplace_arguments1(const gchar *src, std::string &dest){    std::string temp;    guint i;    for (i = 0; i <= dest.size(); ++i)    {        if ( dest[i] == 'x')        {            temp += src;        } else {            temp += dest[i];        }    }    dest.assign(temp);}voidfunctions_modify_function1 (Function *f, std::string str){        char src[255];        gdouble xdiff = f->xmax - f->xmin;        f->eq = g_strdup(str.c_str());        sprintf (src, "(%f+%f*x)", f->xmin, xdiff);        replace_arguments1 (src, str);        mgl_data_modify(f->data_y, str.c_str(), 0);}std::stringfunctions_get_func_info (const gint num){    std::string str(_("Функция:\n"));    Function *f = functions[num];    char buf[32];    str += f->eq;    str += "\n";    str += _("Минимум по y:\n\t");    sprintf (buf, "%f", mgl_data_min(f->data_y));    str += buf;    str += "\n";    str += _("Максимум по y:\n\t");    sprintf (buf, "%f", mgl_data_max(f->data_y));    str += buf;    str += "\n";    str += "Нули функции:\n\t";    for (gint i = 0; i < f->data_y->nx-1; ++i)    {        if ( (f->data_y->a[i] > 0 && f->data_y->a[i+1] < 0) ||            (f->data_y->a[i] < 0 && f->data_y->a[i+1] > 0) || f->data_y->a[i] == 0)        {            str += "X";            sprintf (buf, "%f", (f->data_x->a[i]+f->data_x->a[i+1])/2);            str += buf;            str += "\n\t";        }    }    return str;}voidfunctions_delete_function (const gint index){    FunctionList::iterator it;    Function *f;    f = functions[index];        for (it = functions.begin(); it != functions.end(); ++it)        {            if (*it == f)            {                functions.erase(it);                delete f;                return;            }        }}voidfunctions_delete (){    FunctionList::iterator it;    for (it = functions.begin(); it != functions.end(); )    {        delete *it;        functions.erase(it);    }}gintfunctions_get_count (){    return functions.size();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -