#include <iostream>
#include <fstream>
using namespace std;
int EvenSumDigits(int val){
int sum = 0;
while(val !=0){
sum = sum + val%10;
val = val/10;
}
return sum%2;
}
void getValues(int *Arr, int n){
int evenArr[10000], val = 0, id = 0, idxArr[10000];
for(int i=0 ; i<n ; ++i){
if(!EvenSumDigits(Arr[i])){
evenArr[val++] = Arr[i];
idxArr[id++] = i;
}
}
for(int i=0 ; i<val ; ++i){
cout<<evenArr[i] <<" "<<idxArr[i] <<endl;
}
cout<<"Number of elements: "<<val<<endl;
}
int main() {
int values[10000], val, n = 0, choice;
ifstream iFile("data.txt");
if(!iFile)
{
cout << "Error! the requested file data.txt'" << "' was not found" << endl;
cout << "Exiting ..." << endl;
exit(-1);
}
int sum = 0, min = 1000000, max = -1000000;
while (iFile >> val){
if(val < 0)
break;
values[n++] = val;
}
int evenArr[10000], idval = 0, id = 0, idxArr[10000];
for(int i=0 ; i<n ; ++i){
if(!EvenSumDigits(values[i])){
evenArr[idval++] = values[i];
idxArr[id++] = i;
}
}
for(int i=0 ; i<idval ; ++i){
cout<<"Value = "<<evenArr[i] <<" id = "<<idxArr[i] <<endl;
}
cout<<"Number of elements: "<<idval<<endl;
getValues(values,n);
}
=======================================================
SEE OUTPUT
Thanks, PLEASE COMMENT if there is any concern.
c++ write a program that reads all values from a text file "data.txt" and stores them in ID array valuesl I. The input process from the file should be terminated when a negative value is detec...
LEC230,0z2.SP19.51pot-AdobeAoobat Pro DC F Viw Window Help Home tools ELEC230 CZ22, SP1 Sign tn Quiz 2, Sec 51, 28/04/2019 write a program that reads all values from a text file "data.txt" and stores them in 1D array values The input process from the file should be terminated when a negative value is detected. (An example of such a file is shown below). Also, the program should copy from values[1 any value which has even sum of digits and its Index...
Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...
Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements.
Write a C++ program that reads in 6 elements from the keyboard and stores them in an array x[6]. It should then create a second array y[6] that contains the elements from x in reverse order and with the s Tsecond - Tsmallest shown below. A sample run should look like: rocted ITrom it (e.g., Jlast first Tsmallest Vsecond last , etc). The program should finally print out both arrays to screen, in the format Enter 6 array elements: 4...
Create a C++ program that reads in from a file numbers.txt and stores each value of each line into a two dimensional array ( int array [4][4] ) The array should be filled row by row from left to right. numbers.txt : 1,8,7,3 3,5,9,2 2,4,6,2 9,3,6,2
C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...
1) Write a C program that reads a hexadecimal value from the keyboard and then stores the value into an unsigned char variable. Read two int values p and n from the keyboard, where the values are less than 8. Implement the following commands: S – sets the n bits starting at position p to 11..1 R – resets the n bits starting at position p to 00…0 F – flips the n bits starting at position p to their...
C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...
write a complete Java program with comments in main and in each method. Data: The input data for this program is given as two columns of numbers. All data will be entered from a fle named input.txt and all output will go to the screen Assume there will not be more than 100 7 23.56 16 88.12 10 75.1 Design a Java class with a main method that does the following 1) Reads the data into two arrays of doubles,...
C Program Question: Write a program that reads all integers that are in the range of 0 to 100, inclusive from an input file named: a.txt and counts how many occurrences of each are in the file. After all input has been processed, display all the values with the number of occurrences that were in are in the input file. Note: The program ignores any number less than 0 or greater than 100. Note: Do not display zero if a...