#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int evenSumofDigit(int num)
{
int lDigit;
lDigit= num % 10; // breaking last number
if (lDigit >= 0 && lDigit <= 4) // if
last digit is between 0 to 4
return num << 1;
else
return (num << 1) + 1; // if
last digit is between 0 to 9
}
void getValues(int *array, int n) {
int j = 0;
int *evenArr = new int[n];
int *idxArr = new int[n];
for (int i = 0; i < n; i++) {
if (evenSumofDigit(array[i]) % 2 ==
0) { // if sum of digits are even then they are copied
evenArr[j] =
array[i]; // value copying
idxArr[j] = i;
// index copying
j++; //
positions for other 2 array even and index
}
}
cout << endl;
int sizeOfOther = j;
cout << ":::: Total Number of Values Copied:
::::" <<sizeOfOther<< endl<<endl;
cout << ":::: Even Sum Digit Values ::::"
<< endl;
for (int i = 0; i < sizeOfOther; i++) {
cout << evenArr[i] << "
";
}
cout << endl;
cout << endl;
cout << ":::: Index of Even Sum Digit Values
::::" << endl;
for (int i = 0; i < sizeOfOther; i++) {
cout << idxArr[i] << "
";
}
cout << endl << endl;
}
int main()
{
int *values;
int size;
int data;
int count = 0;
int i = 0;
values = new int[1000];
ifstream theFile("data.txt");
while (theFile >> data) {
if (data < 0) { // if number is
lesser than 0 then break
break;
}
else { // otherwise copy them into
array
values[i] =
data;
i++;
count++;
}
}
theFile.close();
cout << count << endl;
size = count;
cout << ":::: DATA IN ARRAY FROM FILE ::::"
<< endl;
for (int i = 0; i < size; i++) {
cout << values[i] << "
";
}
cout << endl;
getValues(values, size);
return 0;
}
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP
LEC230,0z2.SP19.51pot-AdobeAoobat Pro DC F Viw Window Help Home tools ELEC230 CZ22, SP1 Sign tn Quiz 2,...
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 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 (location) to two new arrays evenArr 1 and idxArrl I, respectively. In addition, the program must...
LECN O72 SPIS 52pd-Adobe Acobat Pro DC Id Vew Wwindow Halp ELECZ30 072 3P1 ame lools O & T O Quiz 2, Sec 52, 24/04/2019 Write a program that operates on the following array values[8] {1, 88, 0, 0, 7, 0, 8, }; The program should store every 0 and its index from this array in another two 1D arrays named zeros[ ]and index ], respectively In addition, to accomplish this task, the program should use a function findZeros (...