Create a program operations of vectors Create two arrays of

Create a program \"operations of vectors\" Create two arrays of 1 times 5 (1 row 5 columns) Let the user to input the values of each element of both arrays (use a function) Show a menu with 3 options sum. rest, multiplication Let the user to select an option 5. Perform the operation foe each element of the array Example summation (1, 2, 3, 4, 5)+(5, 4, 3, 2, 1)=(6, 6, 6, 6, 6] Show the result to the user

Solution

Please follow the code and comments for description :

CODE :

#include <iostream> // required header

using namespace std;

int *insertElements(); // required functions to enter the data


int main() // driver class
{
   int a[5], b[5], *p, *q, choice; // reauired initisalisations
   cout << \"Enter the Elements for the First Array : \" << endl;
   p = insertElements(); // calling the function to add data
   cout << \"The Entered Elements are : \" << endl;
   for(int i = 0; i < 5; i++){ // printing the data
       cout << *(p + i) << endl;
   }
   cout << \"Enter the Elements for the Second Array : \" << endl;
   q = insertElements(); // calling the function
   cout << \"The Entered Elements are : \" << endl;
   for(int j = 0; j < 5; j++){ // printing the data
       cout << *(q + j) << endl;
   }

   cout << \"Select the Option You Want To Perform.\" << endl; // prompt for the user to select the data
   cout << \"-------------------------------------------\" << endl;
   cout << \"1.Addition. \" << endl;
   cout << \"2.Subtraction. \" << endl;
   cout << \"3.Multiplication. \" << endl;
   cout << \"4.Exit. \" << endl;
   cout << \"-------------------------------------------\" << endl;

   cin >> choice; // getting the choice
   switch(choice) { // switching the choice
    case 1 :
        cout << \"Performing the Addition : \" << endl; // performing the data addition
        cout << \"The result is : \";
        for(int x = 0; x < 5; x++){
            for(int y = x; y <= x; y++) {
                cout << *(p + x) + *(q + y) << \" \"; // adding the data
            }
        }
        cout << \"\ \";
        break;
      
    case 2 :
        cout << \"Performing the Subtraction : \" << endl; // performing the subtraction
        cout << \"The result is : \";
        for(int x = 0; x < 5; x++){
            for(int y = x; y <= x; y++) {
                cout << (*(p + x)) - (*(q + y)) << \" \";    // getting the data
            }
        }
        cout << \"\ \";
        break;
      
    case 3 :
        cout << \"Performing the Multiplication : \" << endl; // performing the multiplication
        cout << \"The result is : \";
        for(int x = 0; x < 5; x++){
            for(int y = x; y <= x; y++) {
                cout << (*(p + x)) * (*(q + y)) << \" \"; // getting the data
            }
        }
        cout << \"\ \";
        break;
      
    case 4 :
        cout << \"Exiting the Code.!\" << endl; // exit teh code
        exit(0);
      
    default :
        exit(0);
   }

   return 0;
}

int *insertElements() {
    static int arr[5];
    cout << \"Enter the Elements : \" << endl;
    for(int m = 0; m < 5; m++){
        cin >> arr[m];
    }
    return arr;
}

OUTPUT :

Enter the Elements for the First Array :                                                                                                                      
Enter the Elements :                                                                                                                                          
1                                                                                                                                                             
2                                                                                                                                                             
3                                                                                                                                                             
4                                                                                                                                                             
5                                                                                                                                                             
The Entered Elements are :                                                                                                                                    
1                                                                                                                                                             
2                                                                                                                                                             
3                                                                                                                                                             
4                                                                                                                                                             
5                                                                                                                                                             
Enter the Elements for the Second Array :                                                                                                                     
Enter the Elements :                                                                                                                                          
1                                                                                                                                                             
2                                                                                                                                                             
3                                                                                                                                                             
4                                                                                                                                                             
5                                                                                                                                                             
The Entered Elements are :
1                                                                                                                                                             
2                                                                                                                                                             
3                                                                                                                                                             
4                                                                                                                                                             
5                                                                                                                                                             
Select the Option You Want To Perform.                                                                                                                        
-------------------------------------------                                                                                                                   
1.Addition.                                                                                                                                                   
2.Subtraction.                                                                                                                                                
3.Multiplication.                                                                                                                                             
4.Exit.                                                                                                                                                       
-------------------------------------------                                                                                                                   
2                                                                                                                                                             
Performing the Addition :                                                                                                                                  
The result is : 2 4 6 8 10


Hope this is helpful.

 Create a program \
 Create a program \
 Create a program \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site