C++

『Cプログラマのための C++入門』

『Cプログラマのための C++入門』 柴田望洋『Cプログラマのための C++入門』を勉強してまいります。 1. C++ に慣れよう 1-1-1 コメント 1-1-2 定数 1-2-1 関数プロトタイプ 1-2-2 可変個引数 1-2-3 デフォルト引数 1-2-4 インライン引数 1-3-1 Cリンケージと…

メンバへのポインタ

Cプログラマのための C++入門 > 2.クラスの概念 > メンバへのポインタ C++ #include <stdio.h> #include "Student.h"int main(int argc, char* argv[]) { Student Shibata("柴田望洋", 180, 80); Student Masuyan("増田真二", 170, 60); Shibata.Print(); Masuyan.Pri</stdio.h>…

コンストラクタ

Cプログラマのための C++入門 > 2.クラスの概念 > コンストラクタ C++ #include <stdio.h> #include "Student.h"void PrintStudent(Student x) { printf("%s\n", x.Name()); printf(" 英語 = %d\n", x.English()); printf(" 数学 = %d\n", x.Mathematics()); printf("</stdio.h>…

this ポインタ

Cプログラマのための C++入門 > 2.クラスの概念 > this ポインタ C++ #include <stdio.h>struct student { public: char name[20]; int eng; int math; private: int ave; public: void calc_ave(); int average(); };void student::calc_ave() { this->ave = (this-></stdio.h>…

メンバ関数

Cプログラマのための C++入門 > 2.クラスの概念 > メンバ関数 C++ #include <stdio.h>struct student { public: char name[20]; int eng; int math; private: int ave; public: void calc_ave(); int average(); };void student::calc_ave() { ave = (eng + math) / 2</stdio.h>…

構造体とメンバの透過性

Cプログラマのための C++入門 > 2.クラスの概念 > 構造体とメンバの透過性 C++ #include <stdio.h>struct student { char name[20]; int eng; int math; int ave; };void calc_ave(student* x) { x->ave = (x->eng + x->math) / 2; }int average(student* x) { return</stdio.h>…

関数の多重定義

Cプログラマのための C++入門 > 1. C++ に慣れよう > 関数の多重定義 C++ #include <stdio.h>int abs(int x) { return (x < 0 ? -x : x); } long abs(long x) { return (x < 0L ? -x : x); } double abs(double x) { return (x < 0.0 ? -x : x); }int main(int argc, </stdio.h>…

『明解C言語 入門編』in multi language

『明解C言語 入門編』in multi language 柴田望洋『明解C言語 入門編』を勉強してまいります。 1. まずは慣れよう 000.整数値 15 と 37 の和を表示する 001.整数値 15 から 37 を引いた値を表示する 002.整数値 15 と 37 の和を親切に表示する 003.2つの変…

ポインタのソート

明解C言語 入門編 > 12. 構造体 > ポインタのソート C #include <stdio.h> #include <string.h> #include <alloc.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int compare_height(gstudent* </alloc.h></string.h></stdio.h>…

構造体の動的配列 (malloc)

明解C言語 入門編 > 12. 構造体 > 構造体の動的配列 (malloc) C #include <stdio.h> #include <string.h> #include <alloc.h>#define NINSU 5typedef struct { char name[20]; int height; float weight; } gstudent;typedef int (*compare)(gstudent*, gstudent*);int compare_height(g</alloc.h></string.h></stdio.h>…

構造体

明解C言語 入門編 > 12. 構造体 > 構造体 C #include <stdio.h> #include <string.h>struct gstudent { char name[20]; int height; float weight; };int main(int argc, char* argv[]) { struct gstudent sanaka; strcpy(sanaka.name, "Sanaka"); sanaka.height = 175; sanaka</string.h></stdio.h>…

2つの値を交換する

明解C言語 入門編 > 10. ポインタ > 2つの値を交換する C #include <stdio.h>void swap1(int nx, int ny) { int tmp = nx; nx = ny; ny = tmp; }void swap2(int* nx, int* ny) { int tmp = *nx; *nx = *ny; *ny = tmp; }int main(int argc, char* argv[]) { int na </stdio.h>…

文字列を読み込み、書式化して表示

明解C言語 入門編 > 9. 文字列の基本 > 文字列を読み込み、書式化して表示 C #include <stdio.h> int main(int argc, char* argv[]) { char str[40]; printf("文字を入力してください:"); scanf("%s", str); printf("%s\n", str); /* そのまま */ printf("%5s\n", s</stdio.h>…

選ばれた動物の鳴き声を表示 (列挙体)

明解C言語 入門編 > 8. いろいろなプログラムを作ってみよう > 選ばれた動物の鳴き声を表示 (列挙体) C #include <stdio.h>enum animal { Dog , Cat , Monkey , Invalid }; void dog(void) { puts("ワンワン!!"); } void cat(void) { puts("ニャ〜オ!!"); } void</stdio.h>…

識別子の有効範囲を確認する

明解C言語 入門編 > 6. 関数 > 識別子の有効範囲を確認する C #include <stdio.h>int x = 700;void print_x(void) { printf("%d\n", x); }int main(int argc, char* argv[]) { int x = 800; print_x(); /* 700 */ printf("%d\n", x); /* 800 */ int i; for (i = 1; i </stdio.h>…

配列の要素に値を読み込む (#define)

明解C言語 入門編 > 5. 配列 > 配列の要素に値を読み込む (#define) C #include <stdio.h>#define NINSU 5int main(int argc, char* argv[]) { int i; int score[NINSU]; int sum = 0; puts("点数を入力してください。"); for (i = 0; i < NINSU; i++) { printf("%d</stdio.h>…

1から5までの和を求めて表示 (初期化子)

明解C言語 入門編 > 4. プログラムの流れの繰り返し > 1から5までの和を求めて表示 (初期化子) C #include <stdio.h> int main(int argc, char* argv[]) { int no = 1; int sum = 0; do { sum += no++; } while (no <= 5); printf("1から5までを足した値はは%dで</stdio.h>…

整数と浮動小数点数を書式化して表示

明解C言語 入門編 > 2. 演算と型 > 整数と浮動小数点数を書式化して表示 C #include <stdio.h> int main(int argc, char* argv[]) { printf("[%d]\n", 123); printf("[%.4d]\n", 123); printf("[%4d]\n", 123); printf("[%04d]\n", 123); printf("[%-4d]\n\n", 123);</stdio.h>…

読み込んだ3つの整数値の合計値と平均値を表示 (キャスト)

明解C言語 入門編 > 2. 演算と型 > 読み込んだ3つの整数値の合計値と平均値を表示 (キャスト) C #include <stdio.h> int main(int argc, char* argv[]) { int na, nb, nc; int sum; double avg; puts("3つの整数を入力してください。"); printf("整数A:"); scanf</stdio.h>…

読み込んだ2つの整数値の平均値を実数で表示 (キャスト)

明解C言語 入門編 > 2. 演算と型 > 読み込んだ2つの整数値の平均値を実数で表示 (キャスト) C #include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; puts("2つの整数を入力してください。"); printf("整数A:"); scanf("%d", &vx); printf("整数B</stdio.h>…

型と演算について確認する

明解C言語 入門編 > 2. 演算と型 > 型と演算について確認する C #include <stdio.h> int main(int argc, char* argv[]) { int n1, n2, n3, n4; double d1, d2, d3, d4; n1 = 5 / 2; n2 = 5.0 / 2.0; n3 = 5.0 / 2; n4 = 5 / 2.0; d1 = 5 / 2; d2 = 5.0 / 2.0; d3 = 5</stdio.h>…

読み込んだ2つの実数値の 和・差・積・商 を実数で表示

明解C言語 入門編 > 2. 演算と型 > 読み込んだ2つの実数値の 和・差・積・商 を実数で表示 C #include <stdio.h> int main(int argc, char* argv[]) { double vx, vy; puts("2つの数を入力してください。"); printf("実数vx:"); scanf("%f", &vx); printf("実数vy</stdio.h>…

整数と浮動小数点数

明解C言語 入門編 > 2. 演算と型 > 整数と浮動小数点数 C #include <stdio.h> int main(int argc, char* argv[]) { int nx; double dx; nx = 9.99; dx = 9.99; printf(" int 型変数nxの値:%d\n", nx); printf(" nx / 2:%d\n", nx / 2); printf("double型変数dxの値</stdio.h>…

読み込んだ2つの整数値の平均値を表示

明解C言語 入門編 > 2. 演算と型 > 読み込んだ2つの整数値の平均値を表示 C #include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; puts("2つの整数を入力してください。"); printf("整数A:"); scanf("%d", &vx); printf("整数B:"); scanf("%d",</stdio.h>…

読み込んだ整数値の符号を反転して表示

明解C言語 入門編 > 2. 演算と型 > 読み込んだ整数値の符号を反転して表示 C #include <stdio.h> int main(int argc, char* argv[]) { int num; printf("整数を入力してください:"); scanf("%d", &num); printf("符号を反転させた値は%dです。\n",-num); return 0; </stdio.h>…

読み込んだ2つの整数値の 商・剰余 を表示

明解C言語 入門編 > 2. 演算と型 > 読み込んだ2つの整数値の 商・剰余 を表示 C #include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; puts("2つの整数を入力してください。"); printf("整数A:"); scanf("%d", &vx); printf("整数B:"); scanf("</stdio.h>…

読み込んだ2つの整数値の 和・差・積・商・剰余 を表示

明解C言語 入門編 > 2. 演算と型 > 読み込んだ2つの整数値の 和・差・積・商・剰余 を表示 C #include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; puts("2つの整数を入力してください。"); printf("整数1:"); scanf("%d", &vx); printf("整数2</stdio.h>…

読み込んだ2つの整数値の和を表示

明解C言語 入門編 > 1. まずは慣れよう > 読み込んだ2つの整数値の和を表示 C #include <stdio.h> int main(int argc, char* argv[]) { int n1, n2; puts("2つの整数を入力してください。"); printf("整数1:"); scanf("%d", &n1); printf("整数2:"); scanf("%d</stdio.h>…

読み込んだ整数の10倍の値を表示

明解C言語 入門編 > 1. まずは慣れよう > 読み込んだ整数の10倍の値を表示 C #include <stdio.h> int main(int argc, char* argv[]) { int no; printf("整数を入力してください:"); scanf("%d", &no); printf("その数の10倍は%dです。\n", no * 10); return 0; </stdio.h>…

2つの変数に整数値を格納して表示

明解C言語 入門編 > 1. まずは慣れよう > 2つの変数に整数値を格納して表示 C #include <stdio.h> int main(int argc, char* argv[]) { int vx, vy; vx = 57; vy = vx + 10; printf("vxの値は%dです。\n", vx); printf("vyの値は%dです。\n", vy); return 0; }実行</stdio.h>…