Question

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 wr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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;
}

CAWINDOWS\system32\cmd.exe Ci. 11 :: DATA IN ARRAY FROM FILE : 132 51 23 33 61 71 411 587 5 1230 : :: Total Number of Values

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
LEC230,0z2.SP19.51pot-AdobeAoobat Pro DC F Viw Window Help Home tools ELEC230 CZ22, SP1 Sign tn Quiz 2,...
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
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