Question: #include #include #include #include using namespace std; int main() { int v_size = 0; //variable for the size of the arrays, its the same for
#include#include #include #include using namespace std; int main() { int v_size = 0; //variable for the size of the arrays, its the same for both so that we can do addition and subtraction int v_id = 0; //use it to determine which vector to operate on, used for average computation int ceiling = 0; //when generating random numbers to place in vector, this constraints the maximum number attainable by the random number generator int action = 0; //determine which course of action the program will take double avg = 0.0; GetSize: cout<<"Enter size for vectors: "; cin>>v_size; if(cin.fail() == true) { system("CLS"); cout<<"Invalid Input. Please Re-enter vector size: "; cin.clear(); cin.ignore(10000, ' '); goto GetSize; } GetCeiling: cout<<"Enter Maximum Random Number for Vector: "; cin>>ceiling; if(cin.fail() == true) { system("CLS"); cout<<"Invalid Input. Please Re-enter Maximum Random Number: "; cin.clear(); cin.ignore(10000, ' '); goto GetCeiling; } int v1[v_size]; int v2[v_size]; int result[v_size]; int run_sum =0; //randomly initialize the vectors srand (time(NULL)); //seed for(int i=0; i >action; //system("CLS"); if(cin.fail() == true || action<-1 || action>5) { system("CLS"); cout<<"Invalid Input. Please Re-enter Desired Action: "; cin.clear(); cin.ignore(10000, ' '); goto GetAction; } if(action == -1) goto end; if(action == 0) { for(int i=0; i >v_id; if(cin.fail() == true || (v_id!=1 && v_id!=2)) { system("CLS"); cout<<"Invalid Input. Please Re-enter Vector Selection(1 or 2): "; cin.clear(); cin.ignore(10000, ' '); goto getVector; } if(v_id == 1 ) for(int i=0; i >v_id; if(cin.fail() == true || (v_id!=1 && v_id!=2)) { system("CLS"); cout<<"Invalid Input. Please Re-enter Vector Selection(1 or 2): "; cin.clear(); cin.ignore(10000, ' '); goto GetVector; } GetIndex: cout<<"Select Index to be Updated: "< >index; if(cin.fail() == true || index<0 || index>(v_size-1)) { system("CLS"); cout<<"Invalid Input. Please Re-enter index to be updated: "; cin.clear(); cin.ignore(10000, ' '); goto GetIndex; } cout<<"Enter updated value: "; if(v_id == 1) { cin>>v1[index]; for(int i=0; i< v_size; i++) cout< >v2[index]; for(int i=0; i< v_size; i++) cout<
//Need to create subfunctions and call them in the main:
- InitializeVectors: This is a void function that initializes the two vectors by random numbers. Inside this function, the user will be prompted to enter the maximum random number. After the vectors have been populated with random numbers, print the vectors side by side. The parameters are the two arrays and their size.
- EditVector: This is a void function that allows the user to update a value belonging to either vector. The user specifies the vector he wants to edit, the index he wants edit, and finally the updated value. The entire vector must then be printed on the screen. You need to pass the two arrays and their sizes.
- CalculateAverage: This is a function that returns the average value in a vector. It returns a double and receives as parameters an array and its size.
- printVector: A void function that takes a vector as a parameter along with its size, and prints it on the screen.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
