• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            電子科大實驗報告之四:罐裝飲料瓶(Matlab的解法)

            題目:
            設易拉罐的側面的厚度1單位,
            s=2*PI*r*h+4*PI*r^2
            h高度,r為半徑,體積V=PI*h*r^2.
            V一定時,求使s最小的r和h.

            Matlab的解法:
            解法1:
            v=350;
            s=0;h=0;r=0;
            for j=1:6

            ?r_=(v/(j*pi))^(1/3)
            ?h_=j*r_
            ?s_=2*pi*r_*h_+4*pi*r_*r_
            ?
            ?if(s>s_ | s==0)

            ??s=s_;
            ??h=h_;
            ??r=r_;

            ?end
            end
            s
            r
            h
            r/h


            解法2:
            v=350;
            s=[];h=[];r=[];
            for j=1:6

            ?r(j)=(v/(j*pi))^(1/3)
            ?h(j)=j*r(j)
            ?s(j)=2*pi*r(j)*h(j)+4*pi*r(j)^2

            end

            [minCost,j]=min(s)
            r(j)
            h(j)
            r(j)/h(j)


            解法3:
            cost=inline('(2*pi*x+4*pi)*(350/(pi*x))^(2/3)');
            s=fminbnd(cost,0.001,25)
            feval(cost,s)

            fplot(cost,[0.1 50]);grid on;

            posted @ 2006-04-06 14:13 張沈鵬 閱讀(488) | 評論 (0)編輯 收藏
             

            這學期電腦被家中沒收,只能在網吧上網,什么也干不了,很是郁悶。每天到圖書館翻看C++和神經網絡的書,在紙上寫代碼...................


            秋天的時候,
            落葉帶著一生的惆悵,
            第一次學會飛翔。

            春天的期望,
            夏天的夢想,
            在微涼的風中,
            成為沒有回聲的吟唱。

            許多年以后,
            我們的故事,
            終究還是被所有的人遺忘。

            一段塵封的記憶,
            層層疊疊,
            埋藏在亙古的時光。

            吻別,
            芬芳,歌聲和陽光。

            最后的最后,
            我才明白,
            一切的盡頭,
            就是我出發的地方。

            posted @ 2006-03-22 17:25 張沈鵬 閱讀(291) | 評論 (2)編輯 收藏
             

            http://giallo.sourceforge.net/
            Giallo is a C++ library for asynchronous network programming, based on proactor style notification, independent of underlying OS demultiplexing methods. The aim is to get this accepted into Boost.

            http://asio.sourceforge.net/
            asio is a cross-platform C++ library for network programming that provides developers with a consistent asynchronous I/O model using a modern C++ approach.

            posted @ 2006-03-08 21:44 張沈鵬 閱讀(629) | 評論 (0)編輯 收藏
             

            看到有前輩寫了一個UTF-8與UNICODE相互轉換的代碼,順便提一下,希望可以給大家提供一點幫助.
            下面是一些編碼格式的bit長

            Examples of fixed-width encoding forms:

            Type Each character
            encoded as
            Notes
              7-bit a single 7-bit quantity example: ISO 646
              8-bit G0/G1 a single 8-bit quantity with constraints on use of C0 and C1 spaces
              8-bit a single 8-bit quantity with no constraints on use of C1 space
              8-bit EBCDIC a single 8-bit quantity with the EBCDIC conventions rather than ASCII conventions
            16-bit (UCS-2) a single 16-bit quantity within a code space of 0..FFFF
            32-bit (UCS-4) a single 32-bit quantity within a code space 0..7FFFFFFF
            32-bit (UTF-32) a single 32-bit quantity within a code space of 0..10FFFF
            16-bit DBCS process code a single 16-bit quantity example: UNIX widechar implementations of Asian CCS's
            32-bit DBCS process code a single 32-bit quantity example: UNIX widechar implementations of Asian CCS's
            DBCS Host two 8-bit quantities following IBM host conventions

            Examples of variable-width encoding forms:

            Name Characters are encoded as Notes
            UTF-8 a mix of one to four 8-bit code units in Unicode
            and one to six code units in 10646
            used only with Unicode/10646
            UTF-16 a mix of one to two 16 bit code units used only with Unicode/10646

            Boost中提供了一個UTF-8 Codecvt Facet,可以在utf8和UCS-4(Unicode-32)之間轉換.
            使用方式如下

              //...
              // My encoding type
              typedef wchar_t ucs4_t;

              std::locale old_locale;
              std::locale utf8_locale(old_locale,new utf8_codecvt_facet<ucs4_t>);

              // Set a New global locale
              std::locale::global(utf8_locale);

              //  UCS-4 轉換為 UTF-8
              {
                std::wofstream ofs("data.ucd");
                ofs.imbue(utf8_locale);
                std::copy(ucs4_data.begin(),ucs4_data.end(),
                      std::ostream_iterator<ucs4_t,ucs4_t>(ofs));
              }

              // 讀入 UTF-8 ,轉換為 UCS-4 
              std::vector<ucs4_t> from_file;
              {
                std::wifstream ifs("data.ucd");
                ifs.imbue(utf8_locale);
                ucs4_t item = 0;
                while (ifs >> item) from_file.push_back(item);
              }
              //...
            UTF-8 Codecvt Facet詳見
            http://www.boost.org/libs/serialization/doc/codecvt.html

            posted @ 2006-02-15 17:19 張沈鵬 閱讀(2662) | 評論 (2)編輯 收藏
             

            boost在路上...tokenizer
            tokenizer - Break of a string or other character sequence into a series of tokens, from John Bandela
            tokenizer - 分解字串,提取內容.作者: John Bandela

            例一:
            // simple_example_1.cpp
            #include<iostream>
            #include<boost/tokenizer.hpp>
            #include<string>

            int main(){
               using namespace std;
               using namespace boost;
               string s = "This is,  a test";
               tokenizer<> tok(s);
               for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
                   cout << *beg << "\n";
               }
            }

            輸出
            This
            is
            a
            test

            tokenizer默認將單詞以空格和標點為邊界分開.

            例二:
            #include<iostream>
            #include<boost/tokenizer.hpp>
            #include<string>

            int main(){
               using namespace std;
               using namespace boost;
               string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
               tokenizer<escaped_list_separator<char> > tok(s);
               for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
                   cout << *beg << "\n";
               }
            }
            輸出
            Field 1
            putting quotes around fields, allows commas
            Field 3

            雙引號之間可以有標點.


            例三:
            // simple_example_3.cpp
            #include<iostream>
            #include<boost/tokenizer.hpp>
            #include<string>

            int main(){
               using namespace std;
               using namespace boost;
               string s = "12252001";
               int offsets[] = {2,2,4};
               offset_separator f(offsets, offsets+3);
               tokenizer<offset_separator> tok(s,f);
               for(tokenizer<offset_separator>::iterator beg=tok.begin(); beg!=tok.end();++beg){
                   cout << *beg << "\n";
               }
            }

            把12252001分解為
            12
            25
            2001

            例4:
            // char_sep_example_1.cpp
            #include <iostream>
            #include <boost/tokenizer.hpp>
            #include <string>

            int main()
            {
              std::string str = ";!!;Hello|world||-foo--bar;yow;baz|";
              typedef boost::tokenizer<boost::char_separator<char> >
                tokenizer;
              boost::char_separator<char> sep("-;|");
              tokenizer tokens(str, sep);
              for (tokenizer::iterator tok_iter = tokens.begin();
                   tok_iter != tokens.end(); ++tok_iter)
                std::cout << "<" << *tok_iter << "> ";
              std::cout << "\n";
              return EXIT_SUCCESS;
            }

            輸出
            <!!> <Hello> <world> <foo> <bar> <yow> <baz>
            自定義分隔的標點

            例5:
                // char_sep_example_2.cpp
                #include <iostream>
                #include <boost/tokenizer.hpp>
                #include <string>

                int main()
                {
                    std::string str = ";;Hello|world||-foo--bar;yow;baz|";
                    typedef boost::tokenizer<boost::char_separator<char> >
                        tokenizer;
                    boost::char_separator<char> sep("-;", "|", boost::keep_empty_tokens);
                    tokenizer tokens(str, sep);
                    for (tokenizer::iterator tok_iter = tokens.begin();
                         tok_iter != tokens.end(); ++tok_iter)
                      std::cout << "<" << *tok_iter << "> ";
                    std::cout << "\n";
                    return EXIT_SUCCESS;
                }

            The output is:

                <> <> <Hello> <|> <world> <|> <> <|> <> <foo> <> <bar> <yow> <baz> <|> <>
            去除-; , 保留|但將它看作是分隔符,當兩個分隔符相鄰的時候會自動加空格

            例6:
                // char_sep_example_3.cpp
                #include <iostream>
                #include <boost/tokenizer.hpp>
                #include <string>

                int main()
                {
                   std::string str = "This is,  a test";
                   typedef boost::tokenizer<boost::char_separator<char> > Tok;
                   boost::char_separator<char> sep; // default constructed
                   Tok tok(str, sep);
                   for(Tok::iterator tok_iter = tok.begin(); tok_iter != tok.end(); ++tok_iter)
                     std::cout << "<" << *tok_iter << "> ";
                   std::cout << "\n";
                   return EXIT_SUCCESS;
                }

            The output is:

                <This> <is> <,> <a> <test>
            保留標點但將它看作分隔符

            posted @ 2006-01-25 18:00 張沈鵬 閱讀(748) | 評論 (0)編輯 收藏
             

            MinGW的下載安裝我就不多說了
            1.
            設置MinGW的環境變量,在
            E:\!程序\C++\boost_1_33_0\tools\build\jam_src
            目錄下運行
            build.bat mingw
            編譯bjam,在
            E:\!程序\C++\boost_1_33_0\tools\build\jam_src\bin.ntx86
            下生成bjam.exe,Copy it to windows directory.

            2.
            在Boost的解壓目錄下運行
            bjam "-sTOOLS=mingw" install
            就可以了,編譯完成的文件會自動放在C:\Boost\lib下
            注意,boost的解壓目錄的路徑中不要有中文或!之類的標點,不然可能有許多奇怪的錯誤.

            3.
            可以在lib目錄下你需要的庫中找到有jam文件的目錄,運行
            bjam "-sTOOLS=mingw"
            就可以只編譯該庫,編譯完成后會防止stage\lib目錄下

            posted @ 2006-01-25 17:59 張沈鵬 閱讀(512) | 評論 (0)編輯 收藏
             
            用dll要一個導入庫和頭文件,對于Gcc/G++可以用工具dlltool來生成這個導入庫.命令如下:

            dlltool --dllname foo.dll --def foo.def --output-lib libfoo.a

            dlltool在MinGW的工具包中有.
            然后可以用 -l libfoo 調用庫(libfoo的lib前綴可以省略,注意libfoo不要加后綴名,-L可以指定庫的目錄)
            posted @ 2006-01-19 02:41 張沈鵬 閱讀(973) | 評論 (0)編輯 收藏
             

            用mingw32-make前修改一下makefile文件,改為如下

            # DEBUG can be set to YES to include debugging info, or NO otherwise(不是DEBUG)
            DEBUG????????? := NO

            # PROFILE can be set to YES to include profiling info, or NO otherwise
            PROFILE??????? := NO

            # TINYXML_USE_STL can be used to turn on STL support. NO, then STL
            # will not be used. YES will include the STL files.(使用STL,選擇的話,則可以使用std::string)
            TINYXML_USE_STL := YES

            另外可以tinyxml_guide.zip可以下載.

            以下轉載:

            TinyXml學習筆記

            張弛<zhangchi@china.com>

            一、????? TinyXml的特點

            TinyXml是一個基于DOM模型的、非驗證的輕量級C++解釋器。

            1.????? SAX和DOM

            目前XML的解析主要有兩大模型:SAX和DOM。

            其中SAX是基于事件的,其基本工作流程是分析XML文檔,當發現了一個新的元素時,產生一個對應事件,并調用相應的用戶處理函數。這種方式占用內存少,速度快,但用戶程序相應得會比較復雜。

            而DOM(文檔對象模型),則是在分析時,一次性的將整個XML文檔進行分析,并在內存中形成對應的樹結構,同時,向用戶提供一系列的接口來訪問和編輯該樹結構。這種方式占用內存大,速度往往慢于SAX,但可以給用戶提供一個面向對象的訪問接口,對用戶更為友好。

            2.????? 驗證和非驗證

            對于一個特定的XML文檔而言,其正確性分為兩個層次。首先是其格式應該符合XML的基本格式要求,比如第一行要有聲明,標簽的嵌套層次必須前后一致等等,符合這些要求的文件,就是一個合格的XML文件,稱作well-formatted。但除此之外,一個XML文檔因其內容的不同還必須在語義上符合相應的標準,這些標準由相應的DTD文件或者Schema文件來定義,符合了這些定義要求的XML文件,稱作valid。

            因此,解析器也分為兩種,一種是驗證的,即會跟據XML文件中的聲明,用相應的DTD文件對XML文件進行校驗,檢查它是否滿足DTD文件的要求。另一種是忽略DTD文件,只要基本格式正確,就可以進行解析。

            就我所知,驗證的解析器通常都是比較重量級的。TinyXml不支持驗證,但是體積很小,用在解析格式較為簡單的XML文件,比如配置文件時,特別的合適。

            二、 TinyXml的構建和使用
            1.????? 獲取

            TinyXml首頁在http://www.grinninglizard.com/tinyxml/index.html,從這里可以找到最新版本的源代碼,目前的版本是2.3.4。

            2.構建

            TinyXml在構建時可以選擇是否支持STL,選擇的話,則可以使用std::string,所以通常應該打開這個選項。

            在Windows上,TinyXml的源碼包里提供了VC6的工程文件,直接用它就可以生成兩個靜態庫(帶STL和不帶STL),非常容易。唯一需要注意的是,默認生成的庫是單線程的,如果用在多線程的項目中,需要改動一下配置,生成相應的多線程庫。

            在Unix平臺上,TinyXml的源碼包里只提供了一個Makefile,對于典型的Linux系統,或裝了gcc和gmake的其他Unix,這個Makefile足夠用了,我在RH9和RHEL4上測試,簡單的make就成功了。需要注意的有以下幾點:默認的編譯是不支持STL的,可以通過編輯Makefile的TINYXML_USE_STL := NO那一行,把NO改成YES就可以支持STL了;還有默認只生成了一個測試程序,沒有生成任何庫,如果要生成靜態庫的話,可以用ar命令,將生成的幾個目標文件打包就行了,如果要生成動態庫,則需要加上-fpic參數重新編譯。

            3.????? 使用

            構建了相應的庫之后,在使用了它們的工程中,只要在連接時把他們連上就行了。需要注意的是,如果需要STL支持,在編譯用到了TinyXml的文件時,需要定義一個宏TIXML_USE_STL,對gcc,可以使用參數-DTIXML_USE_STL,對cl.exe(VC),可以使用參數/DTIXML_USE_STL,如果嫌麻煩,可以直接定義在 tinyxml.h文件里。

            三、 TinyXml的編程模型1.????? 類之間的關系

            TinyXml實現的時DOM訪問模型,因此提供了一系列的類對應XML文件中的各個節點。主要類間的關系如下圖所示:

            TiXmlBase:其他類的基類,是個抽象類

            TiXmlNode:表示一個節點,包含節點的一般方法,如訪問自節點、兄弟節點、編輯自身、編輯子節電

            TiXmlDocument:表示整個XML文檔,不對應其中某個特定的節點。

            TiXmlElement:表示元素節點,可以包含子節點和TiXmlAttribute

            TiXmlComment:表示注釋

            TiXmlDeclaration:表示聲明

            TiXmlText:表示文本節點

            TiXmlUnknown:表示未知節點,通常是出錯了

            TiXmlAttribute:表示一個元素的屬性

            下面是一個簡單的例子:

            <?xml version="1.0" encoding="utf-8" ?>

            <!-This is only a sample-->

            <book>

            ?????? <name>TinyXml How To</name>

            ?????? <price unit=”RMB”>20</price>

            ?????? <description>Some words…</description>

            </ book >

            整個文檔,對應TiXmlDocument

            book,name,price, description,都對應TiXmlElement

            第一行對應一個TiXmlDeclaration

            第二行對應一個TiXmlComment

            “TinyXml How To”對應一個TiXmlText

            unit則是price的一個TiXmlAttribute

            這些類與XML文件中的相應元素都有很好的對應關系,因此相信參照TinyXml的文檔,可以很容易的掌握各個方法的使用。

            2.??需要注意的問題

            各類之間的轉換

            由于各個節點類都從TiXmlNode繼承,在使用時常常需要將TiXmlNode*類型的指針轉換為其派生類的指針,在進行這種轉換時,應該首先使用由TiXmlNode類提供的一系列轉換函數,如ToElement(void),而不是c++的dynamic_cast

            檢查返回值

            由于TinyXml是一個非校驗的解析器,因此當解析一個文件時,很可能文件并不包含我們預期的某個節點,在這種情況下,TinyXml將返回空指針。因此,必須要對返回值進行檢查,否則將很容易出現內存訪問的錯誤。

            如何重頭建立一個XML文件

            先建立一個TiXmlDocument對象,然后,載入某個模板,或者直接插入一個節點作為根節點,接著就可以像打開一個已有的XML文件那樣對它進行操作了。

            四、總結

            TinyXml最大的特點就是它很小,可以很方便的靜態連接到程序里。對于像配置文件、簡單的數據文件這類文件的解析,它很適合。但是由于它是非驗證的,因此需要在程序里做許多檢查工做,加重了程序編寫的負擔。因此對于復雜的XML文件,我覺得最好還是用驗證的解析器來處理。
            Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=477335

            posted @ 2006-01-15 15:19 張沈鵬 閱讀(2376) | 評論 (6)編輯 收藏
             
            提取未確定數目的參數
            在標準庫的<cstdarg>中專門提供一組宏來訪問它們.
            例:
            void error(int severity ...)
            {
             va_list ap;
             //用va_start初始化ap,第二個參數是函數的最后一個有名的形式參數的名字
             va_start(ap,severity);
             for(;;){
              //宏va_arg是按順序提取各個無名參數,第二個參數是假定的該無名參數的類型
              chap* p = va_arg(ap,char*);
              if(p==0)break;
              cerr<<p<<' ';
             }
             va_end(ap);//調用va_start后必須用va_end退出
             cerr<<'n';
             if(severity) exit(severity);
            }
            posted @ 2006-01-14 21:31 張沈鵬 閱讀(224) | 評論 (0)編輯 收藏
             
            網頁中可以用,將來也可以用的XUL的程序中去

            http://free5.ys168.com/?ak747

            下的XUL的文件夾
            將來可以在XUL程序中使用,下一步的改進計劃是成為類似Windows Media Player五個星標。
            posted @ 2006-01-11 14:05 張沈鵬 閱讀(271) | 評論 (0)編輯 收藏
            僅列出標題
            共7頁: 1 2 3 4 5 6 7 
             
            影音先锋女人AV鲁色资源网久久 | 久久婷婷五月综合97色一本一本| 人妻丰满?V无码久久不卡| 亚洲国产小视频精品久久久三级| 久久久精品国产| 国产精品久久久久9999高清| 99久久国产免费福利| 漂亮人妻被中出中文字幕久久| 少妇高潮惨叫久久久久久| 亚洲精品高清久久| 97精品国产97久久久久久免费 | 亚洲中文字幕伊人久久无码| 日韩精品久久无码中文字幕| 99久久国产主播综合精品| 久久精品中文字幕一区| 91亚洲国产成人久久精品| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 久久夜色精品国产亚洲| 亚洲国产精品热久久| 蜜臀av性久久久久蜜臀aⅴ| 久久青青草原精品国产不卡| 久久99久久99小草精品免视看 | 色老头网站久久网| 国产精品永久久久久久久久久| 亚洲欧美日韩中文久久| 亚洲午夜精品久久久久久浪潮 | 久久国产精品成人片免费| 一本色道久久综合狠狠躁篇| 国产精品一区二区久久精品无码 | 久久精品国产只有精品66 | 久久久久无码精品国产不卡| 亚洲国产精品无码久久九九| 精品久久久久久国产牛牛app| 国产婷婷成人久久Av免费高清 | 久久精品国产亚洲AV不卡| 色噜噜狠狠先锋影音久久| 精品国产91久久久久久久| 久久久久久综合一区中文字幕| 久久精品国产亚洲av麻豆小说 | 久久综合丁香激情久久| 久久精品国产半推半就|