1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

Similar documents
2 : 2008/12/ /01/ G :

第3章 OpenGL の基礎

第3章 OpenGL の基礎

C B

tuat1.dvi

r07.dvi

ohp07.dvi

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

2 T ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy ( ) ( ) ( ) ( ) u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a

橡Pro PDF

演算増幅器

ex01.dvi

WinHPC ppt

演算増幅器

XMPによる並列化実装2

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix()

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

r08.dvi

ohp08.dvi

ex01.dvi

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 <<

1.ppt

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

17 1. strucr Potter ( ) Harry Potter and the Philosopher s Stone 1997 English Title : Harry Potter and the Philosopher s Stone : : 1997 #include<stdio

Condition DAQ condition condition 2 3 XML key value

C

double float

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

導入基礎演習.ppt

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

file:///D|/C言語の擬似クラス.txt

ohp03.dvi

PowerPoint Presentation

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

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

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

untitled

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

main

6-1

untitled

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 >>

Microsoft Word - C.....u.K...doc

yacc.dvi

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

新版明解C言語 実践編

joho07-1.ppt

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

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

debug ( ) 1) ( ) 2) ( ) assert, printf ( ) Japan Advanced Institute of Science and Technology

Minimum C Minimum C Minimum C BNF T okenseq W hite Any D

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

1 level Level swtich ButtonPress ButtonRelease Expose Level

Informatics 2014

P06.ppt

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

AutoTuned-RB

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

comment.dvi

SystemC言語概論

実際の株価データを用いたオプション料の計算

:30 12:00 I. I VI II. III. IV. a d V. VI

新・明解C言語 ポインタ完全攻略

準備 計算結果を可視化するために OpenGL を 利用する. 2

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

libaux.dvi

pptx

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

K227 Java 2

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

(K&R 2.9) ~, &,, >>, << 2. (K&R 5.7) 3. (K&R 5.9) 4. (K&R 5.10) (argc argv atoi(), atof() ) 5. (K&R 7.5) (K&R 7.6) - FILE, stdin, stdout, std

PowerPoint Presentation

<4D F736F F D20438CBE8CEA8D758DC03389F0939A82C282AB2E646F63>

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

第5回お試しアカウント付き並列プログラミング講習会

design_pattern.key

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

‚æ4›ñ

r03.dvi

新・明解C言語 実践編

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程

lexex.dvi

:30 12:00 I. I VI II. III. IV. a d V. VI

I117 II I117 PROGRAMMING PRACTICE II 2 SOFTWARE DEVELOPMENT ENV. 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu

$ pwd /home1/t0/t0903 / / /home1/t0/t0903 / / /home1/t0/t0903 / /... ~ $ ls $ ls -a

卒 業 研 究 報 告.PDF

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

untitled

1.3 ( ) ( ) C

/*p7-1-1*/

115 9 MPIBNCpack 9.1 BNCpack 1CPU X = , B =

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

2008 DS T050049

Transcription:

: : :0757230G :2008/07/18 2008/08/17

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

private: float num; ; Number::Number() printf("construct an instance of the Number\n"); Number::~Number() printf("destruct the instance of the Number\n"); void Number::setNumber(float n) num = n; float Number::getNumber() return num; int main(void) // // a b c d printf("a\n"); printf("the main function is started.\n"); printf("b\n"); Number n; printf("c\n"); n.setnumber(5); printf("d\n"); printf("number is %f\n", n.getnumber() ); printf("e\n"); printf("the main function is finished.\n"); printf("g\n"); return 0;

%./Number3-2 a The main function is started. b Construct an instance of the Number c d number is 5.000000 e The main function is finished. g Destruct the instance of the Number int main(void) b c Construct an instance of the Number " printf("b\n"); Number n; printf("c\n"); Number n; Number::Number()printf Dstrruct the instance of the Number g main 3.3) printf Number3-3.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

private: float num; ; Number::Number() printf("construct an instance of the Number\n"); Number::~Number() printf("destruct the instance of the Number\n"); void Number::setNumber(float n) num = n; float Number::getNumber() return num; int main(void) printf("a\n"); printf("the main function is started\n"); printf("b\n"); Number pnum = new Number; // printf("c\n"); Number num2; // printf("d\n"); pnum->setnumber(5); printf("e\n"); num2.setnumber(6); printf("f\n"); printf("number = %f Number2 = %f\n", pnum->getnumber(), num2.getnumber() ); printf("g\n"); delete pnum; printf("h\n");

printf("the main function is finished\n"); printf("i\n"); return 0; %./Number3-3 a The main function is started b Construct an instance of the Number c Construct an instance of the Number d e f Number = 5.000000 Number2 = 6.000000 g Destruct the instance of the Number h The main function is finished i Destruct the instance of the Number 3.2 main 3.2 Number pnum = new Number; Number num2;deleat pnum; main 3.4) File File class File //File // File(); void open(char filename); void write(char data); void read(char out_data);

void close(); FILE file_descriptor; File file_descriptor OS OS private 3.5) (Number) (ComplexNumber) (Number ) Number3-5.cpp #include <stdio.h> class Number // Number Number(); // ~Number(); // void setnumber(float n); float getnumber(); private: float num; ; Number::Number() printf("construct an instance of the Number\n"); Number::~Number() printf("destruct the instance of the Number\n"); void Number::setNumber(float n) num = n;

float Number::getNumber() return num; class ComplexNumber : public Number // Number ComplexNumber(); ~ComplexNumber(); void setimaginary(float i); // float getimaginary(); // private: float imaginarynumber; ; ComplexNumber::ComplexNumber() printf("construct an instance of ComplexNumber\n"); ComplexNumber::~ComplexNumber() printf("destruct the instance of ComplexNumber\n"); // set(get)imaginary void ComplexNumber::setImaginary(float i) imaginarynumber = i; float ComplexNumber::getImaginary() return imaginarynumber; int main(void) printf("a\n"); ComplexNumber cn; printf("b\n"); cn.setnumber(5);

printf("c\n"); cn.setimaginary(0.5); printf("d\n"); printf("complexnumber = (%f,%f)\n", cn.getnumber(), cn.getimaginary() ); printf("e\n"); return 0; %./Number3-5 a Construct an instance of the Number Construct an instance of ComplexNumber b c d ComplexNumber = (5.000000,0.500000) e Destruct the instance of ComplexNumber Destruct the instance of the Number ComplexNumber ComplexNumber ~ComplexNumbersetImaginary getimaginary public imaginarynumber private main ComplexNumber cn; Number ComplexNumber retrun 0;ComplexNumberNumber 3.6) main 3 print Number3-6.cpp #include <stdio.h> #include <string.h> class Printable //print //Printable

//print Printable() // virtual void print() = 0; // = 0. ; class PrintableNumber : public Printable //print Number PrintableNumber(float n) num = n; // // virtual void print(); float getnumber() return num; private: float num; ; void PrintableNumber::print() printf("number = %f\n", getnumber()); printf("void PrintableNumber \n"); class PrintableString : public Printable //print PrintableString(char s) strcpy(str_buf, s); virtual void print(); char getstring() return str_buf; private: char str_buf[256]; // ; void PrintableString::print() printf("string = %s\n", getstring() ); printf("void PrintableString \n"); int main(void) Printable plist[3] ; plist[0] = new PrintableNumber(5); // plist[1] = new PrintableNumber(6);

plist[2] = new PrintableString("some string"); int i; for(i=0; i<3; i++) plist[i]->print(); // //plist[i] print %./Number3-6 number = 5.000000 void PrintableNumber number = 6.000000 void PrintableNumber string = some string void PrintableString 1 plist[0] = new PrintableNumber(5);PrintableNumber print PrintableNumber 2 plist[1] = new PrintableNumber(6); PrintableNumber print PrintableNumber 3 plist[2] = new PrintableString("some string");printablestring print PrintableString 3.7) java extends interface (extends) extends (interface) interface 4.1) lineart C C++

