Question

Please help with this C++ problem using Array

Question #1: Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100. As each number is read validate it and store it in the array. After reading all the values display only the unique values that the user entered. Make sure you account for the worst case scenario in which all 20 numbers are different. Use the smallest possible array to solve this problem.

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

C++ Program :

#include <iostream>
using namespace std;

int main() {
   // using array as map. I store the input numbers in the given map
   int map[101],n;
   for(int i=0;i<=100;i++){
       map[i] = 0;
   }
   for(int i=1;i<=20;i++){
       cout<<"Input a number between 10 and 100 :";
       cin>>n;
       //Store the number in a map
       map[n] = 1;
       cout<<endl;
   }
   cout<<"printing unique numbers"<<endl;
   for(int i=10;i<=100;i++){
       //Output the number if the map is not equal to 0
       if(map[i]!=0){
           cout<<i<<endl;
       }
   }
   return 0;
}

OUTPUT:

Success time: 0 memory: 16064 signal:0

Input a number between 10 and 100 : 10
Input a number between 10 and 100 : 10
Input a number between 10 and 100 : 10
Input a number between 10 and 100 : 11
Input a number between 10 and 100 : 11
Input a number between 10 and 100 : 12 
Input a number between 10 and 100 : 13
Input a number between 10 and 100 : 13
Input a number between 10 and 100 : 13
Input a number between 10 and 100 : 13
Input a number between 10 and 100 : 13
Input a number between 10 and 100 : 14 
Input a number between 10 and 100 : 14
Input a number between 10 and 100 : 15
Input a number between 10 and 100 : 16
Input a number between 10 and 100 : 17 
Input a number between 10 and 100 : 18
Input a number between 10 and 100 : 19
Input a number between 10 and 100 : 20
Input a number between 10 and 100 : 22
printing unique numbers
10
11
12
13
14
15
16
17
18
19
20
22
Add a comment
Know the answer?
Add Answer to:
Please help with this C++ problem using Array Use a one-dimensional array to solve the following...
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++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array...

    C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the "worst case" in which all...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • Read 20 integers into an array. Next, use the unique algorithm to reduce the array to...

    Read 20 integers into an array. Next, use the unique algorithm to reduce the array to the unique values entered by the user. Use the copy algorithm to display the unique values.

  • Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...

    Please solve this question using c++ language Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...

  • java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...

    java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array of 1000 integers. Name the array: x 2. Assign 95 to the ninth element, 25 to the twentieth element of array x. 3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x. 4. Display the sixtieth element of the array. 5. Use the for statement to generate all indexes to read and display all elements in...

  • C# Use a one-dimensional array to solve the following problem: A company pays its salespeople on...

    C# Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write an application (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges...

  • PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE...

    PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE COMPLETE ALL ASPECTS OF PAPER THANK YOU!!! Objectives To learn to code, compile and run a program containing ARRAYS. . Assignment Plan and code a modular program utilizing arrays. Use at least three functions to solve the problem. Input numbers from a textfile. Input the numbers, one by one. Store the even numbers in one array. Store the odd numbers in a second array....

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