C++HW4 - volume = volume increment setprecision(3...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
//Homework #4 //This program will calculate the pressure of a gas #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double moles; double temp; double start; double final; double increment; double A = 3.592; double B = .0427; double R = .08206; double pressure; cout << "Quantity if carbon dioxide (moles): " ; cin >> moles; cout << "Temperature (kelvin): " ; cin >> temp; cout << "Initial volume (milliliters): " ; cin >> start; start = start / 1000; cout << "Final volume (milliliters): " ; cin >> final; final = final / 1000; cout << "Volume increment (milliliters): " ; cin >> increment; increment = increment / 1000; cout << "\nSteve Carr\n\n" ; cout << fixed << setprecision (4) << moles << " moles of carbon dioxide at " << temp << " kelvin\n\n" ; cout << "Volume (ml)" << setw(70) << "Pressure (atm)\n-------------------------------------------\n" ; double volume = start; while (final >= volume) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
pressure = ((moles*R*temp)/(volume-(B*moles)))-((A*(pow(moles, 2)))/(pow(volume, 2))); cout << fixed << setprecision(0) << volume*1000; cout << setw(25) << setprecision (4) << pressure << endl;
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: volume = volume + increment; setprecision(3); } return (0); } //Steve Carr //Homework #4b //This program will calculate and compare the square root of a number #include <iostream> #include <iomanip> #include <cmath> #include <fstream> using namespace std; const double ERR = .00001; double x; double b; double square ( double ERR) //Pre: ERR=.00001, x > 0 { //Post: return b double r = 1; double a,b; while ( (pow(r ,2)-x) > ERR ) r = ((x/(r+r))/ 2.0); a = r; for ( int j=0;j<10;j++) { b = x; b = b/a; b = b + a; b = b/2; a = b; } return b; } int main() { setprecision(8); double math; ifstream fin; fin.open( "data.txt" ); fin >> x; cout << "Square Root Calculations by Steve Carr\n\n" ; while (!fin.fail()) { math = sqrt(x); cout << "Approximate square root: " << fixed << square(b) << endl; cout << "Math library sqrt:" << fixed << math << endl << endl; fin >> x; } fin.close(); return (0); }...
View Full Document

This homework help was uploaded on 04/18/2008 for the course COS 220 taught by Professor Roberts during the Spring '08 term at University of Maine Orono .

Page1 / 4

C++HW4 - volume = volume increment setprecision(3...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online