4.2) C++ C++ main.cpp / main.cpp lineart lineart.c, lineart.cpp / #include <GLUT/glut.h> #include <stdlib.h> // for malloc #include balls.h static Animation anim(20); // void display(void) glclear(gl_color_buffer_bit); anim.draw(); glflush(); // void idle(void) anim.forward(); display(); // // usleep(10000); //

void init(void) glclearcolor(0.0, 0.0, 0.0, 1.0); //. int main(int argc, char argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_rgba); glutcreatewindow(argv[0]); glutdisplayfunc(display); glutidlefunc(idle); init(); glutmainloop(); return 0; balls.cpp / balls.cpp lineart lines.c, lines.cpp / #include <OpenGL/gl.h> #include <glut/glut.h> #include <stdlib.h> #include "balls.h" // #define BALL_RAD 0.1 // //0 f float frand(float f) return (float)rand() / RAND_MAX f;

//BALL void Ball::forward(int i,int num_balls, Ball b) int j; float n; pos.add(vel); // pos vel // if(pos.x < -1 pos.x > 1) vel.x = -vel.x; if(pos.y < -1 pos.y > 1) vel.y = -vel.y; / balls.c void forwardanimation / // for(j=0; j<num_balls; ++j) Ball b2 = b+j-i; if(i!=j) / a b (BALL_RAD). ab / /BALL b b2 BALL_RAD / if( (b->pos.x-b2->pos.x)(b->pos.x-b2->pos.x) +(b->pos.y-b2->pos.y)(b->pos.y-b2->pos.y) <=(2BALL_RAD)(2BALL_RAD) ) // // b->col = Color( frand(1), frand(1), frand(1) ); b2->col = Color( frand(1), frand(1), frand(1) ); // n = b->vel.x; b->vel.x = b2->vel.x; b2->vel.x = n; n = b->vel.y; b->vel.y = b2->vel.y; b2->vel.y = n;

//BALL void Ball::draw() glcolor3f(col.r, col.g, col.b); // glpushmatrix(); gltranslatef(pos.x, pos.y, 0); glutsolidsphere(ball_rad, 16, 2); // glpopmatrix(); //ANIMATION (num:) Animation::Animation(int num) balls = new Ball[num]; num_balls = num; int i, j; // Animation for(i=0; i<numballs(); ++i) // balls[i] = Ball(Vector2(frand(2.0)-1, frand(2.0)-1),vector2(frand(0.001), frand(0.001)),color((i & 4) / 4, (i & 2) / 2, i & 1)); //ANIMATION void Animation::forward() int i; for(i=0; i<num_balls; ++i) Ball b = balls+i; b->forward(i, num_balls, b); //ANIMATION void Animation::draw() int i;

for(i=0; i<num_balls; ++i) Ball b = balls+i; b->draw(); balls.h / balls.h / #include "types.h" class Ball Ball() Ball(Vector2 ipos, Vector2 ivel, Color icol) pos = ipos; vel = ivel; col = icol; // void forward(int i, int num_balls, Ballb); // void draw(); // private: Vector2 pos; // Vector2 vel; // Color col; // ; // class Animation Animation(int num); void setball(int i, Ball p); //? int numballs() return num_balls; // void draw(); // void forward(); //? private: int num_balls; // Ball balls; // ; //

types.h / color.h / class Vector2 Vector2() // Vector2(float ix, float iy) x = ix; y = iy; void add(vector2 rhs) // x += rhs.x; y += rhs.y; float x; float y; ; class Color Color() // Color(float ir, float ig, float ib) r = ir; g = ig; b = ib; float r; float g; float b; ; Makefile LOADLIBES = -framework glut -framework OpenGL CC = g++ -Wall balls:main.o balls.o main.o:balls.h types.h balls.o:balls.h types.h types.o:types.h clean: rm balls.o ~

make ball C http://ja.wikipedia.org/wiki/ IT e-words http://e-words.jp/ java http://www.nextindex.net/java/inherit.html