A sentimental consulting company is in charge of putting people who could have an affinity in contact
Question:
A sentimental consulting company is in charge of putting people who could have an affinity in contact so that they can meet. For this they have a program in C++ (thousands of lines of code) that is in charge of processing all the information about the clients to find those who could establish a good relationship. The program returns as a result, an array of size N PEOPLE (which is an int) of integers (compatible[ ]) which is an index to the array of people indicating the person with whom it has an affinity. (The name is not stored to maintain anonymity). For example, if compatible[10]=25 means that person 10 will like person 25, but not the other way around though.
Solution a)
/* Check all people */
int i;
for(i=0; i
/* If a person is compatible with another who is
compatible with the first, they are mutually compatible */
if( i==compatible[compatible[i]]) {
printf("%d and %d are compatible and match "i,compatible[i]);
}
Solution b)
int maxcomp=0; /* Save the maximum compatibility */
int ncomp; /* Save the compat. no. of the current person */
int indmaxcomp=0; /* Index of the most compatible */
/* Loop through all the people */
int i;
for(i=0; i
int j;
ncop=0;
for(j=0; j
/* Check if it is compatible */
if (compatible[j]==i)
ncomp++;
/* If we have a new maximum */
if(ncomp>maxcomp)
{
maxcomp=ncomp;
indmaxcomp=i;
}
}
printf("%d are compatible with %d people",indmaxcomp,maxcomp);
Solution c)
/* Check all people */
int i;
for(int i=0; i
{ 3. 4. ncop=0;
/* Check if you have someone compatible */
int j;
for(j=0; j
// If you have someone compatible we finish
if(compatible[j]==i)
{
ncop=1;
break;
}
if (ncomp==0)
printf("No one is compatible with %d ",i);
}
1. Analyze and explain which of the three previous solutions is the correct one and execute them.
2. Develop the necessary code for the correct solution in JAVA Code that displays the output of the program on the screen.
3. Write the part of the program that allows you to find all compatible associated pairs. Never mind that the couple appeared repeatedly.
4. Write the part of the program that finds the person with whom the most people are compatible.
5. Write the part of the program that finds those people with whom no one is compatible.
Foundations Of Business
ISBN: 9780357717943
7th Edition
Authors: William M. Pride, Robert J. Hughes, Jack R. Kapoor