• <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>

            2009年5月21日

            struct 與class 的區別

            以前一直沒有明白struct結構體與class類 的區別:
            (1)
                 名字不同一個是struct,一個是class
            (2)
              默認的訪問屬性不同 struct是public,class 是private

            posted @ 2009-05-21 22:19 彈杯一笑 閱讀(229) | 評論 (0)編輯 收藏

            2009年5月12日

            C/C++: 控制臺輸入密碼, 用*號掩藏

            //此代碼有一個網友所寫

            #include 
            <iostream>
            #include 
            <conio.h>

            /**
             * 秘密在于conio.h中的getch()從鍵盤中讀取字符時,并不會在屏幕上輸出已經輸入的字符,
             * 而用一個putch('*')來哄騙,代表已經輸入一個字符
             * 怪不得這個頭文件要叫conio.h, con的意思就有哄騙,看來就是由此而來.
             
            */


            using namespace std;

            int main() {
                    
            char* password;
                    
            char* passwordConfirm;

                    
            int length = 4;
                    password 
            = new char[length + 1];
                    passwordConfirm 
            = new char[length + 1];

                    
            char* p = NULL;
                    
            int count = 0;

                    cout 
            << "Input password : ";
                    p 
            = password;
                    count 
            = 0;
                    
            //fflush(stdin);
                    while (((*= getch()) != 13&& count < length) {
                            
            // 這里不是'\n'(10), new line
                            
            // 而是'\r'(13), reback. 即是按下回車鍵,好像這個東西是linux的.
                            
            // 主要是與getch這個函數有關.
                            putch('*');
                            fflush(stdin);

                            p
            ++;
                            count
            ++;
                    }

                    password[count] 
            = '\0';

                    cout 
            << endl << "Confirm the password : ";
                    p 
            = passwordConfirm;
                    count 
            = 0;
                    
            //fflush(stdin);
                    while (((*= getch()) != 13&& count < length) {
                            putch(
            '*');
                            fflush(stdin);

                            p
            ++;
                            count
            ++;
                    }

                    passwordConfirm[count] 
            = '\0';

                    cout 
            << endl;
                    
            if (strcmp(password, passwordConfirm) == 0{
                            cout 
            << "The password is right." << endl;
                            cout 
            << password << endl;
                    }
             else {
                            cout 
            << "Confirm password fail." << endl;
                            cout 
            << password << endl << passwordConfirm << endl;
                    }


                    
            return 0;
            }


            posted @ 2009-05-12 10:44 彈杯一笑 閱讀(871) | 評論 (0)編輯 收藏

            2009年4月1日

            N皇后問題求解

                 摘要: //N皇后問題求解(此處為8皇后)   1#include <iostream>  2#include <cstdio>  3#include <ctime>  4#include <cmath>   ...  閱讀全文

            posted @ 2009-04-01 23:17 彈杯一笑 閱讀(418) | 評論 (0)編輯 收藏

            2009年3月30日

            如何設計一個范型算法

            // essential  c++
            向一個容器(比如 vector)中添加數字后,然后隨便輸入待比較的數字( int a ;),求找出在vector中比a大的數字,比a小的數字,和a相等的數字,或者是a的3倍,5倍等之類的數字的集合.

            //開始看下面的代碼之前,你是怎么思考的呢?你是不是覺得直接在里面寫個函數比較就是了?或者是其他的呢?

             1#include<iostream>
             2#include <vector>
             3#include <string>
             4using namespace std;
             5/*
             6* 單獨寫出相關的函數  如 比較,倍數之類的,后面調用 。
             7* 此處僅寫了小于和大于函數   其他的依次類推。
             8* 注意參數 與指針函數的匹配
             9*/

            10bool less_than(int v1,int v2)
            11{
            12     return v1<v2?true:false;
            13}

            14bool greater_than(int v1,int v2)
            15{
            16     return v1 > v2 ? true:false;
            17}

            18
            19vector<int> filter_ver1(const vector<int> &vec,int filter_value,bool(*pred)(int,int))         
            20
            21//個人覺得這個函數設置得很好,用到函數指針傳遞相關的函數。注意相關形參的匹配
            22{           
            23            vector<int> nvec;
            24            for(size_t ix = 0;ix != vec.size(); ++ix)
            25                    if(pred(vec [ix],filter_value))            //  調用相關函數進行操作
            26                    nvec.push_back(vec[ix]);           //滿足結果就保存
            27            return nvec;
            28}

            29int main()
            30{   
            31    int value;
            32    vector<int> ivec; 
            33    cout <<"請輸入數字:  "<<endl;
            34    while(cin >> value)
            35    ivec.push_back(value);
            36    cin.clear();             //使輸入流有效
            37    int ival;
            38    cout<<"請輸入你要比較數字: "<<endl;
            39    cin >>ival;
            40    vector<int> vec=filter_ver1(ivec,ival ,greater_than);  // 函數的調用  傳遞函數名即可
            41    vector<int>::iterator it=vec.begin();
            42    while(it!= vec.end())
            43               cout<<*it++<<"  ";
            44               cout<<endl;
            45
            46    system("pause");
            47    return 0;
            48}

            posted @ 2009-03-30 23:54 彈杯一笑 閱讀(399) | 評論 (0)編輯 收藏

            僅列出標題  
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(7)

            隨筆檔案(4)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久人妻精品一区三寸蜜桃 | 国产成人精品久久一区二区三区| 久久精品国产亚洲AV香蕉| 中文字幕久久波多野结衣av| 国产aⅴ激情无码久久| 国产成人久久精品区一区二区| 色综合久久综合网观看| 中文字幕精品无码久久久久久3D日动漫 | 久久久久久精品免费看SSS| 伊人久久大香线蕉av一区| 国产精品伊人久久伊人电影| 手机看片久久高清国产日韩| 久久成人国产精品| 国产免费久久精品丫丫| 久久久亚洲欧洲日产国码aⅴ| 久久精品中文字幕一区| 国产国产成人精品久久| 久久综合九色综合网站| 精品国产青草久久久久福利| 久久这里只有精品18| 亚洲午夜久久久影院| 久久国产精品无| 久久99精品国产麻豆婷婷| 人妻精品久久无码区| 久久精品国产亚洲AV无码娇色| 国产精品久久久久a影院| 亚洲AⅤ优女AV综合久久久| 久久无码国产| 一本一道久久a久久精品综合| 国产免费久久精品丫丫| 精品无码久久久久久久动漫| 99国产精品久久| 色综合久久久久网| 久久精品国产只有精品66 | 亚洲国产成人久久综合碰碰动漫3d | 久久久久久无码国产精品中文字幕 | 国内精品久久久久影院一蜜桃| 国产精品99久久精品| 一本久久a久久精品综合夜夜| 久久涩综合| 久久99精品久久久久子伦|