(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
#OOP_D_ITS - 3rd - Migration From C To C++
1. Migration: C to C++ 09/09/2009 1 Hadziq Fabroyir - Informatics ITS
2. C/C++ Program Structure Operating System void function1() { //... return; } int main() { function1(); function2(); function3(); return 0; } void function2() { //... return; } void function3() { //... return; } Operating System
3. Naming Variable MUST Identifier / variable name can include letters(A-z), digits(0-9), and underscore(_) Identifier starts with letteror underscore Do NOT use keywordsas identifier Identifier in C++ is case-sensitive CONSIDER Usemeaningfullname Limit identifier length up to 31 characters, although it can have length up to 2048 Avoid using identifiers that start with an underscore 09/09/2009 Hadziq Fabroyir - Informatics ITS 3
5. Declaring Variable 09/09/2009 Hadziq Fabroyir - Informatics ITS 5 int value; char[] firstName; Char[] address; int 9ball; long bigInt; System::String full_name; int count!; long class; float a234_djJ_685_abc___;
6. Initializing Variable int value = 0; char[] firstName = “Budi”; long bigInt(100L); System::String^ full_name = “Budi Lagi”; 09/09/2009 Hadziq Fabroyir - Informatics ITS 6
9. Example of Data Types int main() { char c = 'A'; wchar_t wideChar = L'9'; int i = 123; long l = 10240L; float f = 3.14f; double d = 3.14; bool b = true; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 9
10. Enumerations Variable with specific sets of values Enum Day {Mon, Tues, Wed, Thurs, Fri, Sat, Sun}; Day today = Mon; Enum Day {Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun}; Day nextDay = Tues; 09/09/2009 Hadziq Fabroyir - Informatics ITS 10
11. Basic Input/Output Operations int main() { //declare and initialize variables int num1 = 0; int num2 = 0; //getting input from keyboard cin >> num1 >> num2; //output the variables value to command line cout << endl; cout << "Num1 : " << num1 << endl; cout << "Num2 : " << num2; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 11
13. Basic Operators int main() { int a = 0; int b = 0; int c = 0; c = a + b; c = a - b; c = a * b; c = a / b; c = a % b; a = -b; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 13
14. Bitwise Operators 09/09/2009 Hadziq Fabroyir - Informatics ITS 14 & bitwise AND ~ bitwise NOT | bitwise OR ^ bitwise XOR >>shift right <<shift left
15. Increment and Decrement Operators int main() { int a = 0; int b = 0; a++; b--; ++a; ++b; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 15
16. Shorthand Operators int main() { int a = 0; int b = 0; a += 3; b -= a; a *= 2; b /= 32; a %= b; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 16
19. Declaring Namespace namespace MyNamespace { // code belongs to myNamespace } namespace OtherNamespace { // code belongs to otherNamespace } 09/09/2009 Hadziq Fabroyir - Informatics ITS 19
20. Using Namespace #include <iostream> namespace myStuff { int value = 0; } int main() { std::cout << “enter an integer: “; std::cin >> myStuff::value; std::cout << “You entered “ << myStuff::value << std:: endl; return 0; } #include <iostream> namespace myStuff { int value = 0; } using namespace myStuff; int main() { std::cout << “enter an integer: “; std::cin >> value; std::cout << “You entered “ << value<< std:: endl; return 0; } 09/09/2009 Hadziq Fabroyir - Informatics ITS 20
21. Visual C++ Programming Environment Hadziq Fabroyir - Informatics ITS ISO/ANSI C++ (unmanaged) C++/CLI .NET Framework Managed C++ Native C++ Framework Classes Native C++ MFC Common Language Runtime (CLR) Operating System HHardware 09/09/2009 21
23. ITC1398 Introduction to Programming Chapter 3 23 Control Structures Three control structures Sequence structure Programs executed sequentially by default Selection structures if, if…else, switch Repetition structures while, do…while, for
24. ITC1398 Introduction to Programming Chapter 3 24 if Selection Statement Choose among alternative courses of action Pseudocode example If student’s grade is greater than or equal to 60 print “Passed” If the condition is true Print statement executes, program continues to next statement If the condition is false Print statement ignored, program continues
26. ITC1398 Introduction to Programming Chapter 3 26 if Selection Statement Translation into C++ if ( grade >= 60 ) cout << "Passed"; Any expression can be used as the condition If it evaluates to zero, it is treated as false If it evaluates to non-zero, it is treated as true
27. ITC1398 Introduction to Programming Chapter 3 27 if…else Double-Selection Statement if Performs action if condition true if…else Performs one action if condition is true, a different action if it is false Pseudocode If student’s grade is greater than or equal to 60 print “Passed”Else print “Failed” C++ code if ( grade >= 60 ) cout << "Passed";else cout << "Failed";
29. ITC1398 Introduction to Programming Chapter 3 29 if…else Double-Selection Statement Ternary conditional operator (?:) Three arguments (condition, value if true, value if false) Code could be written: cout << ( grade >= 60 ? “Passed” : “Failed” ); Condition Value if true Value if false
30. ITC1398 Introduction to Programming Chapter 3 30 if…else Double-Selection Statement Nested if…else statements One inside another, test for multiple cases Once a condition met, other statements are skipped Example If student’s grade is greater than or equal to 90 Print “A” Else If student’s grade is greater than or equal to 80 Print “B” Else If student’s grade is greater than or equal to 70 Print “C” Else If student’s grade is greater than or equal to 60 Print “D” Else Print “F”
32. while Repetition Statement A repetition statement (also called a looping statement or a loop) allows the programmer to specify that a program should repeat an action while some condition remains true. The pseudocode statement While there are more items on my shopping list Purchase next item and cross it off my list 09/09/2009 Hadziq Fabroyir - Informatics ITS 32
36. For your practice … Lab Session I (Ahad, 19.00-21.00) 4.14 5.20 6.27 Lab Session II (Senin, 19.00-21.00) 4.35 5.12 6.30 09/09/2009 Hadziq Fabroyir - Informatics ITS 36
37. ☺~ Next: OOP using C++ ~☺ [ 37 ] Hadziq Fabroyir - Informatics ITS 09/09/2009