Question

Write a function called expensiveBooks which receives a double array of book prices and the number...

Write a function called expensiveBooks which receives a double array of book prices and the number of books.

Return the total number of books that are priced over 100.0.

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

FUNCTION

int expensiveBooks(double *price,double *nob)
{
    int count=0;
    int i;
    for(i=0;i<n;i++)
    {
       if(*(price+i)>100)
       count =count +*(nob+i);
   }
   return count;
}

PROGRAM

#include<iostream>
#include<iomanip>
using namespace std;
int n;
//method to count the number of books that are greater than 100 price
int expensiveBooks(double *price,double *nob)
{
    int count=0;
    int i;
    for(i=0;i<n;i++)
    {
       if(*(price+i)>100)
       count =count +*(nob+i);
   }
   return count;
}
//driver program
int main()
{
   int i;
   //ask for numbe of data you want to enter
   cout<<endl<<"Enter the number of data ";
   cin>>n;
   //allocate the size of array
   double *price = new double[n];
   double *nob = new double[n];
   //input the prices for books
   cout<<endl<<"Enter the prices for "<<n<<" number of books";
   for(i=0;i<n;i++)
   cin>>*(price+i);
   //enter the number of copies
   cout<<endl<<"Enter the number of books for "<<n<<" books";
   for(i=0;i<n;i++)
   cin>>*(nob+i);
   //display the book details
   cout<<endl<<"Book Details"<<endl;
   cout<<endl<<"Number of Books Price of Books"<<endl;
   for(i=0;i<n;i++)
   cout<<endl<<" "<<*(nob+i)<<"\t\t\t"<<*(price+i);
   //display the result
   i=expensiveBooks(price,nob);
   cout<<endl<<" There are "<<i<<" Number of books above price 100.00";
     
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a function called expensiveBooks which receives a double array of book prices and the number...
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
  • C++ ( Please Read) Write a function prototype and a function definition called getTotal that receives...

    C++ ( Please Read) Write a function prototype and a function definition called getTotal that receives an  array of type double, the number of rows in the array. It returns the total of all elements in the array.

  • C++ Programme Write a function that receives, as arguments, a pointer to a double array, as...

    C++ Programme Write a function that receives, as arguments, a pointer to a double array, as well as the number of elements: in the array(int). The function must use pointer operations and calculate the standard deviation of the elements in the array. The function returns the standard deviation to the calling statementſ Use the function in main( to display its operation. | Example: array = (11.2, 2.4, 3.13, 16.4, 5.8, 9.22, 4.9, 10.5, 6.5, 2.99) std Dev(array) = 4.249367 ZWI...

  • 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...

  • Write a function called addNeighbors that takes an array of numbers and adds each number in...

    Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next to it. The array will always have an even number of numbers in it. In the end you should return an array of neighbors added up. Please use JavaScript Instructions from your teacher. Medium Question #4 Write a function called addNeighbors that takes an array of numbers and adds each number in the array to the number next...

  • Write a function template named summarray, with two parameters: and array called are and an int...

    Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?   

  • In C++ Write a function called fillArray that will fill an array of any constantly declared...

    In C++ Write a function called fillArray that will fill an array of any constantly declared array size variable with random numbers in the range of 1 - 100. Write a function called printArray that will print an array of any size. Write a third function called countEvens which will count and return the number of even numbers in the array. In main create an array that holds 25 ints. Use your functions to fill, print, and count the number...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • Please code using C++ Thank you Write a function that receives a 2d array of type...

    Please code using C++ Thank you Write a function that receives a 2d array of type double and returns the average of all elements in the 2d array

  • Write a function named stats, that takes an array and the number of elements in the...

    Write a function named stats, that takes an array and the number of elements in the array as arguments. It must compute and print the minimum value in the array, maximum value in the array and the average value of all the values inside the array. Your function MUST be named stats Your function has two parameters in the following order: an array of type double The number of elements in the array, type int Your function should NOT return...

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

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