1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Musya8 [376]
3 years ago
10

You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips

that contains the number of elements in zipcodeList, and a bool variable duplicates. Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise. Use only j, k, zipcodeList, nZips, and duplicates.
Computers and Technology
2 answers:
irina [24]3 years ago
5 0

Answer:

You cant use j =0… you have to use j = k+1, otherwise j =1 and k =1 will match up and be equal when really its comparing the exact same line to itself.

Explanation:

The solution will be as follows:

duplicates = false

for (k = 0; k < nZips; k++){

   for (j = k+ 1 ; j < nZips ; j++){

     if (zipcodeList [k] ==zipcodeList[j]){

          duplicates =true

           break;

              }

        }

}

dmitriy555 [2]3 years ago
3 0

Answer:

The c++ program for the scenario is given below.

#include <iostream>

using namespace std;

int main() {    

   int i,j, nZips, zipcodeList[nZips];

   bool duplicates;        

   cout<<"This program checks if duplicate values exist in the array." <<endl;    

   cout<<"Enter the number of integers to be inserted in the array."<<endl;

   cin>>nZips;    

   cout<<"Enter the integers to be inserted in the array."<<endl;    

   for(i=0; i<nZips; i++)

   {

       cin>>zipcodeList[i];

   }    

   for(i=0; i<nZips; i++)

   {

       for(j=0; j<nZips; j++)

       {

           if(i != j)

           {

               if(zipcodeList[i] == zipcodeList[j])

               {

                   duplicates = true;

                   cout<<"The value of duplicates variable is true meaning "<<duplicates<<endl;

                   break;

               }

               else

                   duplicates = false;

           }

       }

       

       if(duplicates == true)

               break;

}    

   if(duplicates == false)

       cout<<"The value of duplicates variable is false meaning "<<duplicates<<endl;    

   return 0;

}  

OUTPUT

This program checks if duplicate values exist in the array.

Enter the number of integers to be inserted in the array.

7

Enter the integers to be inserted in the array.

1234

2345

1234

5678

9087

6554

4560

3456

6789

The value of duplicates variable is true meaning 1  

Explanation:

The variables mentioned in the question are used as required. There is no logic applied to validate user input. It is assumed that user inputs only valid values.

This program is designed to check whether duplicate values are present in the array. The boolean variable duplicates is assigned value true or false depending on the presence of duplicate values.

The user is prompted the number of values to be put in the array along with those values.

Once the array is filled, the array is checked for identical values. If any identical value is present, the value of duplicates variable is assigned to true and the loop is discontinued.

If no identical values are present, the loop completes and duplicates variables is assigned the value of false.

In either case, the value of the duplicates variable is displayed.

You might be interested in
Assume that a 5 element array of type string named boroughs has been declared and initialized. Write the code necessary to switc
hammer [34]

Answer:

Explanation:

Let's do this in python. First we can set a placeholder variable to hold the first element of the array, then we can set that first element to the last element (5th) of that array. Then we set the last element of that array to the placeholder, which has value of the original first element of the array

placeholder = boroughs[0] # in python, 0 is the first element or arra

boroughs[0] = boroughs[-1] # -1 means the last element of the array

boroughs[-1] = placeholder

6 0
3 years ago
Knowing the meaning of the acronym WYSIWYG can be most helpful to you when you
Lady_Fox [76]
<span>Knowing the meaning of the acronym WYSIWYG can be most helpful to you when you are trying to buy something. The acronym stand for "what you see is what you get" which could mean in purchase contexts that you don't get tricked in any way, you buy what you saw.</span>
6 0
3 years ago
1. What makes discrimination different from harassment? (Don't give me definitions.)
-BARSIC- [3]
Discrimination includes acting against a race whereas harassment isn’t not allowing a race to do something but instead insulting them. For example not giving someone of a certain race a job is discrimination but if someone followed a person of another race down the street calling them rude names, that’s harassment
7 0
2 years ago
Using C++
sweet-ann [11.9K]

Answer:

#include<iostream>

using namespace std;

void OutputMinutesAsHours(double origMinutes) { //Same as question

   double hours=origMinutes/60; //solution is here

   cout<<hours;

}

//Below is same as mentioned in question

int main() {

OutputMinutesAsHours(210.0);

cout << endl;

return 0;

}

OUTPUT :

3.5

Explanation:

In the above code, only two lines are added. To convert minutes into hours we have to divide them 60, so we take minutes as input and define a new variable of double type which stores minutes converted to hours and then that variable is printed to console. For 210, it gives 3.5, similarly for 3600 it gives 60 and so on.

6 0
3 years ago
Help me please, I'm attempting a test<br>​
dusya [7]
It’s A it’s a keyboard
8 0
2 years ago
Read 2 more answers
Other questions:
  • How to open CD port in PC lenovo ideapad 330​
    14·1 answer
  • Among the web programming languages, css is used to define _____ of the web page
    5·1 answer
  • An OS X backup utility that automatically backs up files to a dedicated drive that is always available when the computer is turn
    6·1 answer
  • Mobile computing has two major characteristics that differentiate it from other forms of computing. What are these two character
    8·1 answer
  • Why does brainly keep saying “oops... something went wrong! Try again”
    7·2 answers
  • This diagram shows a number of computing devices connected to the Internet with each line representing a direct connection.
    11·1 answer
  • Walmart store wants to compare the sales of five of its stores. Write a complete program to ask the user to enter the sales for
    12·1 answer
  • While surfing online, Patricia checks her email and reads the latest messages. She then browsers a website and logs in a comment
    8·1 answer
  • Grace is performing a penetration test against a client's network and would like to use a tool to assist in automatically execut
    13·2 answers
  • Me inculparon de crear una cuenta en Facebook y colocaron el barrio donde vivo, ¿cómo podría demostrar lo contrario? Ayuda urgen
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!