Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <stdlib.h>
- using namespace std;
- bool sym_1 (int array_1[], int size_1);
- bool sym_2 (int array_2[], int size_2);
- bool sym_3 (int array_3[], int size_3);
- int main(int argc, char* argv[])
- {
- int size_1;
- int size_2;
- int size_3;
- int* array_1;
- int* array_2;
- int* array_3;
- char peek;
- if(argc != 4)
- {
- cout << "\nError: Number of command line arguments specified incorrect." << endl;
- return(0);
- }
- size_1 = atoi(argv[1]);
- size_2 = atoi(argv[2]);
- size_3 = atoi(argv[3]);
- array_1 = new int[size_1];
- array_2 = new int[size_2];
- array_3 = new int[size_3];
- do{
- cout << "\nPlease enter an array consisting of " << size_1 << " integers, each separated by a space: ";
- for (int i = 0; i < size_1; i++)
- {
- cin >> array_1[i];
- }
- peek = cin.peek();
- if(peek != '\n')
- {
- cin.clear();
- cin.ignore(10000,'\n');
- }
- }while(peek != '\n');
- cout << "\nPlease enter an array consisting of " << size_2 << " integers, each separated by a space: ";
- for (int i = 0; i < size_2; i++)
- {
- cin >> array_2[i];
- }
- cout << "\nPlease enter an array consisting of " << size_3 << " integers, each separated by a space: ";
- for (int i = 0; i < size_3; i++)
- {
- cin >> array_3[i];
- }
- if(sym_1(array_1, size_1))
- {
- cout << "\nArray 1 was symmetric." << endl;
- }
- else
- {
- cout << "\nArray 1 was not symmetric." << endl;
- }
- if(sym_2(array_2, size_2))
- {
- cout << "\nArray 2 was symmetric." << endl;
- }
- else
- {
- cout << "\nArray 2 was not symmetric." << endl;
- }
- if(sym_3(array_3, size_3))
- {
- cout << "\nArray 3 was symmetric." << endl;
- }
- else
- {
- cout << "\nArray 3 was not symmetric." << endl;
- }
- delete [] array_1;
- delete [] array_2;
- delete [] array_3;
- return 0;
- }
- bool sym_1 (int array_1[], int size_1)
- {
- for (int i = 0; i <= ((size_1)/2); ++i)
- {
- if(array_1[i] != array_1[size_1 - (1 + i)])
- {
- return false;
- }
- }
- return true;
- }
- bool sym_2 (int array_2[], int size_2)
- {
- for (int i = 0; i <= ((size_2)/2); ++i)
- {
- if(array_2[i] != array_2[size_2 - (1 + i)])
- {
- return false;
- }
- }
- return true;
- }
- bool sym_3 (int array_3[], int size_3)
- {
- for (int i = 0; i <= ((size_3)/2); ++i)
- {
- if(array_3[i] != array_3[size_3 - (1 + i)])
- {
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement