Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++] You need to run the program for each file and compute the median value for each file. Sample code is given at the end

[C++] You need to run the program for each file and compute the median value for each file. Sample code is given at the end of this lab assignment. Replace the cout that is inside the while loop with code to compute the total of all balances. After the while loop completes, display the total of all balances.

// MedianOfDataFile.cpp : Defines the entry point for the console application. // #include "stdafx.h" // Only for Microsoft Visual Studio #include  #include  #include  // used by the exit() functiona using namespace std; int main(int argc, char* argv[]) { // variables to control the disk file ifstream infile; char filename[200]; int recordCount = 0; int recordsToSkip = 0; // variables for fields of each record in the file int AcctNo = 0; char Name[100] = ""; double AcctBal = 0.0; // varible used to determine the median double median = 0.0; cout << "Enter the name of the data file: "; cin >> filename; // ---- PART 1, Count the number of records in the file infile.open(filename); if (infile.fail()) { cerr << "Unable to open --" << filename << "--, first pass" << endl; exit(1); } while (!infile.eof()) // while not end of file { Name[0] = 0; // initialize to 0 to test for empty records/ infile >> AcctNo >> Name >> AcctBal; if (Name[0] != 0) // ignore empty records recordCount++; } infile.close(); cout << "There are " << recordCount << " records in " << filename << endl; // ---- PART 2, Determine the number of records to skip if (recordCount %2 == 1) recordsToSkip = recordCount/2; // Odd number of records else recordsToSkip = recordCount/2 - 1; // Even number of records // ---- PART 3, open the file, skip leading records, determine the mean // - - - - - You need to complete the program // Display the results cout << "The median of " << filename << " is " << median << endl << endl; return 0; } 

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions