c workshop #6
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 PresentationTRANSCRIPT
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
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(“$”);
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
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
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.
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.
7
8
9
10
11
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
13
Do the same for all three edit boxes, naming them: m_Number1, m_Number2, m_Result
14
1. Select the Message Maps tab
2. Select Object IDs: IDOK
3. Select BN_CLICKED
4. Press “Add Function”
5. Confirm
15
16
17
18
19
File: Calc.c
20
File: CalcDlg.c, page 1 of 3
21
File: CalcDlg.c, page 2 of 3
22
File: CalcDlg.c, page 3 of 3
23
Option calculator
24
25
26
27