{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

gold - /if no error occurred while opening file/input data...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// gold.cpp / #include <iostream.h> #include <iomanip.h> #include <fstream.h> #include "apvector.h" # int main() { float x; int index; i ifstream infile_us; //declare file pointer for us information ifstream infile_japan; //declare file pointer for japan information ifstream infile_germany; //declare file pointer for germany information ifstream infile_uk; //declare file pointer for uk information / apvector <float> us(10); //declare a vector names US with 10 elements apvector <float> japan(10); apvector <float> germany(10); apvector <float> uk(10); infile_us.open("us.dat",ios::in); //open the us file for input infile_japan.open("japan.dat",ios::in); //open the japan file for input infile_germany.open("germany.dat",ios::in); //open the germany file for input infile_uk.open("uk.dat",ios::in); //open the uk file for input / if (infile_us && infile_japan && infile_germany && infile_uk)
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //if no error occurred while opening file { //input data from file { for (index=0;index<=9;index++) { infile_us >> x; us[index]=x; u infile_japan >> x; japan[index]=x; j infile_germany >> x; germany[index]=x; g infile_uk >> x; uk[index]=x; u } } else { cout << "An error occurred while opening this file.\n"; } cout.setf(ios::showpoint); cout.setf(ios::fixed); cout << setprecision(2); cout << "YEAR" << " " << setw(10) << "US" << setw(10) << "JAPAN" << setw(10) << "GERMANY" << setw(10) << "UK" << endl; for (index=0;index<=9;index++) { cout << 1980+index << " " << setw(10) << us[index] << setw(10) << japan[index] << setw(10) << germany[index] << setw(10) << uk[index] << endl; } infile_us.close(); infile_japan.close(); infile_germany.close(); infile_uk.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