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...

  • 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...

  • 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...

  • 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...

  • For your second program, please read the data from the input file directly into an array....

    For your second program, please read the data from the input file directly into an array. (You may safely dimension your array to size 300.) Then close the input file. All subsequent processing will be done on the array. Your program should have two functions besides main(). The first function will print out the contents of the array in forward order, 10 numbers per line, each number right justified in a 5 byte field. The second function will print out...

  • (a) Load the data file data/tips.csv into a pandas DataFrame called tips_df using the pandas read_table()...

    (a) Load the data file data/tips.csv into a pandas DataFrame called tips_df using the pandas read_table() function. Check the first five rows. (b) Create a new dataframe called tips by randomly sampling 6 records from the dataframe tips_df. Refer to the sample() function documentation. (c) Add a new column to tips called idx as a list ['one', 'two', 'three', 'four', 'five', 'six'] and then later assign it as the index of tips dataframe. Display the dataframe. (d) Create a new...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

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