新版 明解C++入門編

Similar documents
解きながら学ぶC++入門編

明解C++

新・明解Java入門

新・明解C言語 実践編

新・明解C言語で学ぶアルゴリズムとデータ構造

新・明解Javaで学ぶアルゴリズムとデータ構造

新版明解C言語入門編

明解Java入門編

新版明解C言語 実践編

Javaによるアルゴリズムとデータ構造

基礎プログラミング2015

解きながら学ぶC++入門編

PowerPoint プレゼンテーション - 物理学情報処理演習

gengo1-2

PowerPoint Presentation

Microsoft Word - no15.docx

Microsoft Word - Cプログラミング演習(12)

Cプログラミング1(再) 第2回

プログラミング実習I

PowerPoint プレゼンテーション - 物理学情報処理演習

ソフトゼミC 第二回 C++の基礎

基礎プログラミング2015

Microsoft PowerPoint - program.ppt [互換モード]

C , C++ C C++ C++ C cpprefjp - C++ 1 C CUI 2.1 donothing.cpp 1

Microsoft PowerPoint - 3.ppt [互換モード]

2

Microsoft Word - 3new.doc

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

Taro-ファイル処理(公開版).jtd

Microsoft PowerPoint - 4.ppt [互換モード]

Microsoft PowerPoint ppt

明解Javaによるアルゴリズムとデータ構造

スライド 1

情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤

講習No.12

PowerPoint プレゼンテーション - 物理学情報処理演習

基礎プログラミング2015

JavaプログラミングⅠ

PowerPoint プレゼンテーション

JavaプログラミングⅠ

情報処理演習 B8クラス

解きながら学ぶC言語

8 / 0 1 i++ i 1 i-- i C !!! C 2

初歩のC言語ターミナル_2014_May.pages

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲

Microsoft PowerPoint - class2-OperatorOverLoad.pptx

Microsoft Word - Training10_プリプロセッサ.docx

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

Prog1_15th

Java講座

新・明解Javaで学ぶアルゴリズムとデータ構造

break 文 switch ブロック内の実行中の処理を強制的に終了し ブロックから抜けます switch(i) 強制終了 ソースコード例ソースファイル名 :Sample7_1.java // 入力値の判定 import java.io.*; class Sample7_1 public stati

解きながら学ぶJava入門編

Java プログラミング Ⅰ 3 回目変数 変数 変 数 一時的に値を記憶させておく機能型 ( データ型 ) と識別子をもつ 2 型 ( データ型 ) 変数の種類型に応じて記憶できる値の種類や範囲が決まる 型 値の種類 値の範囲 boolean 真偽値 true / false char 2バイト文

Microsoft PowerPoint - Compiler03note.pptx

char int float double の変数型はそれぞれ 文字あるいは小さな整数 整数 実数 より精度の高い ( 数値のより大きい より小さい ) 実数 を扱う時に用いる 備考 : 基本型の説明に示した 浮動小数点 とは数値を指数表現で表す方法である 例えば は指数表現で 3 書く

PowerPoint プレゼンテーション - 物理学情報処理演習

PowerPoint プレゼンテーション - 物理学情報処理演習

System.out.println("char : " + (int)character.min_value + "~" + (int)character.max_value); System.out.println("float : " + Float.MIN_VALUE + "~" + Flo

Microsoft PowerPoint - 03BNFScanner-print.ppt

Microsoft PowerPoint - 03BNFScanner.ppt [互換モード]

Prog1_6th

Microsoft Word - no103.docx

PowerPoint プレゼンテーション

講習No.1

6 関数 6-1 関数とは少し長いプログラムを作るようになると 同じ処理を何度も行う場面が出てくる そのたびに処 理を書いていたのでは明らかに無駄であるし プログラム全体の見通しも悪くなる そこで登場す るのが 関数 である 関数を使うことを 関数を呼び出す ともいう どのように使うのか 実際に見て

JavaプログラミングⅠ

数値計算

Microsoft Word - Cプログラミング演習(1)_2012

練習&演習問題

PowerPoint プレゼンテーション

Condition DAQ condition condition 2 3 XML key value

Microsoft PowerPoint - Compiler03.pptx

ポインタ変数

C言語によるアルゴリズムとデータ構造

Microsoft Word - DF-Salford解説09.doc

PowerPoint Presentation

新コンフィギュレータのフレームワークについて

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

kiso2-03.key

Microsoft PowerPoint - 12.ppt [互換モード]

Taro-ポインタ変数Ⅰ(公開版).j

JavaプログラミングⅠ

Microsoft PowerPoint - CproNt02.ppt [互換モード]

PowerPoint プレゼンテーション

プログラミング演習 土曜日(Q組)

Microsoft PowerPoint - 説明2_演算と型(C_guide2)【2015新教材対応確認済み】.pptx

* ライブラリ関数 islower(),toupper() を使ったプログラム 1 /* 2 Program : trupper.c 3 Student-ID : K 4 Author : TOUME, Kouta 5 Comments : Used Library function i

Microsoft PowerPoint - VBA解説1.ppt [互換モード]

Microsoft Word - Cプログラミング演習(3)

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

kiso2-09.key


PowerPoint Presentation

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

<4D F736F F D20438CBE8CEA8D758DC F0939A82C282AB2E646F63>

第2回講義:まとめ

memo

Transcription:

第 1 章画面 出力 入力 C++ C++ C++ C++ C++ C++ C++ C++ #include using C++ C++ C++ main C++ C++ C++ int double char C++ C++ C++ string C++ C++ C++

21 1-1 C++ 歴史 C++ C++ 歴史 CC with classes Fig.1-1 C C++ Simula 67 Fig.1-1C++ C++

3 C++ 1-1 標準 C 標準 C++

41 1-2 画面 表示 画面 出力 List 1-1 List 1-1 chap1/list11.cpp // cout << "++\n"; cout << "\n"; 実行結果 ++ " p.v /, \, #,,, <, >, (, ), ", ; C++ p.11 Table 1-1 \ source program source file source 原始

5 list11.cpp.cpp.c.cc.c 処理系 C++ Microsoft Visual C++ GNU C++ 実行 Fig.1-2 実行 1 bitbinary digit 1 1 1 2 1 1, 1, 2,, 9 1 1 1-2 //... 実行 11111111 11111111111 1111111111 11111111111 11111111 Fig.1-2 診断 diagnostic message

61 ( 注釈 ) // // // 注釈 comment /* */ /* /* */ */ */ /* <iostream> Fig.1-3 <iostream> <string> header< > iostream string #include include

7 //... cout cin <iostream> 1-2 Fig.1-3#include 4 4 4 4 <iostream> iostream iostream.h iostream.hpp std 名前空間 利用 #include using std 名前空間 name space 4 4 std standard cout std::cout 9 1-1 <iostream> 1-2 List 1-1p.4 using cout std::cout

81 画面 出力 cout << "++\n"; cout << "\n"; stream Fig.1-4 cout 標準出力 standard output stream 4 4 4 4 < << 挿入子 inserter < < < cout << "ABC"; ABC cout Fig.1-4 iostream 入出力 input-output streamcout cont count 文字列 "++\n" "ABC" " 文字列 string literal "" " cout " 8

9改行 \n 4 4 4 \ n \ 拡張表記 3 main 関数 Fig.1-5 1-2 main main cout << "++\n"; cout << "\n"; Fig.1-5main main 関数 main function main 文 statement 4 4 C++ main 6 文 main ; 1-3 ;

101 List 1-2 List 1-2 // \n 実行結果 ++ cout << "++\n\n"; \n ABC ABC chap1/list12.cpp 連続 出力 List 1-3 List 1-3 // << chap1/list13.cpp 実行結果 警報改行 cout << "\a" << "\n"; cout << 警報 \a cout

11記号文字 読 方 Table 1-1 MS-Windows \ List 1-3 cout << " a" << " n"; Table 1-1 1-2 + - * / \ JIS %., : ; ' " ( ) [ ] < >?! & ~ JIS - - ^ # _ = 注意!!

121 自由形式記述 List 1-4 List 1-1 /* List 1-4 */ using namespace std; int main( cout << "++\n"; << "\n" ; cout ) chap1/list14.cpp 読 正 実行結果 ++ 自由形式 free formatted intmaincout, <<, //, /*, */ 空白類文字 ma in " "" " " cout << " ++\n"; cout << "" "++\n";

13List 1-5 List 1-5 // chap1/list15.cpp 実行結果 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz cout << "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // "abcdefghijklmnopqrstuvwxyz\n"; // 1-2 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz\n" white space 2 3 "ABCD" "EFGH" "IJKL" 1 "ABCDEFGHIJKL" # #include preprocessing directive #include #define #if \ #include <iostream> #include \ <iostream> \ 4 4

141 List 1-1main Fig.1-6, 4, 8, 12, for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) cout << setw(3) << i * j; cout << '\n'; 3 List 3-13p.106 Fig.1-6 1-4 1-5

15bug debug C++ 1-2 Column 1-1 List 1C-1 // // cout << "++\n"; cout << "\n"; chap1/list1c1.c 実行結果 2 // // /* */ List 1C-2 // /* cout << "++\n"; cout << "\n"; */ chap1/list1c2.c 実行結果 #if Column 11-7 p.415

161 1-3 変数 演算結果 出力 List 1-6 18 63 List 1-6 // 1863 cout << "1863" << 18 + 63 << "\n"; chap1/list16.cpp 実行結果 186381 整数 18 63 整数 integer literal 18 1 8 "18" 2 1 8 4 演算結果 出力 Fig.1-7 cout "1863" "\n" \n 4 4 4 4 18 + 63 81 cout << "1863" << 18 + 63 << "\n"; 1863 81 Fig.1-7

171-3 変数 18 63 変数 宣言 宣言 declaration x 宣言文 declaration statement int x; // xint int x Fig.1-8 x 3.5 int 型 type int x int int 4, int x, y; // intxy int x ; int x int Fig.1-8

181 x y 63 18 List 1-7 List 1-7 // xy int x; int y; x = 63; y = 18; // xint // yint // x63 // y18 ㆒ chap1/list17.cpp 実行結果 x63 y18 81 4 cout << "x" << x << "\n"; // x cout << "y" << y << "\n"; // y cout << "" << x + y << "\n"; // xy cout << "" << (x + y) / 2 << "\n"; // xy ㆓ 叅 1 int x, y; 代入演算子 ㆒ = 代入演算子 assignment operator Fig.1-9 x 63 y 18 x = 63; y = 18; 63 18 x y Fig.1-9 x 63 y 18 4 4 p.22

191-3 変数 値 表示 ㆓ x Fig.1-10 4 4 4 cout x x 4 63 x cout << "x" << x << "\n"; x 63 63 x Fig.1-10 算術演算子 演算 化叅 x y x + y (x + y) / 2 x + y ( ) ( ) Fig.1-11 a x + y 2 / b( ) x + y / 2 x y / 2 Table 2-10p.76 a xy ( x + y ) / 2 y b x 2 x + y / 2 Fig.1-11( ) / 63 18 4.5 4 1-6 List 1-7 x y int 1-7 int

201 変数 初期化 ㆒ List 1-8 List 1-8 // xy int x; // xint int y; // yint chap1/list18.cpp 実行結果一例 x6936 y2358 9294 4647 cout << "x" << x << "\n"; // x cout << "y" << y << "\n"; // y cout << "" << x + y << "\n"; // xy cout << "" << (x + y) / 2 << "\n"; // xy x y 6 p.226 初期化 伴 宣言 List 1-9 x y 63 18 初期化 initialize Fig.1-12 = 初期化子 initializer C++ = = 63 = 63 4 initializer clause int x = 63 ; Fig.1-12

211-3 List 1-9 // xy int x = 63; // xint63 int y = 18; // yint18 chap1/list19.cpp 実行結果 x63 y18 81 4 cout << "x" << x << "\n"; // x cout << "y" << y << "\n"; // y cout << "" << x + y << "\n"; // xy cout << "" << (x + y) / 2 << "\n"; // xy 初期化 代入 List 1-7 4 4 4 4 4 Fig.1-13 10 = = a int x = 63; b x = 63; 63 int 63 x x Fig.1-13 1-8 int

221 1-4 入力 入力 List 1-10 cin 標準入力 standard input stream cin >> 抽出子 extractor cin Fig.1-14 int List 4-1p.129 cin >> x; 123 1 2 3 x cin Fig.1-14 演算子 - * % + - 演算子 operator operand x y x + y + x y Fig.1-15 +, -, *, /, % Table 1-2 Table 1-3 算術演算子 arithmetic operator

23List 1-10 // int x; int y; // // cout << "xy\n"; cout << "x"; // x cin >> x; // x cout << "y"; // y cin >> y; // y chap1/list11.cpp 実行例 xy x7 Ÿ y5 Ÿ x + y12 x - y2 x * y35 x / y1 x % y2 1-4 cout << "x + y" << x + y << "\n"; cout << "x - y" << x - y << "\n"; cout << "x * y" << x * y << "\n"; cout << "x / y" << x / y << "\n"; cout << "x % y" << x % y << "\n"; // x + y // x - y // x * y // x / y // x % y 2 項演算子 binary operator 単項演算子 unary operator 3 項演算子 ternary operator x + y Fig.1-15 Table 1-2additive operator x + y x - y x y x y Table 1-3multiplicative operator x * y x / y x % y x y x y x, y x y x, y

241 連続 読込 << cout >> cin List 1-11 List 1-11 // int x; int y; // // cout << "xy\n"; chap1/list111.cpp 実行例 xy xy7 5 Ÿ x + y12 x - y2 x * y35 x / y1 x % y2 cout << "xy"; cin >> x >> y; // xy // xy cout << "x + y" << x + y << "\n"; cout << "x - y" << x - y << "\n"; cout << "x * y" << x * y << "\n"; cout << "x / y" << x / y << "\n"; cout << "x % y" << x % y << "\n"; // x + y // x - y // x * y // x / y // x % y x y >> >> 7 5 7 x 5 y 7 5 Ÿ 7 7 5 5 7 Ÿ 5 Ÿ / % Column 1-2p.27

25単項 算術演算子 List 1-12 List 1-12 // int a; cout << ""; cin >> a; chap1/list112.cpp 実行例㆒ 7 Ÿ 7-7 実行例 // -15 Ÿ -1515 // // a 1-4 int b = -a; // ab cout << a << "" << b << "\n"; ㆒ ㆓ b ㆒ main b -a - - + +a a ㆓ cout << +a << "" << b << "\n"; + - Table 1-4 Table 1-4 +x x -x x

261 実数値 読込 int double List 1-13 List 1-13 // double x; double y; // // cout << "xy\n"; chap1/list113.cpp 実行例 xy x7.5 Ÿ y5.25 Ÿ x + y12.75 x - y2.25 x * y39.375 x / y1.42857 cout << "x"; cin >> x; cout << "y"; cin >> y; // x // x // y // y cout << "x + y" << x + y << "\n"; cout << "x - y" << x - y << "\n"; cout << "x * y" << x * y << "\n"; cout << "x / y" << x / y << "\n"; // x + y // x - y // x * y // x / y 5. 5 5. 5. Table 1-3 % % % cout << "x % y" << x % y << "\n"; // int double List 2-16p.63 4

27 1-9 1-10 1 1 1-11 7 Ÿ 7 7 Ÿ 117 1-3 x7.5 Ÿ y5.25 Ÿ 12.75 6.375 1-4 1-12 7.8 Ÿ 3.2 Ÿ 12.48 Column 1-2 除算 演算結果 / % x / y x % y x = 22 y = 5 4 2 / x = -22 y = -5 x = -22 y = 5 x = 22 y = -5 x / y x % y 4-2 5 3-4 -2-5 3-4 2-5 -3 x y y (x / y) * y + x % y x

281 定値 List 1-14 // double r; List 1-14 cout << ""; cin >> r; // // // cout << "" << 2 * 3.14 * r << "\n"; cout << "" << 3.14 * r * r << "\n"; chap1/list114.cpp 実行例 7.2 Ÿ 45.216 162.778 // // r 2 r r 2 3.14 floating-point literal 3.14 3.1415926535 3.1416 3.1416 3.14 3.14 3.1416 3.14 4 4 4 4 const object List 1-15 const PI 3.1416 4

29// const double PI = 3.1416; double r; List 1-15 cout << ""; cin >> r; // // // // cout << "" << 2 * PI * r << "\n"; cout << "" << PI * r * r << "\n"; chap1/list115.cpp 実行例 7.2 Ÿ 45.239 162.861 // // 1-4 PI 3.1416 PI 3.14159 3.1416 3.14159 PI const const double PI = 3.1416; const double PI; PI = 3.1416; const cv cv const volatile

301 乱数 生成 List 1-16 List 1-16 // 9 #include <ctime> #include <cstdlib> ㆒ srand(time(null)); // chap1/list116.cpp 実行例 6 int lucky = rand() % 1; // 9 叅 cout << "" << lucky << "\n"; ㆓ 9 乱数 ㆒㆓ 叅 ㆓ 叅 叅 rand() 1 1 lucky 9 1-13 1 1 9 1-9 -1 2 1 99 1-14 5 1 95 15 1 Ÿ 5 13

31 ㆒ ㆓ 叅 Column rand RAND_MAX <cstdlib> RAND_MAX 32,767 #include <cstdlib> // int x = rand(); // RAND_MAX int y = rand(); // RAND_MAX cout << "x" << x << "y" << y << "\n"; 1-4 Column 1-3 乱数 生成 x y x y x y 1 2 3 16,838 5,758 1,113 17,515 31,51 5,627 rand rand srand srand(5) srand(23) srand rand 5 22,715 22,43 16,275 21,417 4,96 9, srand srand #include <ctime> #include <cstdlib> // srand(time(null)); // int x = rand(); // RAND_MAX int y = rand(); // RAND_MAX cout << "x" << x << "y" << y << "\n"; time time_t time p.404 Column 11-4 rand 4 4

321 文字 読込 List 1-17 // char c; // List 1-17 cout << ""; cin >> c; cout << "" << c << "\n"; // // // chap1/list117.cpp 実行例 X Ÿ X char >> c char 4 文字列 読込 List 1-18 List 1-18 // #include <string> string name; // cout << ""; cin >> name; cout << "" << name << "\n"; 実行例㆓ Ÿ // // // chap1/list118.cpp 実行例㆒ Ÿ string <string>

33 >> "" name List 1-19 chap1/list119.cpp // #include <string> 実行例㆒ Ÿ 実行例㆓ Ÿ string name; // cout << ""; // getline(cin, name); // List 1-19 cout << "" << name << "\n"; // 1-4 string std::string cout p.7 getline(cin, ) List 1-20 string List 1-20 // #include <string> string s1 = "ABC"; string s2 = "XYZ"; s1 = "FBI"; // // // cout << "s1" << s1 << "\n"; cout << "s2" << s2 << "\n"; // // chap1/list12.cpp 実行結果 s1fbi s2xyz s1 "ABC" "FBI"

341 C++ C Simula 67 C++ #include C++ main ; <iostream> cout << cin >> int double char string string <string> "" \n \a const + *

35( ) / % / % rand /* */ // x + y x - y x * y x / y x % y +x -x #include /* */ chap1/summary.cpp #include <ctime> #include <cstdlib> #include <string> using int a; // aint a = 1; // int b = 5; // RAND_MAX srand(time(null)); // int lucky = rand() % 1; // 9 cout << "" << lucky << "\n"; cout << "" << lucky / 2 << "\n"; cout << "" << lucky % 2 << "\n"; // const double PI = 3.14; double r; 実行例 cout << ""; cin >> r; cout << "" << r << "" << (PI * r * r) << "\n"; 5 3.14 "" 5 2 1 4.5 Ÿ 4.563.585 Shibata BohYoh Ÿ Shibata string name; // cout << ""; // cin >> name; // cout << "\a" "" << name << "\n";