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

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

//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) {

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

View Full Document
pressure = ((moles*R*temp)/(volume-(B*moles)))-((A*(pow(moles, 2)))/(pow(volume, 2))); cout << fixed << setprecision(0) << volume*1000;

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

View Full Document
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern