Question

In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays to keep track of the numb

Write down ONLY the complete function findMost Subs.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

given data:

void findMostSubs(string publ[],int subs[], string * publication, int * nrsub)
{
   *nrsub=0; //to store max subscribers ...function is call by reference
   int index=0; //index of array elements
   int max_index=0; //index of max subscribers
   for(;index<50;index++)
       if(*nrsub<subs[index])
       {
           max_index=index; //whenever nrsub is less than subs[index] change max_index and nrsub.
           *nrsub=subs[index];
       }
   *publication=publ[max_index]; //finally store max_index element from publications to mostSubscriptions .
}

//code is tested with main in the below format:please find the code:

#include<iostream>
#include<string>
using namespace std;
const int NUM_PUBS=50; //number of publications
void findMostSubs(string publ[],int subs[], string * publication, int * nrsub)
{
   *nrsub=0;
   int index=0;
   int max_index=0;
   for(;index<50;index++)
       if(*nrsub<subs[index])
       {
           max_index=index;
           *nrsub=subs[index];
       }
   *publication=publ[max_index];
}

int main()
{
   string pulbications[NUM_PUBS]={"a","b","c","d","f"};
   int subscriptions[NUM_PUBS]={1,2,3,1,7};
   int nrMostSubsriptions;
string mostSubscriptions;
   findMostSubs(pulbications,subscriptions,&mostSubscriptions,&nrMostSubsriptions);
   cout<<"most number of subscribers are="<<nrMostSubsriptions<<" for publication "<<mostSubscriptions<<endl;
}

  
output:

Your Code's Output

most number of subscribers are=7 for publication f

please give me thumb up

Add a comment
Know the answer?
Add Answer to:
In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 3 13 marks In this question you have to write a complete function. MyMedia Publishers...

    QUESTION 3 13 marks In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays to keep track of the number of subscriptions for each of their 50 publications. Array publications holds the names of the magazines and newspapers published and array subscriptions holds the number of subscriptions for each corresponding magazine or newspaper. You have to write a void function, called findMost Subs to determine which publication has the most subscribers. Function findMost Subs...

  • In this question you have to write a complete function. in C++ MyMedia Publishers uses two...

    In this question you have to write a complete function. in C++ MyMedia Publishers uses two parallel arrays to keep track of the number of subscriptions for each of their 50 publications.    Array  publications holds 1)  the names of the  magazines and newspapers  published and  array  subscriptions 2)holds  the  number  of  subscriptions  for  each  corresponding  magazine  or newspaper. You  have  to write  a  void function, called  findMostSubs to  determine  which  publication has  the  most  subscribers. Function findMostSubs has to return the name of the publication as well as the number of subscribers to that publication. Assume the following: • a declaration of a global constant: const...

  • QUESTION 3 13 marks In this question you have to write a complete function. MyMedia Publishers...

    QUESTION 3 13 marks In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays to keep track of the number of subscriptions for each of their 50 publications. Array publications holds the names of the magazines and newspapers published and array subscriptions holds the number of subscriptions for each corresponding magazine or newspaper. You have to write a void function, called fi ndMost Subs to determine which publication has the most subscribers. Function findMbst...

  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

  • This project will allow you to practice with one dimensional arrays, function and the same time...

    This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor. General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams. Write a complete C++ program including comments to do the following: Create the following: •a string array that holds the names of the teams •an integer array that...

  • In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different...

    In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different types of known parameter lists which are either void DisplayMax(string idI, double value[], int size) or void DisplayMax(int idn, short value几int size). The first and second parameters are parallel arrays. (Parallel Arrays are two arrays whose data is related by a common index. For example: with the string array and double array, index 5 of the string array would have some name, and index...

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT