Created
July 1, 2017 23:37
-
-
Save anonymous/f1e69f55f94fbb3d3997c3c1f9b3f63b to your computer and use it in GitHub Desktop.
reading_data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <cmath> | |
using namespace std; | |
// Main Function | |
int main() | |
{ | |
// Variables | |
float data1; // time for 30 oscillations in seconds | |
float data2; // time for 30 oscillations in seconds | |
float data3; // time for 30 oscillations in seconds | |
float avg_oscillation_time; // average of the 3 times | |
float T_period; // time for 30 oscillations divided by 30 | |
float length; // length of string from base to weight on end of string in centimeters | |
const float pi = 3.14; | |
float gravity; // this is what we are trying to figure out in cm/sec squared | |
ifstream file; // this is my file stream object | |
file.open("experiment.data"); // this is my file in the same directory | |
file >> data1 ; // data1 is the first line in the file | |
file >> data2 ; // data2 is the second line in the file | |
file >> data3 ; // data3 is the third line in the file | |
// this is my processing section | |
length=10.5; | |
avg_oscillation_time = (data1 + data2 + data3)/(3); | |
T_period = (avg_oscillation_time) / (30); | |
gravity = pow(pi,2)*(length)*(4) / pow(T_period,2); | |
// this is my display section | |
// this is the data that I extracted from the file | |
cout << "This is the data I extracted from my file. " << endl; | |
cout << endl; | |
cout << data1 << " seconds" << endl; | |
cout << data2 << " seconds" << endl; | |
cout << data3 << " seconds" << endl; | |
cout << endl; | |
cout << "My average oscillation time was " << avg_oscillation_time << " seconds" << endl; | |
cout << endl; | |
cout << "The period of the oscillations was " << T_period << endl; | |
cout << endl; | |
cout << "The gravity we got from our experiment was :" << endl; | |
cout << endl; | |
cout << "gravity" << " = " << gravity << " cm/seconds squared " << endl; | |
cout << endl; | |
cout << "I thought I could jump a bit higher today!" << endl; | |
cout << endl; | |
file.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment