• <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 彈杯一笑 閱讀(230) | 評論 (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 彈杯一笑 閱讀(873) | 評論 (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 彈杯一笑 閱讀(420) | 評論 (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 彈杯一笑 閱讀(400) | 評論 (0)編輯 收藏

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

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(7)

            隨筆檔案(4)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产久精国产| 久久久久无码中| 久久国产乱子伦免费精品| 无码AV波多野结衣久久| 国产精品久久成人影院| 国产精品99久久久久久www| 亚洲人成网站999久久久综合| 亚洲精品国产第一综合99久久| 色偷偷88888欧美精品久久久| 国产精品天天影视久久综合网| 久久人人爽人人爽人人片AV东京热| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 一本一道久久综合狠狠老| 97热久久免费频精品99| 久久夜色精品国产| 91精品国产色综合久久| 亚洲国产高清精品线久久| 久久久久99精品成人片欧美| 久久中文精品无码中文字幕| 99精品国产在热久久无毒不卡| 久久91精品国产91久久小草 | 中文字幕亚洲综合久久2| 亚洲精品无码久久久| 久久96国产精品久久久| 日韩av无码久久精品免费| 内射无码专区久久亚洲| 99久久国语露脸精品国产| 久久夜色精品国产亚洲| 久久笫一福利免费导航| 久久精品国产精品亜洲毛片| 久久精品国产精品亚洲精品 | 99久久做夜夜爱天天做精品| 久久国产高清字幕中文| 久久夜色精品国产网站| 五月丁香综合激情六月久久| 久久久久亚洲av成人网人人软件 | 久久精品国产亚洲AV无码娇色| 一级A毛片免费观看久久精品| 亚洲精品99久久久久中文字幕| 久久久噜噜噜久久| 一本一本久久a久久精品综合麻豆|