Time of Update: 2015-04-15
標籤:c++ 派生 繼承 #include<iostream>using namespace std;class Base{ int x;public: Base(int a) { x = a;//記得給私人成員賦初值,沒有的話會是隨機值 cout<<"constructing Base "<<
Time of Update: 2015-04-16
標籤:因為老師要求用TC所以是在TC上運行……因為上課講的課下就忘了:雖然老師用的是2.0,以下是在TC3.0上啟動並執行,記下來以免哪天又記憶損傷【主檔案-cwww1.cpp】 ↑主檔案:a,b,c為全域變數,plus為全域函數,檔案名稱:cww1.cpp【函數檔案-cwww2.cpp】↑檔案2:extern那個可以無視……寫不寫都一樣,檔案名稱:cww2.cpp【project檔案-cwww.prj】&ua
Time of Update: 2015-04-16
標籤:第一篇博文,希望不是最後一篇。o(∩_∩)o 哈哈接下來幾篇博文會由淺到深地介紹 STL 超好用的順序容器。 容器: 就是一些特定類型對象的集合。 順序容器: 定義:順序容器是容器的一類。該類容器中,對象(元素)在 容器中的位置 與加入容器的順序相對應,不依賴元素的值。
Time of Update: 2015-04-15
標籤:#include <iostream>#include <stdlib.h>using namespace std;int sum(int a,int b){return (rand()%(b-a)+a+1);}void Grial(int a[],int x,int y){if(x>=y)return ;int i=x;int j=y;int temp;int b=sum(i,j);//求取隨機值.int
Time of Update: 2015-04-15
標籤:選擇結構 c程式設計 // 輸入兩個實數,按代數值由小到大的順序輸出這兩個數#include <stdio.h>int main(){int a,b;printf("請輸入兩個數:");scanf("%d%d",&a,&b);if(a > b)printf("由小到大:%d
Time of Update: 2015-04-15
標籤:d語言 c語言 互相調用 d語言二進位相容 很多語言都可以實現與C語言的互相調用,但我覺得D語言做的更好些,D與C的相容是二進位相容,不是在源碼上的相容,也就是說編譯手的二進位檔案是可以互相連結的。廢話不多說,直接上例子一、在D語言中調用C函數首先是準備一個C函數// foo.c#include <stdio.h>int&n
Time of Update: 2015-04-15
標籤:Colleciton<Object>並不是任意類型的Collection的超類。 那麼什麼是所有Colleciton類型的超類型呢?它是Collection<?>這樣一個類型,讀作“未知Colleciton”。它的意思是說Colleciton的元素類型可以匹配任意類型,我們把它稱作萬用字元類型,我們這樣寫: void printCollection(Colleciton<?> c){ for (Object
Time of Update: 2015-04-15
標籤:#include <windows.h>#include <stdio.h>#include <process.h>int g_ntotal = 100;int g_thread_counter;int g_sum;//計算結果HANDLE g_thread_lock;//HANDLE 被類型定義為 void *struct THREAD_DATA{ int num_threads; int thread_id;};void
Time of Update: 2015-04-15
標籤:#include <stdio.h>int sump(int *, int *);int main(void){ int array[] = {1, 3, 4, 7, 8}; printf("total=%d\n", sump(array,array+5)); return 0;}int sump(int * start, int * end){ int total = 0; while(start<end) total +=
Time of Update: 2015-04-14
標籤:1. C語言中無符號數與有符號數 unsigned int a = 6;int b = -20;printf("a+b = %d\n",a+b); #輸出-14printf("a+b %s \n",(a+b)>0 ? "> 0":" < 0"); #輸出a+b > 0有符號數和無符號數在進行比較運算時(==,>=,<=,>,<)
Time of Update: 2015-04-14
標籤:我們知道C++裡 virtual函數可以用來實現多態。繼承類可以實現自己的功能來覆蓋基類。比如下面這段代碼#include<iostream>#include<string>using namespace std;class BaseA{ public: BaseA(string n):name(n){} string getName() const; virtual void showMyName() const; string name;
Time of Update: 2015-04-16
標籤: 靜態建構函式是C#的一個新特性,其實好像很少用到。不過當我們想初始化一些靜態變數的時候就需要用到它了。這個建構函式是屬於類的,而不是屬於哪裡執行個體的,就是說這個建構函式只會被執行一次。也就是在建立第一個執行個體或引用任何靜態成員之前,由.NET自動調用。 class SimpleClass{ // Static constructor static Si
Time of Update: 2015-04-16
標籤:c# labmda lambda運算式 本篇我們來討論C#中的Lambda運算式。本篇會使用上一篇文章:C#委託中的Person類,代碼如下public delegate void MyDelegate();public class Person{ public string Name { get; set; } public int Age { get; set; }
Time of Update: 2015-04-15
標籤:public37.C#檔案操作之檔案讀寫 前面講了FileStream類的檔案操作,現在有專門為檔案讀寫的兩個類,StreamRead和StreamWriter。1.StreamReader類。a.常用的方法。Read():用於讀取輸入資料流中的下一個字元,並使當前流的位置提升一個字元。ReadLine():用於從輸入資料流中讀取一行字元。ReadToEnd():用於從當前位置讀到檔案結束。2.StreamWriter類。Write();WriteLine();與上面
Time of Update: 2015-04-14
標籤:1、擷取集合裡泛型型別的執行個體對象List<T> list;Type[] types = list.GetType().GetGenericArguments();foreach(var type in types){ System.Activator.CreateInstance(type);}雖然是個數組,但是此處好像只有一個值,所以object obj
Time of Update: 2015-04-14
標籤:標籤 項目 使用者 29.ListView控制項 ListView控制項用於顯示項目的列表視圖。每條資料都是一個ListItem類型的對象。
Time of Update: 2015-04-14
標籤:在寫程式的過程中,有時候我們需要添加一些log資訊,這個時候,可以採用下面的方法來實現。 public static void WriteLog(string ExtraMsg, Exception e) { string logPath = Environment.CurrentDirectory + "\\Log"; if (!Directory.Exists(logPath)) {
Time of Update: 2015-04-16
標籤:建議和規則 建議: 用內嵌函式或靜態函數代替與函數相似的宏 在宏參數名兩邊加上括弧 宏其他清單應該加上括弧 應該使用typedef定義編碼類別型 不要複用標準標頭檔名 理解串連標記或執行字串化時的宏替換 把標頭檔放在包含防護條件中 避免使用連續的問號 保證標頭檔名唯一http://www.zjshenghuo.com/article-78643-1.htmlhttp://www.zjshenghuo.com/article-78642-1.htmlhttp://www.
Time of Update: 2015-04-16
標籤: extern 的作用是延深檔案中變數或者函數的可訪問性。主要對全域變數和全域函數其作用。下面是驗證的代碼: a.c: #include<stdio.h> #include<stdlib.h> int value; //定義一個全域變數 void show() { printf("show something\n"); } b.c: extern int value; void b_show() { value = 100;
Time of Update: 2015-04-14
標籤:algorithm 數論 貪心 codeforces 526 c Om Nom and Candies題意:給出一個容量為c背包,兩種物品的價值hr,hb和容量cr,cb,求裝滿背包能裝的最大價值。限制:1 <= c,hr,hb,wr,wb <= 1e9思路:剩餘系設第一種物品有x個,第二種物品有y個,則有:x*hr + y*hb <=