fork download
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. //// Sequence
  8. ////
  9. //// Student data
  10. //int studentID = 15;
  11. //int studentAge = 23;
  12. //double studentFee = 75.25;
  13. //char studentGrade = 'B';
  14.  
  15. //// Print variables
  16. //cout << "Student ID: " << studentID << "\n";
  17. //cout << "Student Age: " << studentAge << "\n";
  18. //cout << "Student Fee: " << studentFee << "\n";
  19. //cout << "Student Grade: " << studentGrade << "\n";
  20. //
  21. //...................................................................//
  22. //
  23. // Selection
  24. //..............................Example 1...........................//
  25. //
  26. //int age = 20;
  27. //bool isCitizen = true;
  28.  
  29. //if (age >= 18) {
  30. // cout << "Old enough to vote.\n";
  31.  
  32. // if (isCitizen) {
  33. // cout << "And you are a citizen, so you can vote!\n";
  34. // }
  35. // else {
  36. // cout << "But you must be a citizen to vote.\n";
  37. // }
  38. //}
  39. //else {
  40. // cout << "Not old enough to vote.\n";
  41. //}
  42. //..............................Example 2...........................//
  43. //int day = 4;
  44. //switch (day) {
  45. //case 1:
  46. // cout << "Monday";
  47. // break;
  48. //case 2:
  49. // cout << "Tuesday";
  50. // break;
  51. //case 3:
  52. // cout << "Wednesday";
  53. // break;
  54. //case 4:
  55. // cout << "Thursday";
  56. // break;
  57. //case 5:
  58. // cout << "Friday";
  59. // break;
  60. //case 6:
  61. // cout << "Saturday";
  62. // break;
  63. //case 7:
  64. // cout << "Sunday";
  65. // break;
  66. //}
  67. //
  68. //...................................................................//
  69. // Iterations
  70. //..............................Example 1...........................//
  71. //int number = 2;
  72. //int i;
  73.  
  74. //// Print the multiplication table for the number 2
  75. //for (i = 1; i <= 10; i++) {
  76. // cout << number << " x " << i << " = " << number * i << "\n";
  77. //}
  78. //
  79. //..............................Example 2...........................//
  80. //for (int i = 1; i <= 3; i++) {
  81. // for (int j = 1; j <= 3; j++) {
  82. // cout << i * j << " ";
  83. // }
  84. // cout << "\n";
  85. //}
  86. //
  87. //................................Quiz...........................//
  88.  
  89. //Write code to print Sum of numbers from 1 to 10 using for loop:
  90.  
  91.  
  92. //int sum = 0;
  93. //for (int i = 1; i <= 10; i++) {
  94. // sum = sum + i;
  95. //}
  96. //cout << sum << endl;
  97.  
  98. // but what if i want to Solve it without loops ?
  99.  
  100. //int num = 10,sum=0;
  101. //sum = num * (num + 1) / 2;
  102. //cout << sum;
  103.  
  104. //................................Arrays...........................//
  105.  
  106. //int myNumbers[5] = { 10, 20, 30, 40, 50 };
  107. //for (int i = 0; i < 5; i++) {
  108. // cout << myNumbers[i] << "\n";
  109. //}
  110.  
  111. // cout << sizeof(myNumbers); // what is the result ?
  112.  
  113. //int getArrayLength = sizeof(myNumbers) / sizeof(myNumbers[0]);
  114. //cout << getArrayLength;
  115.  
  116. // ..............................The best way...........................//
  117.  
  118. //int myNumbers[5] = { 10, 20, 30, 40, 50 };
  119. //for (int num : myNumbers) {
  120. // cout << num << "\n";
  121. //}
  122. // ..............................2D Arrays...........................//
  123.  
  124. // string letters[2][4] = {
  125. // { "A", "B", "C", "D" },
  126. // { "E", "F", "G", "H" }
  127. // };
  128.  
  129. //cout << letters[1][2]; //What is the result ?
  130.  
  131. // ..............................references...........................//
  132. //string food = "Pizza";
  133. //string& meal = food;
  134.  
  135. //cout << food << "\n"; // Outputs Pizza
  136. //cout << meal << "\n"; // Outputs Pizza
  137.  
  138.  
  139. //meal = "Hamburger";
  140. //cout << food << "\n"; // Outputs Hamburger
  141.  
  142. // ..............................pointers.............................//
  143.  
  144. //string food = "Pizza"; // A food variable of type string
  145. //string* ptr = &food; // A pointer variable, with the name ptr, that stores the address of food
  146. //
  147. //// Output the value of food (Pizza)
  148. //cout << food << "\n";
  149. //
  150. //// Output the memory address of food (0x6dfed4)
  151. //cout << &food << "\n";
  152. //
  153. //// Output the memory address of food with the pointer (0x6dfed4)
  154.  
  155. //cout << ptr << "\n"; //what if ( ,& ,* )?
  156.  
  157. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty