Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to follow or put in order an algorithm for thisproblem. this is the quest

ID: 3617593 • Letter: I

Question

I need to follow or put in order an algorithm for thisproblem. this is the question. Given an input file stream, read a file name interactively andopen the file for the input file stream.
  • If a file does not exist, print an error message and thenrepeat the request for the user to enter another file name.
  • while concept with priming read
 Parameter: ifstream& myIn: input file stream
here is what I've done: your Solution File: Use the input file stream filename to openthe file myIn prompt for myIn read a file name read a string to variable myIn while Drag oneor more operations from the operation list Bool: file open was notsuccessful ! (myIn) (not) is true, repeat Drag oneor more operations from the operation list Print error message print -1 prompt for filename Read a file name read a string to variable myIn I need to follow or put in order an algorithm for thisproblem. this is the question. Given an input file stream, read a file name interactively andopen the file for the input file stream.
  • If a file does not exist, print an error message and thenrepeat the request for the user to enter another file name.
  • while concept with priming read
 Parameter: ifstream& myIn: input file stream
here is what I've done: your Solution File: Use the input file stream filename to openthe file myIn prompt for myIn read a file name read a string to variable myIn while Drag oneor more operations from the operation list Bool: file open was notsuccessful ! (myIn) (not) is true, repeat Drag oneor more operations from the operation list Print error message print -1 prompt for filename Read a file name read a string to variable myIn prompt for myIn prompt for myIn prompt for myIn prompt for myIn read a file name read a string to variable myIn read a file name read a string to variable myIn read a file name read a string to variable myIn read a file name read a string to variable myIn while Drag oneor more operations from the operation list Bool: file open was notsuccessful ! (myIn) (not) is true, repeat Drag oneor more operations from the operation list Print error message print -1 prompt for filename Read a file name read a string to variable myIn while while while Drag oneor more operations from the operation list Bool: file open was notsuccessful ! (myIn) (not) Drag oneor more operations from the operation list Bool: file open was notsuccessful ! (myIn) (not) Bool: file open was notsuccessful ! (myIn) (not) Bool: file open was notsuccessful ! (myIn) (not) Bool: file open was notsuccessful ! (myIn) (not) is true, repeat Drag oneor more operations from the operation list Print error message print -1 prompt for filename Read a file name read a string to variable myIn Drag oneor more operations from the operation list Print error message print -1 Print error message print -1 Print error message print -1 Print error message print -1 prompt for filename prompt for filename prompt for filename prompt for filename Read a file name read a string to variable myIn Read a file name read a string to variable myIn Read a file name read a string to variable myIn Read a file name read a string to variable myIn

Explanation / Answer


#include <iostream> #include <fstream> using namespace std; int main() { float average; int count,num,sum; char fname[20]; cout<<"Enter the file name: "; cin>>fname; ifstream inputfile; inputfile.open(fname); if(inputfile.fail()) { cout<<"Unable to open file"; system("pause"); return 1; } cout<<"The numbers were : "; inputfile>>num; sum=0; count=0; while(inputfile) { sum=sum+num; count++; cout<<num<<" "; inputfile>>num; } if(count>0) average=(float)sum/count; else average=0; cout<<" Average of numbers:"<<average<<endl; inputfile.close(); system("pause"); return 0; }
#include <iostream> #include <fstream> using namespace std; int main() { float average; int count,num,sum; char fname[20]; cout<<"Enter the file name: "; cin>>fname; ifstream inputfile; inputfile.open(fname); if(inputfile.fail()) { cout<<"Unable to open file"; system("pause"); return 1; } cout<<"The numbers were : "; inputfile>>num; sum=0; count=0; while(inputfile) { sum=sum+num; count++; cout<<num<<" "; inputfile>>num; } if(count>0) average=(float)sum/count; else average=0; cout<<" Average of numbers:"<<average<<endl; inputfile.close(); system("pause"); return 0; }