2006-12-01から1ヶ月間の記事一覧

AccessとMSDE

http://www.sqlpassj.org/bunkakai/begin/series/default.aspx

分割コンパイルの仕方

すべてのクラスの宣言部分を「クラス名.h」のファイルに入れる すべてのクラスの定義部分を「クラス名.cpp」のファイルに入れる クラスの定義部分の先頭に「#include "クラス名.h"」を入れる クラスを使うソース・ファイルの先頭に「#include "クラス名.h"」…

クラス宣言でインライン関数を使ったプログラム

#include <iostream> class ITest{ private: int a; public: int get() {return a;} void set(int aa) {a = aa;} }; int main() { ITest t; t.set(15); std::cout << t.get(); return 0; }inline 関数名(引数) {内容} クラスのメンバー関数をインライン関数として定義</iostream>…

クラスのメンバー関数にconstを指定したプログラム

#include <iostream> class CTest{ private: int a; public: int get() const; void set(int aa); }; int CTest::get() const { return a; } void CTest::set(int aa) { a = aa; } int main() { CTest c; c.set(7); std::cout << c.get(); return 0; }constのついたメ</iostream>…

関数の仮引数にconstを使ったプログラム

#include <iostream> void mul2(int * const a) { *a *= 2; } int main() { int x = 3; int *px = &x; mul2(px); std::cout << x; return 0; }わざわざconstを使うことで、この関数内でポインタの値が変更されない(できない)ことを、関数のユーザーやコンパイラに伝え</iostream>…

const宣言をポインタと一緒に使う

const int *p; int * const p; const int * const p; ポインタが指す先に格納されている値を変更できないconst宣言 ポインタ自体の値を変更できないconst宣言 ポインタが指す先に格納されている値も、ポインタ自体の値も変更できない

STLに含まれている代表的なコンテナ

コンテナ名 表現するデータ構造 特徴 vector 単純な(配列的な)リスト 配列のように要素にアクセスできるがリスト演算は遅い list リスト 一定時間でリスト演算できるが、配列のようには要素にアクセスはできない stack スタック 最後に入った要素が最初に出…

STLのvectorクラスを利用して、リスト構造のデータを処理する

#include <iostream> #include <vector> using namespace std; int main() { int d; vector<int> v; //メインループ while(1){ cout << "数値を入力してください(0で終了): "; cin >> d; if(d == 0) break; //リストにデータを追加 v.push_back(d); //リストにのデータを表示 cout <</int></vector></iostream>…

クラスにもテンプレートをつかう

template<class T> class Point { public: Point(); Point(T sx, T sy); T x, y; }; template<class T> Point<T>::Point() { x = 0; y = 0; } template<class T> Point<T>::Point(T sx, T sy) { x = sx; y = sy; }</t></class></t></class></class>

テンプレートを使う

template<class T> T minimum(T a, T b) { return (a < b) ? a : b; }</class>

(条件) ? A : B について

int minimum(int a, int b) { return (a < b> ? a : b; } ? より前の条件 (a

例外の使い方

#include <iostream> using namespace std; const int ERROR = 1; double divide(double a, double b) { if(b == 0) throw ERROR; return a / b; } int main() { double a, b, c; cout << "空白で区切って数を2つ入力してください: "; cin >> a >> b; try{ c = divide(</iostream>…

CORBAとは

CORBA(Common Object Request Broker Architecture)とは、分散オブジェクト環境でオブジェクト同士がメッセージを交換するための標準仕様のことである。CORBAには、次の三つの特徴がある。 プラットフォームからの独立 特定のプラットフォームに依存せず、…

Pointクラスで+演算(二項)を使えるようにしたプログラム

#include <iostream> class Point2{ public: Point2(int ax = 0, int ay = 0); Point2 operator+(Point2 &a); int x, y; }; Point2::Point2(int ax, int ay) { x = ax; y = ay; } Point2 Point2::operator+(Point2 &a) { return Point2(x + a.x, y + a.y); } std::ostr</iostream>…

演算子をクラスで再定義する

#include <iostream> class IncChar { public: IncChar(char ac = 'a'); IncChar &operator++(); char c; }; IncChar::IncChar(char ac) { c = ac; } IncChar &IncChar::operator++() { c++; if(c > 'z') c = 'a'; return *this; } int main() { IncChar incchar('t');</iostream>…

リファレンス(参照)の動作を確認するプログラム

#include <iostream> int c = 0; void inc(int &x) { x++; } int &ref_c() { return c; } int main() { int a = 3; int &ra = a; std::cout << "a = " << a << "\n"; ra = 15; std::cout << "a = " << a << "\n"; int b = 4; std::cout << "b = " << b << "\n"; inc(b)</iostream>…

多様性(ポリモーフィズム)実現する仮想関数

#include <iostream> #include "point.cpp" #include "canvas.cpp" #include "shape.cpp" #include "rect.cpp" #include "triangle.cpp" #include "square.cpp" int main() { Canvas c; Shape *shape[3]; Rect r(5, 5, 20, 10); shape[0] = &r; Triangle t(1, 18, 16, </iostream>…

派生派クラス型ポインタを基底クラス型ポインタに変換するプログラム

#include <iostream> class Base{ public: void showName(); }; void Base::showName() { std::cout << "I am Base.\n"; } class Derived : public Base{ public: void showName(); }; void Derived::showName() { std::cout << "I am Derived.\n"; } int main() { Bas</iostream>…

tracert yahoo.co.jp

D:\cp>tracert yahoo.co.jp Tracing route to yahoo.co.jp [203.216.235.201] over a maximum of 30 hops: 1 3 ms 3 ms 3 ms 192.168.0.1 2 58 ms 29 ms 29 ms 10.249.8.1 3 52 ms 29 ms 29 ms 10.249.255.2 4 30 ms 29 ms 29 ms 211.132.120.1 5 57 ms 29 m…

同名のメンバー関数がある時は、派生クラスのメンバー関数が優先されることを示すプログラム

#include <iostream> class Base{ public: void showName(); }; void Base::showName() { std::cout << "I am Base.\n"; } class Derived : public Base{ public: void showName(); }; void Derived::showName() { std::cout << "I am Derived.\n"; } int main() { Der</iostream>…

IT用語辞典 e-Words

http://e-words.jp/ 用語辞典

UML(Unified Modeling Language)とは - IT用語辞典 e-Words

オブジェクト指向のソフトウェア開発における、プログラム設計図の統一表記法。Rational Software社のGrady Booch氏、James Rumbaugh氏、Ivar Jacobson氏の3人によって開発された。従来、オブジェクト指向設計の表記法は50以上の規格が乱立していたが、1997…

CASE(上流CASEツール)とは - IT用語辞典 e-Words

「コンピュータ支援ソフトウェア工学」の略。システム開発支援ツールと開発方法論の統合、システム開発作業の効率化を目的としている。CASEツールと呼ばれるソフトウェアを用い、ソフトウェア開発の多くの局面を自動化することができる。 CASEツールには、計…

マインスイーパーゲーム

#include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; //-----------地雷クラス------------------- //地雷を表現するクラス class Mine { int x, y; static bool map[5][5]; public: enum MSTAT{MISS, NEAR, HIT}; Mine(); MSTAT check(int cx, i</string></ctime></cstdlib></iostream>…

enum/列挙型の例

#include <stdio.h> enum TYUMON {OMUSUBI, ODEN, SABANONITUKE, YASAIITAME}; int main() { enum TYUMON tyu1 = ODEN; printf("%d\n", tyu1); return 0; }実行結果 1</stdio.h>

クラスの例

#include <iostream> using namespace std; class Color { private: int r, g, b; public: void setRGB(int ar, int ag, int ab); void getRGB(int* ar, int* ag, int* ab); }; void Color::setRGB(int ar, int ag, int ab) { r = ar; g = ag; b = ab; } void Color::g</iostream>…

名前空間の指定

a#include <iostream> int main() { std::cout << "Hello, Hello, This is the first program" "in C++.\n"; return 0; }#include <iostream> using namespace std; int main() { cout << "Hello, Hello, This is the first program" "in C++.\n"; return 0; }</iostream></iostream>

Cの構造体とC++のクラスの違い

#include <stdio.h> /* i時刻を格納する構造体 */ typedef struct { int hour; int minute; int second; } Time; /*時刻をセットする関数*/ void Time_set(Time *t, int h, int m, int s) { t->hour = h; t->minute = m; t->second = s; } /*時刻を進める関数*/ void </stdio.h>…

関数の多重定義

#include <iostream.h> void printtype(int num) { cout << num << "はintです。\n"; } void printtype(double num) { cout << num << "はdoubleです。\n"; } int main() { int a = 3; double b = 5.5; printtype(a); printtype(b); return 0; }実行結果 3はintです。 5.</iostream.h>…

cin関数の例

#include <iostream.h> #include <string.h> // 本の数 const int MAX = 5; // 構造体の宣言 struct book { string name; int yen; }; int main() { // 変数の宣言 int maxID, maxYen = 0; book buybook[5]; for(int id = 0; id < MAX; id++){ cout << id + 1 << "番目の本の"; cou</string.h></iostream.h>…