Respuesta :
Answer:
Following are the solution part to this question:
for(i=0;i< oldData.size()&&i< newData.size();i++) //defefing loop to assign newData value to oldData value
{
if (oldData.at(i) != newData.at(i)) //defefing if block to check count value
{
oldData = newData; //assign newData value to oldData value
break; //using break keyword
}
else //defefing else block
{
cout << "Data matches!" << endl;//print message
break; //using break keyword to exit from loop
}
}
Explanation:
The full Program to this question can be described as follows:
#include<vector>//defefing header file
#include<stdlib.h>//defefing header file
#include<iostream>//defefing header file
using namespace std;
int main() //defefing main method
{
vector<int> oldData(3); //defefing vector array oldData
vector<int> newData(4);//defefing vector array newData
unsigned int i = 0; //defefing integer variable
oldData.at(0) = 10; //initilizing value oldData
oldData.at(1) = 12;//initilizing value oldData
oldData.at(2) = 18;//initilizing value oldData
newData.at(0) = 25;//initilizing value newData
newData.at(1) = 27;//initilizing value newData
newData.at(2) = 29;//initilizing value newData
newData.at(3) = 23;//initilizing value newData
for(i=0;i< oldData.size()&&i< newData.size();i++) //defefing loop to assign newData value to oldData value
{
if (oldData.at(i) != newData.at(i)) //defefing if block to check count value
{
oldData = newData; //assign newData value to oldData value
break; //using break keyword
}
else //defefing else block
{
cout << "Data matches!" << endl;//print message
break; //using break keyword to exit from loop
}
}
for (i = 0; i < oldData.size(); ++i) //defining loop to print value
{
cout << oldData.at(i) << " ";//print oldData value
}
return 0;
}
Output:
25 27 29 23
Description of the program can be described as follows:
- In the above-given program first, we defining header file after defining header files inside the main method two vector array that is "oldData and newData" is declared which assigns some integer value.
- In the next step, a loop is declared that uses the "i" variable which starts from 0 and ends when both array sizes were same, inside the loop, and if block is declared that interchange value newData to oldData, and use the break keyword.
- In the next step another for loop is declared that prints the oldData array value.