Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. double giveMeMaxmum(double theArray[], int size)
  2. {
  3. double max = theArray[0];
  4. for (int i = 1; i < size; i++)
  5. {
  6. if (max <= theArray[i])
  7. {
  8. max = theArray[i];
  9. }//endif
  10. }//endfor
  11. return max;
  12. }//end max
  13.  
  14. void getData(double &l, double &w)
  15. {
  16. cout << "Enter value for length: ";
  17. cin >> l;
  18. cout << endl;
  19. cout << "Enter value for width: ";
  20. cin >> w;
  21. }
  22.  
  23. void showData(double l, double w)
  24. {
  25. cout << "your length is :" << l <<"\n";
  26. cout << "your width is :" << w <<"\n";
  27. }
  28.  
  29. void getAreaVoid(double l, double w)
  30. {
  31. double area = l * w;
  32. cout << "The area is ";
  33. cout << area << endl;
  34. }
  35.  
  36. double getAreaReturned(double &l, double &w)
  37. {
  38. double area = l * w;
  39. return area;
  40. }
  41.  
  42.  
  43.  
  44. int main()
  45. {
  46.  
  47. //the regular arrays
  48. const int FIVE = 5;
  49. double sampleArray[FIVE];
  50.  
  51. for (int i = 0; i < FIVE; ++i)
  52. {
  53. cout << "Input data for index " << i <<": ";
  54. cin >> sampleArray[i];
  55. }//endfor
  56.  
  57. double sum = 0;
  58.  
  59. double max = sampleArray[0];
  60. double min = sampleArray[0];
  61.  
  62. for (int i = 0; i < FIVE; ++i)
  63. {
  64. cout << "data at index " << i << " = " << sampleArray[i] << endl;
  65. sum = sum + sampleArray[i];
  66.  
  67. if (max <= sampleArray[i])
  68. {
  69. max = sampleArray[i];
  70. }
  71.  
  72. if (min >= sampleArray[i])
  73. {
  74. min = sampleArray[i];
  75. }
  76.  
  77. }//endfor
  78.  
  79. cout << "the sum is " << sum << endl;
  80. cout << "Max is " << max << endl;
  81. cout << "Min is " << min << endl;
  82.  
  83. cout << "the maximum coming from the function is "<< giveMeMaxmum(sampleArray, FIVE) <<endl;
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. //the double arrays
  95. const int row=3;
  96. const int column=3;
  97. double sales[row][column];
  98.  
  99. for(int i = 0; i < row; ++i)
  100. {
  101. for (int j = 0; j < column; ++j)
  102. {
  103. cin >> sales[i][j];
  104. }//endfor
  105. }//endfor
  106.  
  107.  
  108. for (int i = 0; i < row; ++i)
  109. {
  110. for (int j = 0; j < column; ++j)
  111. {
  112. cout << sales[i][j];
  113. }//endfor
  114. cout << endl;
  115. }//endfor
  116.  
  117.  
  118.  
  119. //THE STRUCTS
  120. struct rectangle
  121. {
  122. double length;
  123. double width;
  124. };
  125.  
  126.  
  127. rectangle myRectangle;
  128. getData(myRectangle.length, myRectangle.width );
  129. showData(myRectangle.length, myRectangle.width);
  130.  
  131. getAreaVoid(myRectangle.length, myRectangle.width);
  132. double len = myRectangle.length;
  133. double wid = myRectangle.width;
  134. cout << len << endl;
  135. cout << wid << endl;
  136. cout << "The area is " << getAreaReturned(len, wid) << endl;
  137.  
  138.  
  139.  
  140.  
  141. //the pointers with arrays
  142. short numbers[] = { 10, 20, 30, 40, 50 };
  143.  
  144.  
  145. for (int i = 0; i < 5; ++i)
  146. {
  147. cout << "The element of my array is:" << *(numbers+i) << endl;
  148. }
  149.  
  150. for (int i = 0; i < 5; ++i)
  151. {
  152. cout << "The address is:" << &(numbers[i]) << endl;
  153. }
  154.  
  155.  
  156.  
  157. system("pause");
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement