1 answer

I need the following done in C++ formatting and please use while statement instead of for....

Question:

I need the following done in C++ formatting and please use while statement instead of for.

Write a program called vectorMismatch.c that that reads 2 vectors of 10 positive integers the prints a count of how many time

Write a program called vectorMismatch.c that that reads 2 vectors of 10 positive integers the prints a count of how many times the 2 vectors have the same value in the same position just as in the previous exercise) and how many times the vectors have the same value but in a different position. Note you have to avoid double-counting -carefully examine the examples below to understand whats wanted Your program must match the examples below perfectly. Your program can assume it is given correct input (20 positive integers). Your program must break down the problem into suitable functions /vectorMismatch Enter vector 1 of 10 positive numbers: 55515 5 255 5 Enter vector 2 of 10 positive numbers: 6661 6 266 6 6 Vectors match in 1 positions. Vectors mismatch in 1 positions.

Answers

Please follow the below code and use comments to better understand the code.

SOURCE CODE:

#include <iostream>
#include <vector>
using namespace std;

//Returns the count of matched elements in the two vectors.
int posMatchCount(vector<int> v1,vector<int> v2)
{
int count=0;
int i=0;
while(i<10)
{
if(v1.at(i)==v2.at(i))
count++;
i++;
}
return count;
}

//Returns the count of mis-matched elements in the two vectors.
int MisMatchCount(vector<int> v1,vector<int> v2)
{
int count=0;
int i=0;
while(i<10)
{
int j=0;
while(j<10)
{
//Positions should not be same. so check for i!=j
if(v1.at(i)==v2.at(j) && i!=j)
count++;
j++;
}
i++;
}
return count;
}

//Testing our functions
int main()
{
vector<int> vector1 (10);
cout<<"Enter Vector 1 of 10 positive numbers: ";
// read 10 values into vector 1
for (int i=0; i<10; i++)
cin>>vector1.at(i);

vector<int> vector2 (10);
cout<<"Enter Vector 2 of 10 positive numbers: ";
// read 10 values into vector 2
for (int i=0; i<10; i++)
cin>>vector2.at(i);
  
int count1=posMatchCount(vector1,vector2);
int count2=MisMatchCount(vector1,vector2);
  
//Print the results
cout<<"Vectors match in "<<count1<<" Positions."<<endl;
cout<<"Vectors mismatch in "<<count2<<" Positions."<<endl;
return 0;
}

=====================================

SCREENSHOT FOR CODE:

=====================================

1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 //Returns the count of matched elements in the two vecto

==========

SAMPLE OUTPUT:

Result compiled and executed in 36.497 sac(s Enter Vector 1 of 10 positive numbers: 5 5 5 15 5 2 55 5 Enter Vector 2 of 10 po====================================

   Please comment down here in the comment box if you have any doubts.

   Please hit the LIKE Button if you liked the answer.

====================================

.

Similar Solved Questions

2 answers
Horace buys #2 3/4# pounds of blueberries for a pie. He needs #48# ounces of blueberries for the pie. How many more pounds of blueberries does he need to buy?
Horace buys #2 3/4# pounds of blueberries for a pie. He needs #48# ounces of blueberries for the pie. How many more pounds of blueberries does he need to buy?...
1 answer
4. Juan deposits of $1,000 in a savings account that pays 8% compounded annually. Exactly 2...
4. Juan deposits of $1,000 in a savings account that pays 8% compounded annually. Exactly 2 years later he deposits $3,000; 2 years later he deposits $4,000; and 4 years later he withdraws all of the interest earned to date and transfers it to a fund that pays 10%compounded annually. How much money ...
1 answer
Please help! please writw in detail and clearly . 4. [20 Points] The time required for...
please help! please writw in detail and clearly . 4. [20 Points] The time required for an automotive center to complete an oil change service on an automobile approximately follows a normal distribution, with a mean of 19 minutes and a standard variance of 9 minutes. (a) The automotive center gu...
1 answer
U. 107 y. 10° Q.10 (kg/m) 0.9950 (kJ/kg.K) 1.009 (N.s/m?) 208.2 (mʻ/s) 20.92 k. 10 (W/m.K)...
u. 107 y. 10° Q.10 (kg/m) 0.9950 (kJ/kg.K) 1.009 (N.s/m?) 208.2 (mʻ/s) 20.92 k. 10 (W/m.K) 30.0 (m²/s) 29.9 Pr 0.700 Air at p = latm enters a thin-walled long tube at an inlet temperature of Tmi = 100 °C. The diameter and length of the tube are 5 mm and 2 m respectively. A constant...
1 answer
How does lightning work?
How does lightning work?...
1 answer
QUESTION 29 In setting their pay structures, companies use a procedure known as performance assessment, which...
QUESTION 29 In setting their pay structures, companies use a procedure known as performance assessment, which determines the worth of each job by determining the market value of the knowledge, skills, and requirements needed to perform it True False QUESTION 30 The first selection device that most j...
1 answer
QUESTION B1. (7 marks) This question assumes the following relational schema Employee (employeeNumber, lastName, firstName, DOB,...
QUESTION B1. (7 marks) This question assumes the following relational schema Employee (employeeNumber, lastName, firstName, DOB, HireDate, Position Salary, Dept) Primary Key: employeeNumber Foreign key: Dept refers to DeptID in Department Department (DeptID, DeptName, DeptLocation) Primary Key: Dept...
1 answer
Problem 5 (18 points): The formation of ozone in the atmosphere occurs via a two-step process....
Problem 5 (18 points): The formation of ozone in the atmosphere occurs via a two-step process. First, sunlight causes the reaction: Step 1: 02(g) → 20(9) Then, as the free 0 atoms move through the atmosphere, they collide with another Oz: Step 2: 0(g) + O2(g) → 03(9) a. (6 points) Determin...
1 answer
The Navarro Frenk & White (NFW) model describes the (spherically symmetric) haloes of dark matter that...
The Navarro Frenk & White (NFW) model describes the (spherically symmetric) haloes of dark matter that form in cosmological simulations. It says that the density of dark matter follows the distribution , where is the distance from the center of the halo, and is an arbitrary length. Show (usin...
1 answer
11. An E-field, as shown below, can be described by the function Ē(x, y) = (5...
11. An E-field, as shown below, can be described by the function Ē(x, y) = (5 kg/C-s-m?)a’yk. What is the flux of electric field through a rectangle, with one corner placed at the origin, that is 3 meters long in the r-direction and 4 meters long in the y-direction? Show all steps for ful...
1 answer
If a 10g mass is oscillating in simple harmonic motion with a spring constant of 2N/m,...
If a 10g mass is oscillating in simple harmonic motion with a spring constant of 2N/m, find the time for one full oscillation (period)....
1 answer
Appendix PR 3-5B Cost of production report: average cost method Blue Ribbon Flour Company manufactures flour...
Appendix PR 3-5B Cost of production report: average cost method Blue Ribbon Flour Company manufactures flour by a series of three processes, beginning in the Milling Department. From the Milling Department, the materials pass through the Sifting and Packaging departments, emerging as packaged refine...
1 answer
CODING IN PYTHON: Assume a customer is at a store purchasing exactly 4 items. The cashier...
CODING IN PYTHON: Assume a customer is at a store purchasing exactly 4 items. The cashier inputs the items and their prices into the computer. Someone has provided the cashier a Python program that does the following: 1. Asks cashier for name of each item (use short names like nails, paint, etc.) 2....
1 answer
1.2. Assume you need to evaluate an ecotouristic project. Each year the project requires maintenance costs...
1.2. Assume you need to evaluate an ecotouristic project. Each year the project requires maintenance costs equal to $200 and you have benefits (income) of $500. Except for the first year when you invest $1,000 and you have zero income. The market interest rate is 5% What is the Net Present Value of ...
1 answer
Determine the molar solubility (S) of Zn(CN)2 in a solution with a pH=5.06. Ignore activities. The...
Determine the molar solubility (S) of Zn(CN)2 in a solution with a pH=5.06. Ignore activities. The Ksp for Zn(CN)2 is 3.0×10−16 TheKa for HCN is 6.2×10−10...