1 / 27

C workshop #6

C workshop #6. Files, Interface to Excel & Matlab, Introduction to C++, More Financial Applications (Newton-Raphson), Cholesky decomposision By: Yuli Kaplunovsky, yuli@magniel.com, (408) 309 4506. Reminder #1.

mason
Download Presentation

C workshop #6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C workshop #6 Files, Interface to Excel & Matlab, Introduction to C++, More Financial Applications (Newton-Raphson), Cholesky decomposision By: Yuli Kaplunovsky, yuli@magniel.com, (408) 309 4506

  2. Reminder #1 • Variablesint 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. Reminder #2 • Functionsvoid 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 );

  4. Reminder #3 • Structurestruct { double Fahrenheit; int On; } T[10];T[0].Fahrenheit = 102.5; T[0].On = 1;T[1].Fahrenheit = 90; T[1].On = 0;

  5. 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"; } 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 desired void vehicle::initialize(int wheels, float weight) { wheels = in_wheels; weight = in_weight; } // get the number of wheels of this vehicle int vehicle::get_wheels() { return wheels; } // return the weight of this vehicle float vehicle::get_weight() { return weight; } // return the weight on each wheel float vehicle::wheel_loading() { return weight/wheels; } 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. inheritance class 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. 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

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

  9. 1. Select the Message Maps tab 4. Press “Add Function” 5. Confirm 3. Select BN_CLICKED 2. Select Object IDs: IDOK

  10. File: Calc.c

  11. File: CalcDlg.c, page 1 of 3

  12. File: CalcDlg.c, page 2 of 3

  13. File: CalcDlg.c, page 3 of 3

  14. Option calculator

More Related