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

Write a complete c++ program to do the following (you can, if you wish, use one

ID: 3843642 • Letter: W

Question

Write a complete c++ program to do the following (you can, if you wish, use one or more function): Read in two integers from a data file and process them as described below. Read and process value repeatedly until you come to the end of the file. You may select the name for the data file. Write to a separate output file (you can select the name for the output file) the integer that were values read in. For each set of two values, write to the output file whichever one of the following messages is appropriate (assume that 0 is positive.) Make as few tests (comparisons) as possible. a - both values are positive b - one value is positive and the other is negative c - neither value is positive For example, suppose the data file holds 11 -5 -9 -1

Explanation / Answer

#include <iostream>
#include <fstream> // For reading and writing files
using namespace std;
int main()
{
std::fstream myfile("C:\data.txt", std::ios::in);
std::fstream output_file("C:\output.txt", std::ios::out);
int a;
int counter = 0;
while (myfile >> a)
{
counter += 1;
int x,y;
if(counter == 1)
x=a;
output_file << a ;
if(counter == 2) // After reading a set of two values assign value according to the logic
{
y=a;
if(x>0 && y>0) // Guessing that you are not taking 0 as positive
output_file <<"-> 0 "; // Asigning zero for both positive
else
if((x>0 || y>0 )&& (x<0 || y<0))
{
output_file <<"-> 1 "; // Assigning 1 for either one is positive and another one is negative
}
else
if(x<0 && y<0)
output_file <<"-> -1 "; // Assigning -1 when both the values are negative
counter=0; //reset the counter
}
}

getchar();

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