Ask Question
13 April, 08:18

If the vector oldData is the same as the vector newData, print "Data matches!" ended with a newline. Otherwise, assign oldData with newData. Ex: If oldData = {10, 12, 18} and newData = {25, 27, 29, 23}, then oldData becomes {25, 27, 29, 23}.

Only enter the Solution Part

#include

#include

using namespace std;

int main () {

vector oldData (3);

vector newData (4);

unsigned int i = 0;

oldData. at (0) = 10;

oldData. at (1) = 12;

oldData. at (2) = 18;

newData. at (0) = 25;

newData. at (1) = 27;

newData. at (2) = 29;

newData. at (3) = 23;

/ / Enter Solution here

for (i = 0; i < oldData. size (); + +i) {

cout << oldData. at (i) << " ";

}

cout << endl;

return 0;

}

+4
Answers (1)
  1. 13 April, 11:35
    0
    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//defefing header file

    #include//defefing header file

    #include//defefing header file

    using namespace std;

    int main () / /defefing main method

    {

    vector oldData (3); / /defefing vector array oldData

    vector 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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “If the vector oldData is the same as the vector newData, print "Data matches!" ended with a newline. Otherwise, assign oldData with ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers