Question
In c++ visual studio
Write a program that does the following: Reads th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hii there I have tried my best to write the program for the same .I guess this may help you out.

#include <iostream>

#include <fstream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

ifstream myfile;

int n;

double x[n],y[n];

myfile.open("data.txt");

cout << "Enter the no of data points to be entered (let it be less than 100) :\n";

cin >> n ;

if (myfile.is_open())

{

for ( int i = 0 ; i < n ; ++i)

{

myfile >> x[i]; // will store all the values of x from "data.txt";

myfile >> y[i]; //will store all the values of y from "dat.txt";

}

}

double xsum = 0 , x2sum =0 , ysum=0 , xysum = 0 ;

for (i=0 ; i<n ; i++)

{

xsum = xsum + x[i]; //calculate sigma x as the sum of x values

ysum = ysum +y[i]; //calculate sigma y as the sum of y values

x2sum = x2sum + pow(x[i] , 2); //calculate sum of the squares of the x values

xysum = xysum + x[i] * y[i]; //calculate the sum of the products of the corresponding x and y values

}

avg1= xsum/n; //calculate average of x values

avg2 =ysum/n; //calculate average of y values

m = ((xysum) - (xsum*avg1)) / ((x2sum) - (xsum*avg2)) ; // calculates slope m

c = (avg2 - (m.avg1)); // calculates intercept c

cout << " \n The slope of the given set of values is : \n "<< m << endl;

cout << " \n The intercept of the given set of values is : \n" << c <<endl;

}

Add a comment
Know the answer?
Add Answer to:
In c++ visual studio Write a program that does the following: Reads the input data set...
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