Public paste
asdfasdf
By: asdf | Date: Dec 6 2006 19:35 | Format: None | Expires: never | Size: 2.01 KB | Hits: 1415

  1. Assignment # 8 – Struct                                                         Due Date: 12/7/06            
  2.  
  3. Problem: (100 points)
  4.  
  5.         Write a program that reads the names of the members of families and each person’s income, and computes the average income for the family. You may assume that people with the same last name who appear consecutively in the input are in the same family.
  6.         To represent the individuals use a struct named individual with the following members: lname, fname, and income.
  7.         Your main function must call a function GetData that receives an input stream and returns a struct. The function reads from an input file named input8.txt the last name, first name, and income of an individual and returns this information in the struct. The input file can have any number of lines. The results must be sent to a file named output8.txt. To calculate the average income it must call a function named calcAvg that receives the total income and the number of members and returns the average (rounded to the cents not truncated).
  8.  
  9. Note:
  10. a) input and output streams must be passed by reference (i.e., you have to use reference parameters).
  11. b) use type double for the income (float may produce wrong results).
  12.  
  13.         The function prototypes must be the following (complete them accordingly):
  14.  
  15. xxxx GetData(ifstream& inFile);
  16.  
  17. xxxx calcAvg(xxxx total, xxxx count);                   (xxxx represents data types)
  18.                                                                        
  19.  
  20. For the input below                                             the output should be:
  21.  
  22.  
  23.  
  24. Lopez Jose 47324.56
  25. Lopez Maria 35854.55
  26. Smith Albert 20964.41
  27. Smith Daisy 17432.00
  28. Smith Mark 0.0
  29. Hart Donald 55678.12
  30. Gomez Robert 23432.20
  31. Gomez Ellen 45800.0
  32. Gomez Paddy 0.0
  33. Gomez Eileen 0.0
  34. Gomez Conan 0.0
  35. Gomez Nora 0.0
  36.  
  37. intput8.txt
  38.  
  39. Last name    Avg. Income  No. of members
  40. -----------------------------------------
  41.    
  42. Lopez          41589.56         2
  43. Smith          12798.80         3
  44. Hart           55678.12         1
  45. Gomez          11538.70         6
  46.  
  47. output8.txt
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. Note: don’t need to submit the algorithm this time.
  56.  
  57. Submit the source program (.cpp) through WebCT.
  58.  
  59.