c workshop #6

27
1 C workshop #6 Files, Interface to Excel & Matlab, Introduction to C+ +, More Financial Applications (Newton-Raphson), Cholesky decomposision By: Yuli Kaplunovsky, [email protected], (408) 309 4506

Upload: mason

Post on 25-Feb-2016

53 views

Category:

Documents


2 download

DESCRIPTION

C workshop #6. Files, Interface to Excel & Matlab, Introduction to C++, More Financial Applications (Newton-Raphson), Cholesky decomposision By: Yuli Kaplunovsky, [email protected], (408) 309 4506. Reminder #1. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: C workshop #6

1

C workshop #6

Files, Interface to Excel & Matlab, Introduction to C++, More Financial Applications (Newton-Raphson), Cholesky decomposision

By: Yuli Kaplunovsky, [email protected], (408) 309 4506

Page 2: C workshop #6

2

Reminder #1• Variables int I; from -2,147,483,648 to 2,147,483,647double D; a fractional numberchar C; a single character, C=‘K’;char S[100]; an array of 100 characters, strcpy(S,”Hello”);

• Control for (I = 0 ; I < 10 ; I++) { printf(“%d “,I); } printf(“\n”);K = 1; while (K < 100) { printf(“%d, “, K); K = K * 2; } do { C = getc(); printf(“%c”, C); } while ( C != ‘q’ );goto ERROR_HANDLE;switch (I) { case 0: K=99; break; case 1: K=88; break; default: K=44; }

• ifif ( A < 10 && A < 20 ) printf(“Yes\n”); else printf(“No\n”);if ( strcmp( Job, “finance”) == 0 || Salary > 100000) printf(“$”);

Page 3: C workshop #6

3

• Functions void main( void ) { .... }int Max( int A, int B ) { if (A>B) return A; else return B; }

• Pointers int Ar[6] = {10,15,20,25,30,35}, *P=NULL, J, K, L;P = &Ar[5];J = Ar[5];K = *P;*P = 88;L = Ar[5];

• Function with pointersvoid Switch( int &P1, int &P2 ) { int C=*P1; *P1=*P2; *P2=C; }calling the function: Switch(&Ar[2], &Ar[4] );or easier to understand: int *Px, *Py;

Px = &Ar[2]; Py = &Ar[4]; Switch( Px, Py );

Reminder #2

Page 4: C workshop #6

4

• Structure struct { double Fahrenheit; int On; } T[10];T[0].Fahrenheit = 102.5; T[0].On = 1;T[1].Fahrenheit = 90; T[1].On = 0;

Reminder #3

Page 5: C workshop #6

5

class#include <iostream.h>

class vehicle {protected: int wheels; float weight;public: void initialize(int wheels, float weight); int get_wheels(void); float get_weight(void); float wheel_loading(void);};

// initialize to any data desiredvoid vehicle::initialize(int wheels, float weight){ wheels = in_wheels; weight = in_weight;}

// get the number of wheels of this vehicleint vehicle::get_wheels(){ return wheels;}

// return the weight of this vehiclefloat vehicle::get_weight(){ return weight;}

// return the weight on each wheelfloat vehicle::wheel_loading(){ return weight/wheels;}

void main(){vehicle motorcycle, truck, sedan;

motorcycle.initialize(2, 900.0); truck.initialize(18, 45000.0); sedan.initialize(4, 3000.0); cout << "The truck has a loading of " << truck.wheel_loading() << " pounds per wheel.\n";

cout << "The motorcycle weighs " << motorcycle.get_weight() << " pounds.\n";

cout << "The sedan weighs " << sedan.get_weight() << " pounds, and has " << sedan.get_wheels() << " wheels.\n";}

Output:The truck has a loading of 2500 pounds per wheel.The motorcycle weighs 900 pounds.The sedan weighs 3000 pounds, and has 4 wheels.

Page 6: C workshop #6

6

inheritanceclass car : public vehicle { int passenger_load;public: void initialize(int in_wheels, float in_weight, int people = 4); int passengers(void);};

void car::initialize(int in_wheels, float in_weight, int people){ passenger_load = people; wheels = in_wheels; weight = in_weight;}

int car::passengers(void){ return passenger_load;}

void main(){ car Mercedes; Mercedes.initialize(4, 3500.0, 5); cout << "The Mercedes carries " << Mercedes.passengers() << " passengers.\n"; cout << "The Mercedes weighs " << Mercedes.get_weight() << " pounds.\n"; cout << "The Mercedes's wheel loading is " << Mercedes.wheel_loading() << " pounds per tire.\n\n";}

Output:The Mercedes carries 5 passengers.The Mercedes weighs 3500 pounds.The Mercedes's wheel loading is 875 pounds per tire.

Page 7: C workshop #6

7

Page 8: C workshop #6

8

Page 9: C workshop #6

9

Page 10: C workshop #6

10

Page 11: C workshop #6

11

Page 12: C workshop #6

12

1. Select from the menu: View --> ClassWizard

2. Select from the tabs: ‘Member Vriable’

3. Select Variable type: int, and type “m_Number1” as the Member variable name

Page 13: C workshop #6

13

Do the same for all three edit boxes, naming them: m_Number1, m_Number2, m_Result

Page 14: C workshop #6

14

1. Select the Message Maps tab

2. Select Object IDs: IDOK

3. Select BN_CLICKED

4. Press “Add Function”

5. Confirm

Page 15: C workshop #6

15

Page 16: C workshop #6

16

Page 17: C workshop #6

17

Page 18: C workshop #6

18

Page 19: C workshop #6

19

File: Calc.c

Page 20: C workshop #6

20

File: CalcDlg.c, page 1 of 3

Page 21: C workshop #6

21

File: CalcDlg.c, page 2 of 3

Page 22: C workshop #6

22

File: CalcDlg.c, page 3 of 3

Page 23: C workshop #6

23

Option calculator

Page 24: C workshop #6

24

Page 25: C workshop #6

25

Page 26: C workshop #6

26

Page 27: C workshop #6

27