Advertisement
Lawnknome

symArray

Nov 15th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6.  
  7. bool sym_1 (int array_1[], int size_1);
  8. bool sym_2 (int array_2[], int size_2);
  9. bool sym_3 (int array_3[], int size_3);
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13.     int size_1;
  14.     int size_2;
  15.     int size_3;
  16.     int* array_1;
  17.     int* array_2;
  18.     int* array_3;
  19.     char peek;
  20.  
  21.     if(argc != 4)
  22.     {
  23.         cout << "\nError: Number of command line arguments specified incorrect." << endl;
  24.         return(0);
  25.     }  
  26.    
  27.     size_1 = atoi(argv[1]);
  28.     size_2 = atoi(argv[2]);
  29.     size_3 = atoi(argv[3]);
  30.  
  31.     array_1 = new int[size_1];
  32.     array_2 = new int[size_2];
  33.     array_3 = new int[size_3];
  34.  
  35.     do{
  36.  
  37.         cout << "\nPlease enter an array consisting of " << size_1 << " integers, each separated by a space: ";
  38.  
  39.         for (int i = 0; i < size_1; i++)
  40.         {
  41.             cin >> array_1[i];
  42.         }
  43.  
  44.         peek = cin.peek();
  45.  
  46.         if(peek != '\n')
  47.         {
  48.             cin.clear();
  49.             cin.ignore(10000,'\n');
  50.         }
  51.            
  52.     }while(peek != '\n');  
  53.  
  54.     cout << "\nPlease enter an array consisting of " << size_2 << " integers, each separated by a space: ";
  55.  
  56.     for (int i = 0; i < size_2; i++)
  57.     {
  58.         cin >> array_2[i];
  59.     }
  60.  
  61.     cout << "\nPlease enter an array consisting of " << size_3 << " integers, each separated by a space: ";
  62.  
  63.     for (int i = 0; i < size_3; i++)
  64.     {
  65.         cin >> array_3[i];
  66.     }
  67.  
  68.     if(sym_1(array_1, size_1))
  69.     {
  70.         cout << "\nArray 1 was symmetric." << endl;
  71.     }  
  72.  
  73.     else
  74.     {
  75.         cout << "\nArray 1 was not symmetric." << endl;
  76.     }  
  77.  
  78.     if(sym_2(array_2, size_2))
  79.     {
  80.         cout << "\nArray 2 was symmetric." << endl;
  81.     }  
  82.  
  83.     else
  84.     {
  85.         cout << "\nArray 2 was not symmetric." << endl;
  86.     }  
  87.  
  88.     if(sym_3(array_3, size_3))
  89.     {
  90.         cout << "\nArray 3 was symmetric." << endl;
  91.     }  
  92.  
  93.     else
  94.     {
  95.         cout << "\nArray 3 was not symmetric." << endl;
  96.     }  
  97.  
  98.     delete [] array_1;
  99.     delete [] array_2;
  100.     delete [] array_3;
  101.  
  102.     return 0;
  103. }
  104.  
  105. bool sym_1 (int array_1[], int size_1)
  106. {
  107.     for (int i = 0; i <= ((size_1)/2); ++i)
  108.     {
  109.         if(array_1[i] != array_1[size_1 - (1 + i)])
  110.         {
  111.             return false;
  112.         }  
  113.     }
  114.  
  115.     return true;
  116. }
  117.  
  118. bool sym_2 (int array_2[], int size_2)
  119. {
  120.     for (int i = 0; i <= ((size_2)/2); ++i)
  121.     {
  122.         if(array_2[i] != array_2[size_2 - (1 + i)])
  123.         {
  124.             return false;
  125.         }  
  126.     }
  127.  
  128.     return true;
  129. }
  130.  
  131. bool sym_3 (int array_3[], int size_3)
  132. {
  133.     for (int i = 0; i <= ((size_3)/2); ++i)
  134.     {
  135.         if(array_3[i] != array_3[size_3 - (1 + i)])
  136.         {
  137.             return false;
  138.         }  
  139.     }
  140.  
  141.     return true;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement