Question

C++ How to find data from columns of data. I'm opening a file that has data...

C++ How to find data from columns of data.

I'm opening a file that has data values in random order that I need to find values for, I need to able to do this for any length of the column and I'm not allowed to use an array or functions. I need to do this with a loop preferably.

For example:

4435         5345345

5435534   5345

45            543543

How would I find:   (5345345 - 4435) / ( 4435 + 5345345)

                       + (5345 - 5435534) / ( 5435535 + 5345)

                           + (543543 - 45) / (45 + 543543) )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<fstream>
using namespace std;

int main()
{
float columnData=0;
fstream colfile("colmnsdata.txt", ios_base::in);
int a,b;
while (colfile >> a>>b)
{
columnData+=(b-a)/(float)(a+b);
//cout<<a<<" " <<b<<endl;
}

cout<<"column data:"<<columnData<<endl;
return 0;
}

colmnsdata.txt

4435 5345345
5435534 5345
45 543543

OUTPUT:

column data :1.00014 Process returned 0 〈0x0〉 execution time : 0-100 s Press any key to continue

Add a comment
Know the answer?
Add Answer to:
C++ How to find data from columns of data. I'm opening a file that has data...
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
  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • *Suppose I have a C++ Text File That Looks Like This:* Text File: 10 20 30...

    *Suppose I have a C++ Text File That Looks Like This:* Text File: 10 20 30 40 11 40 50 60 12 50 60 70 I want to be able to read the 3rd column which have the numbers "30 , 50, 60" and find their average. How do I read data from a text file in columns instead of rows?

  • In C++, how would I read data from a .txt file into an array? For example,...

    In C++, how would I read data from a .txt file into an array? For example, I have an assignment that requires me to read temperatures from a file named data.txt into an array. How would I go about doing this?

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • The following code is from a C++ file. What I'm wondering/looking for is if there's another...

    The following code is from a C++ file. What I'm wondering/looking for is if there's another way to insert numbers 1-100 in a random order. I don't think you should need the code for BinarySearchTree.h, but if you do, copy and paste the link below into your browser for it. https://justpaste.it/30xml /* * Create another integer Binary Search Tree. Insert the numbers from 1 to 100 in a random order. * Then search for all 100 numbers in the tree...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • You have a data file with 2 columns of data (One control and One experimental). One...

    You have a data file with 2 columns of data (One control and One experimental). One column of data has 62 data points. The other column of data has 60 data points. You wish to do a t test on this data set in R. You successfully upload the data set into R but you find that R gives you an error when you try and do a simple t test on the data. What is the problem with this...

  • how can I Use fscanf() inside a loop to read each line in C language? also...

    how can I Use fscanf() inside a loop to read each line in C language? also how can I take the values from the file and add them together for example if the file contents are 2 4 6 I want to read the first line and add 2 then the second one and add 4 and then the third and 6 and finally return the total 12 and stop reading. I do not want to store the values in...

  • In C++. I'm not too sure how to start this. Any help would be appreciated. 1st...

    In C++. I'm not too sure how to start this. Any help would be appreciated. 1st picture is the problem. The 2nd is the data file. Write a routine that reads enrollment data about students in seven colleges for years 2010-2016 from a data file (problem 6.dat) into a 7x7, 2-D array of integers - the file is organized with 7 whole numbers per line, separated by a single space. Your main() should declare/create the array, call the routine to...

  • problem2, the file "Test_Data.xlsx" contains in cylinder pressure data from a firing engine. the data is...

    problem2, the file "Test_Data.xlsx" contains in cylinder pressure data from a firing engine. the data is resolved in crank angle degree and is taken every 1/2 degree. O tittps/ualearn blackboard.com/bbcswebdav/pid plot a new function on the same graph overwriting the orizinal function 1 of11ρ Functions to choose from: y A sin(Bx C)+ D y A sin2(Bx+ C) + D y A In(Bx + C)D y A exp(Bx + C)+ D ž. The file "Test Data.xlsx" contains in-cylinder pressure data from...

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