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. // .........................good question.....................................//
  88. //predict the output of the following code
  89.  
  90. //int x = 3;
  91. //for (int i = 0; i < 3; i++) {
  92. // if (x % 2 == 1)
  93. // x += 2;
  94. // else
  95. // x++;
  96. //}
  97. //cout << x;
  98. //
  99. //................................Quiz...........................//
  100.  
  101. //Write code to print Sum of numbers from 1 to 10 using for loop:
  102.  
  103.  
  104. //int sum = 0;
  105. //for (int i = 1; i <= 10; i++) {
  106. // sum = sum + i;
  107. //}
  108. //cout << sum << endl;
  109.  
  110. // but what if i want to Solve it without loops ?
  111.  
  112. //int num = 10,sum=0;
  113. //sum = num * (num + 1) / 2;
  114. //cout << sum;
  115.  
  116. //................................Arrays...........................//
  117.  
  118. //int myNumbers[5] = { 10, 20, 30, 40, 50 };
  119. //for (int i = 0; i < 5; i++) {
  120. // cout << myNumbers[i] << "\n";
  121. //}
  122.  
  123. // //cout << sizeof(myNumbers) << endl; // what is the result ?
  124.  
  125. //int getArrayLength = sizeof(myNumbers) / sizeof(myNumbers[0]);
  126. //cout << getArrayLength << endl;
  127. //cout << getArrayLength;
  128.  
  129. // ..............................The best way...........................//
  130.  
  131. //int myNumbers[5] = { 10, 20, 30, 40, 50 };
  132. //for (int num : myNumbers) {
  133. // cout << num << "\n";
  134. //}
  135. // ..............................2D Arrays...........................//
  136.  
  137. // string letters[2][4] = {
  138. // { "A", "C", "D" , "G" }, { }
  139. // };
  140.  
  141. //cout << letters[1][2]; //What is the result ?
  142.  
  143. // ..............................references...........................//
  144. // string food = "Pizza";
  145. // string& meal = food;
  146. //string& drink = meal;
  147.  
  148. //// cout << &food << "\n"; // Outputs ?
  149. ////cout << &meal << "\n"; // Outputs ?
  150. ////cout << &drink << "\n"; // Outputs ?
  151.  
  152.  
  153. //meal = "Hamburger";
  154. //cout << food << "\n"; // Outputs ?
  155.  
  156. // ..............................pointers.............................//
  157.  
  158. string food = "Pizza"; // A food variable of type string
  159. string* ptr = &food; // A pointer variable, with the name ptr, that stores the address of food
  160.  
  161. //Output the value of food (Pizza)
  162. cout << food << "\n";
  163.  
  164. //Output the memory address of food (0x6dfed4)
  165. cout << ptr << "\n";
  166.  
  167. // Output the memory address of food with the pointer (0x6dfed4)
  168. //////cout << ptr << "\n"; //what if ( ,& ,* )?
  169.  
  170. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Pizza
0x7ffe27f60b30