Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

With the code I already have, I need help with these last few small tasks in my

ID: 3723590 • Letter: W

Question

With the code I already have, I need help with these last few small tasks in my code. (C++)

#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

bool isEven(int *p)
{
   if (*p % 2 == 0)
       return true;
   else
       return false;
}

int main()
{
   int count = 0;
   int temp;
   vector<int>numbers;

   ifstream File;
   File.open("input.txt");
   while (File >> temp)
   {
       numbers.push_back(temp);
       count++;
   }
   File.close();

   cout << "Numbers read in: " << count << endl;

   File.open("evens.txt");
   count = 0;
   while (File >> temp)
   {
       if (isEven(&temp) == true)
       {
           count++;
       }
   }

   cout << "Even numers: " << count << endl;

Thanks!

Photos 14 Crop and rotate Task 3 Expand the main function so tat a file called "evens.st" is opened for writing. Write all of the even numbers that you detect to this output file, umber per line. Enhance Adjust The output printed to the screen should be the same as task 2. Light You can verify that the number of inesin the evens.xt file using the unix command "we" Color Clarity S we-l evens.tst Vignette Task 4 Add a ne function called isOdd. IsOdd should function similarly to isEven. In fact, isOdd should call isFven to determine the answer to that question. Red eye Spot fix Also add here an output file called odds.txt that contains all of the odd numbers that you discover. Sample output after task 4 Undo all H Save Numbers read in: 100009 Even numbers: 49868 Odd numbers: 5014 save a copy O Type here to search 1:02 AM 3/521118

Explanation / Answer

#include <iostream>

#include <vector>

#include <fstream>

#include <algorithm>

#include <numeric>

#include <math.h>

using namespace std;

bool isEven(int *p)

{

if (*p % 2 == 0)

return true;

else

return false;

}

bool isOdd(int *p)

{

if (*p % 2 == 1)

return true;

else

return false;

}

bool isPrime(int *n)

{

if (*n <= 1)

return false;

for (int i = 2; i < *n; i++)

if (*n % i == 0)

return false;

return true;

}

int maxElement(vector<int>numbers){

int max = *max_element(numbers.begin(), numbers.end());

return max;

}

int minElement(vector<int>numbers){

int min = *min_element(numbers.begin(), numbers.end());

return min;

}

int sumOfElements(vector<int>numbers){

int sum = accumulate(numbers.begin(), numbers.end(), 0);

return sum;

}

double meanOfElements(vector<int>numbers){

double mean = accumulate(numbers.begin(), numbers.end(), 0)/numbers.size();

return mean;

}

double Deviation(vector<int>numbers)

{

double ave = meanOfElements(numbers);

double E=0;

for(int i=0;i<numbers.size();i++)

E+=(numbers[i] - ave)*(numbers[i] - ave);

return sqrt(1/numbers.size()*E);

}

int main()

{

int count = 0;

int temp;

vector<int>numbers;

//numbers

ifstream File;

File.open("input.txt");

while (File >> temp)

{

numbers.push_back(temp);

count++;

}

File.close();

cout << "Numbers read in: " << count << endl;

//even numbers

File.open("input.txt");

count = 0;

while (File >> temp)

{

if (isEven(&temp) == true)

{

count++;

}

}

File.close();

cout << "Even numers: " << count << endl;

//oddnumbers

File.open("input.txt");

count = 0;

while (File >> temp)

{

if (isOdd(&temp) == true)

{

count++;

}

}

File.close();

cout << "Odd numers: " << count << endl;

//primenumbers

File.open("input.txt");

count = 0;

while (File >> temp)

{

if (isPrime(&temp) == true)

{

count++;

}

}

File.close();

cout <<"Prime numers: " << count << endl;

cout<<"Max value: "<<maxElement(numbers)<<endl;

cout<<"Min value: "<<minElement(numbers)<<endl;

cout<<"Sum is : "<<sumOfElements(numbers)<<endl;

cout<<"Mean is : "<<meanOfElements(numbers)<<endl;

cout<<"Deviation is : "<<Deviation(numbers)<<endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote