Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++] The code samples show how to read a disk file and skip records until you reach the location of the records that will contain

[C++]

The code samples show how to read a disk file and skip records until you reach the location of the records that will contain the values to be used when computing the median value. You can verify that you have the correct results by opening the files with a spreadsheet program (Microsoft Excel, Apple Numbers or OpenOffice Calc), select the column with the balances and compute the median value with one of the statistical functions.

Two data files are provided for this lab. One file has an odd number of records and the other file has an even number of records. 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.

Balances-1.txt

2660113 Hendrix_Daniel 220.50 4463320 Gonzales_Luis 235.00 6998318 Brown_Robert 235.83 2798731 Kelly_Dan 250.29 6681985 Bailey_Robert 261.10 7979495 Brewer_Randall 262.83 2338123 Houston_Dan 271.30 3305709 Browne_Richard 276.29 4969050 Bettencourt_Sue 299.89 2516725 Estrada_Manuel 305.57 8213456 Houston_Bill 310.27 7216627 Browne_Sylvia 317.44 4353074 Bettencourt_Sam 367.64 5276956 Brown_Larry 370.51 3379118 Bush_Sandy 379.02 7415592 Brown_Richard 381.07 8248711 Brown_William 392.31 3921164 Black_Donald 410.55 6853921 Aaker_Charles 410.58 7496177 Duncan_Sam 419.44 3242666 Javier_Luis 432.43 5578678 Ha_Sang_Trung 432.56 5234130 Brown_Armando 442.26 8401540 Howard_Alfred 448.03 8646711 Duncan_Miranda 458.00 4248749 Kelly_Edward 460.02 3909086 Baird_Sally 486.85 6539446 Bates_Joan_MD 543.21 2697628 Brooks_Sally 564.57 6654015 Duncan_Jerry 593.47 4454811 Gallagher_Joe 594.87 4576897 Campbell_Chuck 602.54 3706133 Gallagher_Suzy 604.82 2499802 Ha_Kelly 606.28 2774785 Johnston_Steve 630.04 7601760 Clark_Kent 652.97 8766414 Gonzales_Tony 654.64 7377233 Duncan_William 664.42 4486432 Jordan_Marueen 674.92 2955456 Hunter_Paul 691.99 8978821 Brownell_J_R 702.90 3865287 Barber_Larry 704.71 8737779 Fernandez_Chuck 756.49 2817664 Hernandez_Jose 773.58 6622438 Browne_Alice 775.96 6397102 Javier_Jose 802.31 8238225 Howard_Mary 880.06 5864612 Duncan_Kari 882.94 7961122 Houston_Jim 930.15 4314868 Ha_Fong_Vinh 961.50 3373741 Bush_Keith 1002.30 5851526 Houston_John 1039.36 7978236 Gonzales_Alfred 1042.26 2926086 Gonzales_Pablo 1045.15 8453374 Brewer_Manny 1059.75 7212920 Brooks_Richard 1078.90 7685359 Ballard_Gary 1146.19 3625430 Brooks_Kent 1149.42 8253791 Ha_David_L 1151.03 7855458 Barber_Sally 1154.01 7893805 Black_Ralph 1156.34 6847641 Bettencourt_Jim 1162.16 5562645 Blackburn_Randy 1162.80 4555540 Estrada_Leo 1204.18 6752376 Alexander_Lonny 1214.36 2306909 Johnston_Mary 1233.53 3815865 Javier_Maira 1291.18 5901163 Balovich_A 1303.41 8274030 Estrada_David 1322.70 2596858 Dang_Dong 1342.33 5347586 Jordan_David 1380.54 5975152 Brewer_Daryl 1393.26 8525968 Dang_Trang 1428.60 4974554 Estrada_William 1446.78 8448936 Addams_Brent 1447.23 7878014 Estrada_Rene 1449.26 8374768 Boccone_Richard 1502.79 4259635 Brown_Richard 1534.73 3556572 Brown_Kelly 1547.74 4215534 Abraham_Sally 1550.35 4597789 Lambert_Richard 1571.79 6791401 Gonzales_Maria 1593.89 6276226 Cash_Johnny 1603.59 7643057 Hernandez_A 1606.60 3277222 Dang_Kanh 1639.70 2867385 Bobbit_Larry_MD 1652.36 2883903 Aitken_Charles 1667.32 8445875 Dang_Hoang 1680.03 8596337 Brown_Roger 1691.93 8911230 Duncan_Ester 1742.63 7263399 Blackburn_Tom 1743.41 5221192 Bell_Roger 1751.61 4317590 Blackmore_Mark 1758.48 8898693 Kelly_George_MD 1764.68 2344238 Ha_Nguyen 1771.03 8736368 Austin_Nellie 1773.69 6375372 Austin_JR 1810.01 6352036 Burger_Lance 1822.68 8748734 Gonzales_Jose 1829.95 6824395 Joshston_Bill 1867.41 2987125 Gallagher_Mary 1867.68 8636495 Bush_Rachel 1920.78 3584136 Black_Marcie 1947.86 3461583 Brownfield_Joe 1963.09 5687022 Allen_Steve 1972.93 3402482 Brooks_Paul 1984.94 6224649 Abula_Michael 2051.05 8445196 Bailey_Michael 2051.70 3576746 Dang_Quang 2070.09 7671276 Ha_James 2085.68 3564698 Allop_Jose 2106.13 7218536 Bailey_Michael 2112.13 6837553 Howard_Steve 2124.16 7649692 Gonzales_Joe 2132.70 5543111 Bates_Fred 2132.83 6287419 Boucher_Victor 2153.55 3916771 Duncan_Mark 2177.11 

---------------------------------------------------------

Balances-2.txt

2660113 Hendrix_Daniel 220.50 4463320 Gonzales_Luis 235.00 6998318 Brown_Robert 235.83 2798731 Kelly_Dan 250.29 6681985 Bailey_Robert 261.10 7979495 Brewer_Randall 262.83 2338123 Houston_Dan 271.30 3305709 Browne_Richard 276.29 4969050 Bettencourt_Sue 299.89 2516725 Estrada_Manuel 305.57 8213456 Houston_Bill 310.27 7216627 Browne_Sylvia 317.44 4353074 Bettencourt_Sam 367.64 5276956 Brown_Larry 370.51 3379118 Bush_Sandy 379.02 7415592 Brown_Richard 381.07 8248711 Brown_William 392.31 3921164 Black_Donald 410.55 6853921 Aaker_Charles 410.58 7496177 Duncan_Sam 419.44 3242666 Javier_Luis 432.43 5578678 Ha_Sang_Trung 432.56 5234130 Brown_Armando 442.26 8401540 Howard_Alfred 448.03 8646711 Duncan_Miranda 458.00 4248749 Kelly_Edward 460.02 3909086 Baird_Sally 486.85 6539446 Bates_Joan_MD 543.21 2697628 Brooks_Sally 564.57 6654015 Duncan_Jerry 593.47 4454811 Gallagher_Joe 594.87 4576897 Campbell_Chuck 602.54 3706133 Gallagher_Suzy 604.82 2499802 Ha_Kelly 606.28 2774785 Johnston_Steve 630.04 7601760 Clark_Kent 652.97 8766414 Gonzales_Tony 654.64 7377233 Duncan_William 664.42 4486432 Jordan_Marueen 674.92 2955456 Hunter_Paul 691.99 8978821 Brownell_J_R 702.90 9257451 Charles_William 703.68 3865287 Barber_Larry 704.71 8737779 Fernandez_Chuck 756.49 2817664 Hernandez_Jose 773.58 6622438 Browne_Alice 775.96 6397102 Javier_Jose 802.31 8238225 Howard_Mary 880.06 5864612 Duncan_Kari 882.94 7961122 Houston_Jim 930.15 4314868 Ha_Fong_Vinh 961.50 3373741 Bush_Keith 1002.30 5851526 Houston_John 1039.36 7978236 Gonzales_Alfred 1042.26 2926086 Gonzales_Pablo 1045.15 8453374 Brewer_Manny 1059.75 7212920 Brooks_Richard 1078.90 7685359 Ballard_Gary 1146.19 3625430 Brooks_Kent 1149.42 8253791 Ha_David_L 1151.03 7855458 Barber_Sally 1154.01 7893805 Black_Ralph 1156.34 6847641 Bettencourt_Jim 1162.16 5562645 Blackburn_Randy 1162.80 4555540 Estrada_Leo 1204.18 6752376 Alexander_Lonny 1214.36 2306909 Johnston_Mary 1233.53 3815865 Javier_Maira 1291.18 5901163 Balovich_A 1303.41 8274030 Estrada_David 1322.70 2596858 Dang_Dong 1342.33 5347586 Jordan_David 1380.54 5975152 Brewer_Daryl 1393.26 8525968 Dang_Trang 1428.60 4974554 Estrada_William 1446.78 8448936 Addams_Brent 1447.23 7878014 Estrada_Rene 1449.26 8374768 Boccone_Richard 1502.79 4259635 Brown_Richard 1534.73 3556572 Brown_Kelly 1547.74 4215534 Abraham_Sally 1550.35 4597789 Lambert_Richard 1571.79 6791401 Gonzales_Maria 1593.89 6276226 Cash_Johnny 1603.59 7643057 Hernandez_A 1606.60 3277222 Dang_Kanh 1639.70 2867385 Bobbit_Larry_MD 1652.36 2883903 Aitken_Charles 1667.32 8445875 Dang_Hoang 1680.03 8596337 Brown_Roger 1691.93 8911230 Duncan_Ester 1742.63 7263399 Blackburn_Tom 1743.41 5221192 Bell_Roger 1751.61 4317590 Blackmore_Mark 1758.48 8898693 Kelly_George_MD 1764.68 2344238 Ha_Nguyen 1771.03 8736368 Austin_Nellie 1773.69 6375372 Austin_JR 1810.01 6352036 Burger_Lance 1822.68 8748734 Gonzales_Jose 1829.95 6824395 Joshston_Bill 1867.41 2987125 Gallagher_Mary 1867.68 8636495 Bush_Rachel 1920.78 3584136 Black_Marcie 1947.86 3461583 Brownfield_Joe 1963.09 5687022 Allen_Steve 1972.93 3402482 Brooks_Paul 1984.94 6224649 Abula_Michael 2051.05 8445196 Bailey_Michael 2051.70 3576746 Dang_Quang 2070.09 7671276 Ha_James 2085.68 3564698 Allop_Jose 2106.13 7218536 Bailey_Michael 2112.13 6837553 Howard_Steve 2124.16 7649692 Gonzales_Joe 2132.70 5543111 Bates_Fred 2132.83 6287419 Boucher_Victor 2153.55 3916771 Duncan_Mark 2177.11 

---------------------------------------------------------

// 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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

4. Not sure? Ask them.

Answered: 1 week ago

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

What are the need and importance of training ?

Answered: 1 week ago

Question

=+Does it showcase the firm's benefits?

Answered: 1 week ago

Question

=+ Does it list exciting places to go and famous sites to see?

Answered: 1 week ago