zoukankan      html  css  js  c++  java
  • C++ 数据结构

    C++ 数据结构
    C/C++ 数组允许定义可存储相同类型数据项的变量,但是结构是 C++ 中另一种用户自定义的可用的数据类型,它允许您存储不同类型的数据项。

    结构用于表示一条记录,假设您想要跟踪图书馆中书本的动态,您可能需要跟踪每本书的下列属性:

    Title :标题
    Author :作者
    Subject :类目
    Book ID :书的 ID

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 #include<iomanip>
     5 #include<cmath>
     6 using namespace std; 
     7 double f(double);
     8 double xpoint(double,double);
     9 double root(double,double);
    10 
    11 int main(int argc, char** argv) {
    12     double x1,x2,f1,f2,x;
    13     do
    14     {
    15         cout <<"input x1,x2:";
    16         cin >>x1 >>x2;
    17         f1=f(x1);
    18         f2=f(x2);
    19         }while(f1*f2>=0);
    20     x=root(x1,x2);
    21     cout <<setiosflags(ios::fixed)<<setprecision(7);
    22     cout <<"A root of equation is"<< x <<endl;    
    23     return 0;
    24 }
    25 
    26 double f(double x)
    27 {
    28     double y;
    29     y=x*x*x-5*x*x+16*x-80;
    30     return y;
    31 }
    32 
    33 double xpoint(double x1,double x2)
    34 {
    35     double y;
    36     y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
    37     return y;
    38 }
    39 
    40 double root(double x1,double x2)
    41 {
    42     double x,y,y1;
    43     y1=f(x1);
    44     do
    45     {
    46         x=xpoint(x1,x2);
    47         y=f(x);
    48         if(y*y1>0)
    49         {
    50             y1=y;
    51             x1=x;
    52         }
    53         else
    54         x2=x;
    55     }while(fabs(y)>=0.00001);
    56     return x;
    57 }
  • 相关阅读:
    页面检测网络外网连接- 网页基础模块(JavaScript)
    sql server替换字段中的某个字符
    关于Linux下 fork() 函数的总结
    郁闷的一天
    关于 Linux 下的线程函数未定义问题
    英文书籍
    学会阅读外文资料
    内存池设计(五)
    内存池设计(四)
    内存池设计(三)
  • 原文地址:https://www.cnblogs.com/borter/p/9401094.html
Copyright © 2011-2022 走看看