Advertisement
blainebrown

Untitled

Dec 2nd, 2011
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. /*
  2. Source file : Brown_B_Prj5.cpp
  3. Programmer: Blaine Allen Brown
  4. Date: December 2, 2011
  5. Lab CRN 10940
  6. */
  7.  
  8. #include <iostream>
  9. #include <fstream>
  10.  
  11. using namespace std;
  12.  
  13. struct infoType
  14. {
  15. string name;
  16. int id;
  17. double height;
  18. double weight;
  19. double postWeight;
  20. int bmi;
  21. int postBmi;
  22. };
  23.  
  24. struct nodeType
  25. {
  26. infoType info;
  27. nodeType *link;
  28. };
  29.  
  30. void add(nodeType *list, ifstream& inFile)
  31. {
  32. cout << "4" << endl; //debug
  33. string name;
  34. int id;
  35. double height;
  36. double weight;
  37.  
  38. nodeType *position;
  39. cout << "5" << endl; //debug
  40. position = list;
  41. cout << "6" << endl; //debug
  42.  
  43. if(list != NULL)
  44. {
  45. while(position->link != NULL)
  46. {
  47. cout << "7" << endl; //debug
  48. position = position->link;
  49. cout << "8" << endl; //debug
  50. }
  51. }
  52. cout << "9" << endl; //debug
  53.  
  54. nodeType *temp;
  55.  
  56. cout << "10" << endl; //debug
  57. temp = new nodeType;
  58.  
  59. cout << "11" << endl; //debug
  60. inFile >> name >> id >> height >> weight;
  61.  
  62. cout << "12" << endl; //debug
  63. temp->info.name = name;
  64. temp->info.id = id;
  65. temp->info.height = height;
  66. temp->info.weight = weight;
  67.  
  68. cout << "13" << endl; //debug
  69. temp->link = NULL;
  70.  
  71. cout << "14" << endl; //debug
  72. position->link = temp;
  73.  
  74. cout << "15" << endl; //debug
  75. }
  76.  
  77. void print(nodeType *list, char yesNo)
  78. {
  79. int counter = 0;
  80. cout << "Printing the list of members..." << endl;
  81. if(list == NULL)
  82. {
  83. cout << "Got nothing." << endl;
  84. }
  85. nodeType *position;
  86. position = list;
  87. while(position != NULL)
  88. {
  89. cout << "Name: " << position->info.name << endl;
  90. cout << "ID: " << position->info.id << endl;
  91. cout << "Height: " << position->info.height << endl;
  92. if(yesNo == 'y')
  93. {
  94. cout << "Starting weight: " << position->info.weight << endl;
  95. cout << "Starting BMI: " << position->info.bmi << endl;
  96. cout << "Current weight: " << position->info.postWeight << endl;
  97. cout << "Current BMI: " << position->info.postBmi << endl;
  98. }
  99. else
  100. {
  101. cout << "Weight: " << position->info.weight << endl;
  102. }
  103. cout << endl;
  104. counter++;
  105. }
  106. cout << counter << " members in the list." << endl << endl;
  107. }
  108.  
  109. int main()
  110. {
  111. cout << "1" << endl; //debug
  112. nodeType *list;
  113. cout << "2" << endl; //debug
  114. list = NULL;
  115. cout << "3" << endl; //debug
  116.  
  117. //File 1
  118. ifstream inFile;
  119.  
  120. inFile.open("peeps.txt");
  121. if(!inFile)
  122. {
  123. cout << "No such file." << endl;
  124. system("PAUSE");
  125. return 1;
  126. }
  127.  
  128. while(!inFile.eof())
  129. {
  130. add(list, inFile);
  131. }
  132.  
  133. print(list, 'n');
  134.  
  135. inFile.close();
  136. inFile.clear();
  137.  
  138. //File 2
  139. inFile.open("changes.txt");
  140. if(!inFile)
  141. {
  142. cout << "No such file." << endl;
  143. system("PAUSE");
  144. return 1;
  145. }
  146.  
  147. inFile.close();
  148.  
  149. system("PAUSE");
  150. return 0;
  151. }
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement