Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need this scrip in c++ to use 6 functions reading from a text file. 1.) open input 2.) read input 3.)calculate sum 4.) sort array

need this scrip in c++ to use 6 functions reading from a text file. 1.) open input 2.) read input 3.)calculate sum 4.) sort array from high to low 5.) calculate average 6.) find median if i could just get helped reading the data from the file when there is characters it needs to go out and give a error message.

here is my code

#include

#include

#include

#include

#include

#include

using namespace std;

// Functions

void OpenInputFile(ifstream& inFile);

bool ReadInputData(ifstream& inFile,double *matrix1, int ArraySize);

int main()

{

bool running = false;

ifstream inFile;

//Matrix A;

double NumberOfPoints;

bool Pass;

OpenInputFile(inFile);

//inFile >> NumberOfPoints;

//cout

//if(NumberOfPoints!=(int)NumberOfPoints)

//{

inFile >> NumberOfPoints;

cout

//cout

//return 0;

//}

int ArraySize = NumberOfPoints - 1;

double matrix1[ArraySize];

Pass = ReadInputData(inFile,matrix1,ArraySize);

if(Pass == false)

{

cout

return 0;

}

int i=0;

while(i

{

cout

i++;

}

//while(inFile)

//{

//cout

return 0;

}

void OpenInputFile(ifstream& inFile) // function to prompt user for input file and to read bad file stream.

{

string infilename;

cout

cin >> infilename;

cout

inFile.open(infilename.c_str());

while(inFile.fail())

{

cout

cout Input file ailed to open properly!! ";

cout Attempted to open file: "

cout Please try again... "

cout

inFile.clear();

cout

cin >> infilename;

cout

inFile.open(infilename.c_str());

}

}

bool ReadInputData(ifstream& inFile,double *matrix1, int ArraySize)

{

bool haveData=true;

//float number;

int i = 0;

int Pass = 0;

//string MyArray[ArraySize];

//inFile >> matrix1[i];

//if(!inFile)

//{

// haveData=false;

// cout

//}

while(inFile.good())

{

if((inFile >> matrix1[i]))

{

//cout "

//return false;

i++;

}

else

{

//inFile >> matrix1[i];

//i++;

//cout "

}

}

return true;

//i = 0;

//while(i

//{

// std :: stringstream MyArray;

// matrix1[i]=(MyArray[i]);

// if(matrix1[i]==MyArray[i])

// {

// i++;

// }

// else

// {

// i = ArraySize+1;

// return Pass = 0;

// }

//}

//return Pass = 1;

}

//inFile >> NumberOfPoints;

//while(inFile !Eof)

//{

// count ++

//}

//if(!inFile)

//{

// haveData = false;

//}

//inFile.ignore(256,' ');

//inFile >> numberOfCols;

//if(!inFile)

//{

// haveData = false;

//}

//inFile.ignore(256,' ');

//inFile.ignore(256,' ');

//for (int row = 0; row

//{

// for(int col = 0; col

// {

// inFile >> matrix1[row][col];

// }

//}

//inFile.ignore(256,' ');

// inFile.ignore(256,' ');

// for (int row = 0; row

// {

// for(int col = 0; col

// {

// inFile >> matrix2[row][col];

// }

// }

// return haveData;

here is input file

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions