• <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>
            隨筆-9  評論-5  文章-0  trackbacks-0
              2008年10月24日
            使用結構體作為返回值,可以使得函數的調用更加靈活和方便。

            /************************************************************************/
            /* 使用結構體作為返回值                                                                     */
            /************************************************************************/
            #include 
            "iostream.h"
            struct student
            {
                
            int id;
                
            char name[20];
                
            int age;
                
            char department[20];
                
            float gpa;
            }
            ;

            student init();                
            //初始化,返回一個student的結構
            void display(student arg);    //顯示結構體

            int main()
            {
                display(init());    
            //init()返回的是一個student結構體
                return 0;
            }


            void display(student arg)
            {
                cout
            <<"學號:"<<arg.id<<"  姓名:"<<arg.name<<"  年齡"<<arg.age<<"  專業:"<<arg.department<<"  成績:"<<arg.gpa<<endl;
            }

            student init()
            {
                student s1 
            = {3221,"Tom",18,"Computer",86.33};    //初始化一個student的結構體
                return s1;                                        //返回一個student的結構體s1
            }
            posted @ 2008-10-24 12:46 longhr 閱讀(3812) | 評論 (1)編輯 收藏

            /************************************************************************/
            /* 數組直接選擇排序的簡單實現,沒有輸入輸出模塊                                                                     */
            /************************************************************************/
            #include 
            "iostream.h"

            void sort(int a[],int size);
            int main()
            {
                
            int num[]={21,12,45,34,67,30,21,3,56,98,99};

                sort(num,
            sizeof(num)/sizeof(int));

                
            return 0;
            }

            void sort(int a[],int size)
            {
                
            for (int i=0;i<size;i++)
                
            {
                    
            int min=a[i],min_i=i;    //假設首元素是最小的,min_i表示是最小數字i坐標
                    for (int j= i;j<size;j++)
                    
            {
                        
            if (a[j]<min)
                        
            {
                            min
            =a[j];
                            min_i 
            = j;
                        }

                    }

                    
            int temp = a[i];    //a[min_i]為找到的值最小的元素,要把最小的元素放在a[i]中
                    a[i] = a[min_i];
                    a[min_i]
            = temp;
                }

            }
            posted @ 2008-10-24 11:20 longhr 閱讀(479) | 評論 (0)編輯 收藏

            /************************************************************************/
            /* 簡單的求數組中最大值的函數調用方法                                                                     */
            /************************************************************************/
            #include 
            "iostream.h"
            int max(int a[],int size);
            int main()
            {
                
            int num[]={12,34,32,45,65,99,33,56,58,97};
                cout
            <<max(num,sizeof(num)/sizeof(int))<<endl;
                
            return 0;
            }


            int max(int a[],int size)
            {
                
            int max = 0;
                
            for (int i=0;i<size;i++)
                
            {
                    
            if(max<a[i])
                        max
            =a[i];
                }

                
            return max;
            }
            posted @ 2008-10-24 10:41 longhr 閱讀(2507) | 評論 (0)編輯 收藏
              2008年10月23日

            Visual C++ 插件系列介紹

            說到Visual C++的插件,大家可能只有想到Visual Assist吧。天真!行內開發的插件可只有這個!?下面介紹一下vc6.0的其他插件。

            Visual Assist(強烈推薦)
            網址:http://www.wholetomato.com/
            功能:VA從5.0一直到現在的VAX,功能越來越強大,除了以前版本中的自動識別各種關鍵字,系統函數,成員變量,自動給出輸入提示,自動更正大小寫錯誤,自動標示錯誤等等以外,最新的版本中還在WorkSpace窗口中加入一個VA View,可以更方便的查找工程中的文件、類和變量。


            WndTabs(強烈推薦)
            網址:http://www.wndtabs.com/
            功能:WndTabs主要是在編輯窗口中顯示了所有已經打開的文件,在VC中能夠更方便的操作這些文件,比如修改文件屬性,copy文件路徑、文件名等,并且還開放源代碼,你要是愿意的話,可以添加自己很興趣的功能。

            LineCounter
            網址: http://www.wndtabs.com/
            功能:用來統計整個工程的代碼行數,包括總行數、代碼行數、注釋行數、空行數等,并且對多個工程一起統計時,不會把相同的文件計算多次.

            Spelly
            網址:http://www.wndtabs.com/
            功能:一個拼寫檢查的插件,可以對整個文件或所選部分進行拼寫檢查,支持C/C++/C#, VB, Fortran 和HTML。

            SourceStyler C++
            網址:http://www.sourcestyler.com/
            功能:此插件是針對C++的一個格式化工具,可以針對自己的編碼習慣,選擇一種編碼風格,也可以自己定義,而且定義非常詳細,有表達式、指針、模板、類、枚舉等十幾種,肯定能滿足你的需要。

            Numega BoundsChecker(強烈推薦)
            功能:是針對Visual C++6.0應用程序的最為全面的錯誤檢測工具。BoundsChecker 能自動指出靜態,堆棧內存錯誤和資源泄漏問題。BoundsChecker 能夠校驗最新的 Windows APIs,包括 ActiveX, DirectX, OLE/COM, ODBC等等。能夠發現與 Windows 平臺兼容性。

            BCGControlBar Library
            功能:非常好的一套應用于vc6的界面擴展類庫,輕松的作出 vc2003 的界面。并且給了各種界面例子,如vc.net、outlook、更換皮膚等等。

            Comment Wizard
            網址:http://www.shnenglu.com/fwxjj/
            功能:Visual C++插件,提供了Visual C++源代碼注解標準化與自動化功能。在它的幫助下,您可快速創建標頭文件信息注解,文件中模塊注解, C++處理方式,以及C語言功能與歷史校正功能注解,等等。

            String watch Microsoft Visual Studio add-in
            網址:http://www.codeguru.com/cpp/v-s/devstudio_macros/debugging/article.php/c5989
            功能:調試時查看字符串的。

            Tabbar插件
            網址:http://www.winmsg.com/cn/tabbar.htm
            功能:顯示多tab的插件



            轉載自:http://bbs.xgcollege.com/read.php?tid-1138.html

            posted @ 2008-10-23 22:37 longhr 閱讀(4250) | 評論 (1)編輯 收藏


            /************************************************************************/
            /* 輸出常用的ASCII碼表                                                  */
            /************************************************************************/
            #include 
            "iostream.h"
            int main()
            {
                
            for (int i=32;i<=127;i++)
                
            {
                    cout
            <<(char)i; //強制類型轉換
                }

                
            return 0;
            }


            美化一些的版本,這樣看起來輸出更好看一些

            #include "iostream.h"
            #include 
            "iomanip.h"//為了使用setw()
            int main()
            {
                
            char temp;
                
            for (int i=32;i<=127;i++)
                
            {
                    temp 
            = i;
                    cout
            <<setw(2)<<temp; //setw(n) 設域寬為n個字符
                    if (i%16==15)
                    
            {
                        cout
            <<endl;
                    }

                }

                
            return 0;
            }
            輸出的結果如下
               ! " # $ % & ' ( ) * + , - . /
             0 1 2 3 4 5 6 7 8 9 : ; < = > ?
             @ A B C D E F G H I J K L M N O
             P Q R S T U V W X Y Z [ \ ] ^ _
             ` a b c d e f g h i j k l m n o
             p q r s t u v w x y z { | } ~ 
            Press any key to continue

            posted @ 2008-10-23 21:11 longhr 閱讀(802) | 評論 (0)編輯 收藏
            一直對于遞歸的使用不太了解,這樣寫出一個最簡單的算法,這樣就可以知道怎么具體使用了。把公式套進去就可以了。


            #include "iostream.h"
            /************************************************************************/
            /* 使用遞歸最簡單的程序,實現f(n)=2*f(n)+3                              */
            /************************************************************************/
            int f(int i);
            int main()
            {
                
            for (int i=1;i<=8;i++)
                
            {
                    cout
            <<"f"<<"("<<i<<")"<<"="<<f(i)<<endl;
                }

                
            return 0;
                
            }


            int f(int i)
            {
                
            if (i ==1)
                
            {
                    
            return 1;
                }

                
            else
                
            {
                    
            return 2*f(i-1)+3;
                }

            }
            posted @ 2008-10-23 20:57 longhr 閱讀(675) | 評論 (0)編輯 收藏
            能被4整除是閏年,但是特殊情況是整百年要被400整除才行  


            #include "iostream.h"

            int main()
            {
                
            int year;
                cin
            >>year;
                
            if (year%4 ==0 && year%100!=0 || year%400 ==0)
                
            {
                    cout
            <<"是閏年(leapyear)";
                }

                
            else
                
            {
                    cout
            <<"不是閏年";
                }

                
            return 0;
            }
            posted @ 2008-10-23 17:21 longhr 閱讀(1410) | 評論 (3)編輯 收藏
            類似這樣的三角形


            *******
            ******
            *****
            ****
            ***
            **
            *
            #include "iostream.h"
            int main()
            {
                
            for (int i=7;i>0;i--)
                
            {
                    
            int p=i;
                    
            while (p--)
                    
            {
                        cout
            <<"*";
                    }

                    cout
            <<"\n";
                }

                
            return 0;
            }

            輸出這樣的三角形類似
            *
            **
            ***
            ****
            *****
            #include "iostream.h"
            int main()
            {
                
            for (int i=1;i<=5;i++)
                
            {
                    
            int p=i;
                    
            while (p--)
                    
            {
                        cout
            <<"*";
                    }

                    cout
            <<"\n";
                }

                
            return 0;
            }
            類似這樣的等腰三角形
                *
                **
               ***
               ****
              *****
              ******
             *******
             ********
            *********
            **********
            #include "iostream.h"
            int main()
            {
                
            int sum = 10;
                
            for (int i=1;i<=sum;i++)
                
            {
                    
            int p=(sum -i)/2;
                    
            while (p--)
                    
            {
                        cout
            <<" ";
                    }

                    p
            =i;
                    
            while (p--)
                    
            {
                        cout
            <<"*";
                    }

                    cout
            <<"\n";
                }

                
            return 0;
            }

                     *
                    * *
                   * * *
                  * * * *
                 * * * * *
                * * * * * *
               * * * * * * *
              * * * * * * * *
             * * * * * * * * *
            * * * * * * * * * *

            #include "iostream.h"
            int main()
            {
                
            int sum = 10;
                
            for (int i=sum;i>=0;i--)
                
            {
                    
            int p=i;
                    
            while (p--)
                    
            {
                        cout
            <<" ";
                    }

                    p
            =sum -i;
                    
            while (p--)
                        
            {
                            cout
            <<"";
                        }

                    cout
            <<"\n";
                }

                
            return 0;
            }

            posted @ 2008-10-23 16:37 longhr 閱讀(1556) | 評論 (0)編輯 收藏
            采用指針的方法
            #include <stdio.h>
            #include 
            "iostream"
            #include 
            <string.h>
            int main()
            {
                
            char *src = "hello";
                
            int len= strlen(src);
                
            char *dest = (char *)malloc(len+1);
                
            char *d= dest;
                
            char *= &src[len-1];
                len 
            = 1;
                
            while (len--)
                
            {
                    
            *d++=*s--;
                }

                
            *= 0;    //否則會亂碼
                printf("%s\n",dest);
                free(dest);
                
            return 0;
            }

            采用數組的方法
            #include <stdio.h>
            #include 
            "iostream"
            #include 
            <string.h>
            int main()
            {
                
            char src[] = "hello";
                
            int len = strlen(src);
                
            char temp;
                
            for (int i=0;i<len/2;i++)
                
            {
                    temp 
            = src[i];
                    src[i] 
            = src[len-i-1];
                    src[len
            -i-1= temp;
                }

                printf(
            "%s\n",src);
                
            return 0;
            }

            參考的代碼
            int main(){
            char* src = "hello,world";
            int len = strlen(src);
            char* dest = (char*)malloc(len+1);//要為\0分配一個空間
            char* d = dest;
            char* s = &src[len-1];//指向最后一個字符
            while( len-- != 0 )
            *d++=*s--;
            *= 0;//尾部要加\0
            printf("%s\n",dest);
            free(dest);
            // 使用完,應當釋放空間,以免造成內存匯泄露
            return 0;
            }


            #include 
            <stdio.h>
            #include 
            <string.h>
            main()
            {
            char str[]="hello,world";
            int len=strlen(str);
            char t;
            for(int i=0; i<len/2; i++)
            {
            t
            =str[i]; 
            str[i]
            =str[len-i-1]; str[len-i-1]=t;
            }

            printf(
            "%s",str);
            return 0;
            }

            posted @ 2008-10-23 16:05 longhr 閱讀(4231) | 評論 (0)編輯 收藏
            僅列出標題  
            久久线看观看精品香蕉国产| 无码精品久久一区二区三区| 亚洲午夜久久久久久久久电影网 | 色偷偷88888欧美精品久久久| 久久天天躁夜夜躁狠狠| 久久久久亚洲av无码专区导航 | 亚洲精品乱码久久久久久| 久久久久人妻一区二区三区vr | 久久无码中文字幕东京热| 久久精品午夜一区二区福利| 国产精品99久久久久久猫咪| 亚洲精品无码专区久久久| 国内精品久久久久久麻豆| 伊人久久大香线焦AV综合影院| 久久精品国产99国产精品澳门| 亚洲欧洲中文日韩久久AV乱码| 国产精品久久久久久| 无码任你躁久久久久久老妇| 久久国产亚洲精品麻豆| 久久国产精品无| 国产精品亚洲综合专区片高清久久久 | 久久亚洲精品中文字幕| 久久成人18免费网站| 国产精品久久久久影视不卡| 久久免费视频1| 午夜福利91久久福利| 97久久精品人人做人人爽| 72种姿势欧美久久久久大黄蕉| 久久人人爽人人爽人人片AV麻烦| 久久精品视频91| 国产精品免费久久| 国产69精品久久久久9999| 久久99精品综合国产首页| www.久久热.com| 99久久久精品免费观看国产| 97精品伊人久久久大香线蕉| 久久婷婷人人澡人人| 无码8090精品久久一区| 亚洲美日韩Av中文字幕无码久久久妻妇 | 青青草原1769久久免费播放| 国产精品9999久久久久|