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

Info icon This 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) {
Image of page 1

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

View Full Document Right Arrow Icon
pressure = ((moles*R*temp)/(volume-(B*moles)))-((A*(pow(moles, 2)))/(pow(volume, 2))); cout << fixed << setprecision(0) << volume*1000;
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern