Computers and Technology
11.05.2022 06:39
274
378
8
Solved by an expert

Write a program that gets a list of integers from a user. First, the user should

Write a program that gets a list of integers from a user. First, the user should be asked to enter the number of integers to be stored in a list. Then your program should ask for these integers and store them in the list. Finally, the program should ask the user to enter a sentinel value that will be used to search through the integers in the list which are greater than the sentinel value. For example: If the input is: 7 50 60 140 200 75 100 172 70 the output is: 140 200 75 100 172 The 7 indicates that there are seven integers in the list, namely 50 60 140 200 75 100 172. The 70 indicates that the program should output all integers greater than 70, so the program outputs 140 200 75 100 172. You should use methods in addition to the main method. getListValues to get and store the values from the user to print the values found to be greater than the sentinel value.
Show Answers
shavis123
shavis123
4,9(27 marks)

#include <iostream>

using namespace std;

void insert(int *arr, int num);

int n;

void returnGT(int arr[]);

int main(){

   cout<< "Enter the number of integers: "<<endl;

   cin>>n;

   int num[n];

   insert(num, n);

   returnGT(num);

}

void insert(int *arr, int num){

   for (int i = 0; i < num; i++){

       cout<< "Enter item "<< i + 1 << " : ";

       cin>> arr[i];

   }

}

void returnGT(int arr[]){

   int sentinel;

   cout<< "Enter sentinel: ";

   cin>> sentinel;

   for (int i = 0; i < n; i++){

       if (arr[i] > sentinel){

           cout<< arr[i] << " ";

       }

   }

}

Explanation:

The C++ source code defines an array of integer values, the program prompts for user input for the array size and the sentinel value to fill the array with input values and output integer values greater than the sentinel.

cheyennegenevie9833
cheyennegenevie9833
4,5(85 marks)
I think I would use the While loop

Popular Questions about the subject: Computers and Technology

Michelle needs to view and delete macros in a document. Which steps should...
Computers and Technology
09.02.2021 05:19
Which tab is used to configure editing restrictions in Word 2016? Review References...
Computers and Technology
22.06.2020 00:01
Nadia has inserted an image into a Word document and now would like to resize...
Computers and Technology
09.01.2021 07:47
By default, the hyperlink will display the text in the hyperlink itself, such...
Computers and Technology
07.12.2022 04:58
Link to Look in Text to Display Display Alt Text...
Computers and Technology
23.12.2022 10:34
Create and work with interfaces In this exercise, you ll create the DepartmentConstants...
Computers and Technology
02.03.2022 08:31
Please help me guys ... ....
Computers and Technology
22.11.2022 20:38
Please help me ... .......
Computers and Technology
11.01.2021 08:19
Super computer in nuclear energy...
Computers and Technology
28.10.2022 17:44
Each time that you access files on a disk, the monitor blinks or goes blank...
Computers and Technology
19.02.2021 18:31

New questions by subject

Which sentence best explains how the tone reveals the narrator perspective...
English
07.02.2020 09:23
Write a five paragraph or more story about anything...
English
28.03.2023 12:34
Aand b are vertical angles. if angle a=(7x-5) and b=(5x+27) ∘ , then find...
Mathematics
24.09.2020 18:34
What would whitman think about people memorizing his poem and studying it...
History
20.03.2020 13:54
What does the boxer rebellion and the open door policy have to do with us...
History
12.03.2023 17:09
Organisms lacking a nucleus or defined organelles. microbial bodies thriving...
Biology
13.12.2021 08:25
Multiple to list the next five multiples of 3...
Mathematics
14.01.2020 12:00
How does the 14th amendment protect citizens today from discrimination?...
History
16.04.2020 16:08
3. graham uses a hot water bottle on an injury to his back he incurred playing...
Mathematics
23.07.2022 00:16
9. how can the location of a fossil reveal its age? explain ayour answer....
Biology
02.01.2020 16:42
#
#
#
#
# #

We expand our knowledge with many expert answers