1 / 39

C++ Programming Practice Time

C++ Programming Practice Time. Week 2. Practice : Create Project. Run Microsoft Visual Studio. Practice : Create Project. Practice : Create Project. Practice : Create Project. Practice : Create Project. Practice : Create Project. Practice : Create Project. Practice : Create Project.

bo-sears
Download Presentation

C++ Programming Practice Time

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++ Programming Practice Time Week 2.

  2. Practice : Create Project • Run Microsoft Visual Studio

  3. Practice : Create Project

  4. Practice : Create Project

  5. Practice : Create Project

  6. Practice : Create Project

  7. Practice : Create Project

  8. Practice : Create Project

  9. Practice : Create Project

  10. Practice : Create Project

  11. Practice : Create Project

  12. Practice : Preprocessing • #include • #define • #define with parameter

  13. Practice : Preprocessing #include <stdio.h> #define _PI 3.141592 #define SUM(_a, _b) (_a + _b) void main() { printf(“%d\n”, SUM(_PI, 5)); }

  14. Practice : Preprocessing • #include • include pre-defined source • #define • define literal as other literal • #define with parameter • define literal like a function

  15. Practice : Variable • int • char • float • naming rule

  16. Practice : Variable #include <stdio.h> void main() { int Int_Value = 5; char Ch_Zero = ‘0’; char pCh_Test[4] = “val”; float _F_Value0 = 2.f; int &rInt_Test = (*(int*)pCh_Test); }

  17. Practice : Variable • int • integer value : natural, zero, natural with negative • char • character value : ‘a’, ‘b’, ‘1’, ‘*’ … • float • number with floating point : 2.3f, 5.232f, …. • naming rule • alphabet(a~z, A~Z), underline(_), number(0~9) • not allowed start with number

  18. Practice : Literal • integer • character • string • number with floating point

  19. Practice : Literal #include <stdio.h> void main() { int Int_Value = 5; char Ch_Zero = ‘0’; char pCh_Test[4] = “val”; float _F_Value0 = 2.f; int &rInt_Test = (*(int*)pCh_Test); }

  20. Practice : Expression • Math Expression • Comparison Expression • Condition Expression

  21. Practice : Math Expression • Mathematical Operators • Associativity • Precedence • C++ Math Operator Rules

  22. Practice : Mathematical Operators #include <stdio.h> #define _PI 3.141592 void main() { float F_Radius = 2.5f; float F_Area = _PI * F_Radius * F_Radius; float F_Circum = 2.f * _PI * F_Radius; printf(“Area : %f\n”, F_Area); printf(“Circumference : %d\n”, F_Circum); }

  23. Practice : Math Expression • Mathematical Operators • + - * / % • Associativity • Precedence • C++ Math Operator Rules

  24. Practice : Associativity #include <stdio.h> void main() { printf(“%f\n”, 2.f + (3.f + 1.f)); printf(“%f\n”, 2.f + 3.f + 1.f); printf(“%f\n”, (2.f + 3.f) + 1.f); }

  25. Practice : Math Expression • Mathematical Operators • + - * / % • Associativity • (A + B) + C = A + (B + C) • (KOR : 결합법칙) • Precedence • C++ Math Operator Rules

  26. Practice : Precedence #include <stdio.h> void main() { printf(“%f\n”, 2.f * (3.f + 1.f)); printf(“%f\n”, 2.f * 3.f + 1.f); printf(“%f\n”, (2.f * 3.f) + 1.f); }

  27. Practice : Math Expression • Mathematical Operators • + - * / % • Associativity • (A + B) + C = A + (B + C) [KOR : 결합법칙] • Precedence • Order of caculation [KOR : 우선순위] • C++ Math Operator Rules • Check Prof’s Material

  28. C++ Programming C++ Math Operator Rules Operator Associativity Precedence () left to right high * / % left to right middle + - left to right low • Now - what is the value of this?: 2 / 3 / 4 + 5 • How about this: (7*3/4-2)*5

  29. Practice : Expression • Math Expression • Comparison Expression • Condition Expression

  30. Practice : Comparison Expression • Relational and Equality Operators • Equal vs Assign • Precedence

  31. Practice : Relational and Equality Operators #include <stdio.h> void main() { printf(“%d\n”, 1 < 2); printf(“%d\n”, 1 <= 2); printf(“%d\n”, 1 > 2); printf(“%d\n”, 1 >= 2); printf(“%d\n”, 1 == 2); printf(“%d\n”, 1 != 2); }

  32. Practice : Comparison Expression • Relational and Equality Operators • < <= > >= == != • Equal vs Assign • Precedence

  33. Practice : Equal vs Assign #include <stdio.h> void main() { int Int_Value = 2; printf(“%d\n”, (bool)(Int_Value == 3)); printf(“%d\n”, (bool)(Int_Value = 3)); }

  34. Practice : Comparison Expression • Relational and Equality Operators • < <= > >= == != • Equal vs Assign • Equal => Comparison A & B is same • Assign 1) Assign value to Variable 2) Check Variable as bool (false : zero, true : others) • Precedence • Check Prof’s Material

  35. C++ Programming Precedence Operators Precedence () highest (applied first) * / % + - < <= > >= == != = lowest (applied last)

  36. Practice : Expression • Math Expression • Comparison Expression • Condition Expression

  37. Practice : Condition Expression • Condition with Comparison • Complex Conditions(&& || !) • Precedence

  38. Following pages will be filled in next time

  39. The End of Week 2.

More Related