Holey_yan

20150402_KUAS_VisualC++_Exam05

Apr 2nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. /***************************************/
  2. /** 20150402 Exam 05                  **/
  3. /** Maker  : Yan                      **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2015/04/02 pm.12:00      **/
  6. /***************************************/
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <limits.h>
  11. using namespace std;
  12.  
  13. class numInsertAndGetMaximum{
  14. private:
  15.     int numArray[100], numArrayCounter;
  16.  
  17. public:
  18.     void Initalize(){
  19.         for(int i = 0; i < 100; i++)
  20.             numArray[i] = EOF;
  21.         numArrayCounter = 0;
  22.     }
  23.  
  24.     void Insert(int number){
  25.         numArray[numArrayCounter++] = number;
  26.         return;
  27.     }
  28.  
  29.     void ShowArray(){
  30.         cout << "Array Element: ";
  31.         for(int i = 0; i < numArrayCounter - 1; i++)
  32.             cout << setw(3) << numArray[i];
  33.         cout << endl;
  34.     }
  35.  
  36.     int GetMaximum(){
  37.         int tmpMax = INT_MIN;
  38.         for(int i = 0; i < numArrayCounter; i++)
  39.             if(numArray[i] > tmpMax)
  40.                 tmpMax = numArray[i];
  41.  
  42.         return tmpMax;
  43.     }
  44. };
  45.  
  46. int main(int argc, char const *argv[])
  47. {
  48.     numInsertAndGetMaximum numFunction;
  49.     numFunction.Initalize();
  50.  
  51.     int inNum = 0;
  52.     while(inNum != EOF){
  53.         cin >> inNum;
  54.         numFunction.Insert(inNum);
  55.     }
  56.  
  57.     numFunction.ShowArray();
  58.     cout << "The maximum number int the array is: " << numFunction.GetMaximum() << endl;
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment