Question

Write a program that uses an int one-dimensional array list to input 10 integers representing amounts of money. Find the highest (maximum) amount and the lowest (minimum) amount. Output all the amounts and their difference to the highest amount side by side as shown in the sample output.

Chapter #8 (Arrays) and 6 (Value Returning and void Functions) Exercise #1: One-dimensional array manipulation Write a progra


c++
0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <bits/stdc++.h> //include the libraray using namespace std; int getMin(int arr[]) //function to find the minimum in array { int res = arr[0]; //res variable store the minimum for (int i = 1; i < 10; i++) //loop on array of 10 integers res = min(res, arr[i]); //min() function to find the minimum return res; //return the minimum value } int getMax(int arr[]) //function to find the maximum in array { int res = arr[0]; //res variable to store the maximum for (int i =1 ; i < 10; i++) //loop on array of 10 integers res = max(res, arr[i]); //max() function to find the maximum return res; //return the maximum value } int main() {     int a[10];//array of 10 integers        cout<<"Enter 10 amounts of money: "<<endl;  for(int i=0;i<10;i++) //loop for input of array      {        cin>>a[i];       //input array   }       cout<<"The highest amount is "<<getMax(a)<<endl; //call the getMax() function         cout<<"The lowest amount is "<<getMin(a)<<endl; //call the getMin() function  cout<<"The amount and their difference from the largest are:"<<endl;        cout<<"--------------------------"<<endl;   cout<<"Amount Difference"<<endl;    cout<<"--------------------------"<<endl;   for(int i=0;i<10;i++)        {       cout<<" "<<a[i]<<" "<<getMax(a)-a[i]<<endl; //print the array and difference of array value and maximum value }   return 0; } 

#include <bits/stdc++.h> //include the Library using namespace std; int getMin(int arr()) // function to find the minimum inEnter 10 amounts of money: 258 369 1236 258 12 396 1258 852 990 1865 The highest amount is 1865 The lowest amount is 12 The a

Add a comment
Know the answer?
Add Answer to:
Write a program that uses an int one-dimensional array list to input 10 integers representing amounts...
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
  • 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:...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize...

    Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize your array using a text file, user input or assign value while declaring the array, you can choose the method. Then, a. Write a loop to print first row of the array on one line, using cout. b. Write a loop to print first column of the array on one line, using cout. c. Write a loop to print first five rows of the...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • Please do this by JAVA!!!!!!! This program can assume all inputs are integers representing whole dollar...

    Please do this by JAVA!!!!!!! This program can assume all inputs are integers representing whole dollar amounts. 1) Ask the user for a stake amount (initial amount of money available to bet). Check to make the sure user enters a correct number (over 0). State a descriptive error to re-prompt the user if the stake amount is not a correct amount like a negative number). 2) Ask the thrower for their bet. The amount of money the thrower has to...

  • The XYZ Company needs you to write a program that will allow them to enter the...

    The XYZ Company needs you to write a program that will allow them to enter the weekly sales for a salesperson and then the program will calculate things such as most sales (and what day on which they happened), least sales (and day on which they happened), total sales, and daily average. The program will need to do the following: • Validate the user input to ensure that it is not less than 0.0 (0.0 will be acceptable if there...

  • write a C++program to analyze a small subset of the data that has been collected. See...

    write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the...

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12]

    1.      Write a C or C++ program A6p2.c[pp] that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 39 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to convert all 60 array elements modulo 11 (i.e. take the remainder after division by 11) in place. You should divide this update task among the n threads as evenly as possible. Print the array both before and after...

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