C++ program. using namespace std is not allow. Write a program that stores numbe
ID: 3603645 • Letter: C
Question
C++ program.
using namespace std is not allow.
Write a program that stores numbers from a user defined range in an array of size 200
Your program should
Call a function asking the user for both the min value and the max value of the numbers (note max value in the file I'm giving you is 1000). Make sure your min is less than your max!
Call a function to fill the array from a file called numbers.txt until you have filled in the 200 numbers from that range
Ask the user for a number in the required range, the
Call a function that:
The function accepts 3 arguments - the array, the size of the array and the user's number to search the array
It should then print the location (index) of the users number or not found if it is not in the array
Next print a menu asking:
Print (O) dds - if this is selected print all the odd numbers
Print (E)vens - if this is selected print all the even numbers
Print (L)ower - if this is selected print all the numbers less than the user's number
Print (H)igher -if this is selected print all the numbers greater than the user's number
Quit
And then perform the requested action. Note the letters inside the parentesis are the expected input.
Note:
You will need many functions. Make sure your location function matches the description above, the others can be as you design them
The output should be:
Select a minimum and maximum where the minimum is less than the maximum)
Enter the min number (1 to 1000):
Enter the max number (1 to 1000):
Enter your number from 200 to 250:
Found at index: 73
Found at index: 142
Found at index: 163
Would you like to:
Print (O)dds
Print (E)vens
Print (L)ower
Print (H)igher
(Q)uit
Note:
In the menu.
If odds is selcted output should be:
Printing Odds
example:
0: 643
1: 677
3: 527
...
all odd numbers
If evens is slected output:
Printing Evens
example:
1: 360
8: 294
12: 266
...
all even numbers
If higher is selected output:
Printing Higher
example:
3: 475
4: 467
5: 471
...
all higher numbers
If lower is selected output:
Printing Lower
example:
4: 294
5: 267
8: 266
...
all lower numbers
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
int input, remainder, even = 1, odd = 1;
int *myOddData, *myEvenData; // declaring pointers
myOddData = new int [odd]; // declaring array for odds of size "odd"
myEvenData = new int [even]; // declaring array for evens of size "even"
cout << "This program accepts integers until you enter 0. Please enter a value: ";
cin >> input;
while (input != 0) {
remainder = input % 2;
if (remainder == 0) {
myEvenData[even] = input;
even++;
}
else {
myOddData[odd] = input;
odd++;
}
cout << "Enter another integer: ";
cin >> input;
}
cout << " The number of evens is " << even << ". ";
cout << "The even values are: ";
for(int i = 0; i < even; i++) {
cout << myEvenData[i] << " ";
}
cout << endl;
cout << "The number of odds is " << odd << ". ";
cout << "The odd values are: ";
for(int i = 0; i < odd; i++) {
cout << myOddData[i] << " ";
}
delete[] myOddData;
delete[] myEvenData;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.