Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. /*
  2. =^._.^= DEEEKITTY || DENISE THUY VY NGUYEN 
  3. lab1-1.C
  4.                                    
  5. PURPOSE:
  6. IMPLMENTED: DENISE NGUYEN       //
  7. DATE:31/01/16   //
  8. USER INFORMATION: This will take MAX amount of student data:
  9. id, First Name, Major, Gender, and age. 
  10. Then will ask to enter in a ID to serach.
  11. Display reponse and exit to find the youngest and oldest of all   ///
  12. IMPLEMENTED METHOD: while () Yes or No will
  13. OVERVIEW:
  14. SUBPARTS:
  15. |     .-.
  16. |    /   \         .-.
  17. |   /     \       /   \       .-.     .-.     _   _
  18. +--/-------\-----/-----\-----/---\---/---\---/-\-/-\/\/---
  19. | /         \   /       \   /     '-'     '-'
  20. |/           '-'         '-'
  21. */
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <string>
  26. using namespace std;
  27.  
  28. //struct
  29. struct Student
  30. {
  31. int id;
  32. string name;
  33. char gender;
  34. string major;
  35. int age;
  36. };
  37.  
  38. //prototypes
  39. void getStuData(Student list[]);
  40. int findID(Student s[], int look);
  41. void displayStu(Student list[], int postition);
  42. void findYoungOld(Student s[]);
  43.  
  44. //const array 
  45. const int MAX=2;
  46.  
  47. //DRIVER =^.,.^=
  48. int main()
  49. {
  50. Student list[MAX];
  51. cout << endl;
  52. cout << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪•* ♪ღ♪\n";
  53. cout << "This program will take in Student data.\n";
  54. cout << "Serach for ID";
  55. cout << "Before exiting program will display the youngest and oldest age\n";
  56.  
  57. cout << "Enjoy (。◕◡◕。)\n";
  58. cout << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪•* ♪ღ♪\n" << endl;
  59. cout << "\n";
  60.  
  61. //calling function
  62. getStuData(list);
  63.  
  64. int look; //The id the user is looking for
  65. cout << "☁ ▅▒░☼‿☼ USE KEYBORAD FOR VALID INPUTS ☼‿☼░▒▅ ☁\n";
  66. cout << "Enter the ID  you are looking for: ";
  67. cin >> look;
  68. //calling function
  69. int s;
  70. int i;
  71. int position;
  72. position = findID(list, look);
  73. if(position >= 0)
  74. {
  75. displayStu(list, position);
  76. }
  77. else
  78. cout << "No student with id " << look << " was found" << endl;
  79.  
  80. cout << endl;
  81.  
  82. findYoungOld(list);
  83.  
  84. return 0;
  85. }
  86.  
  87. //functions
  88. ////This function loads students' data into the array and returns the number of students. 
  89. void getStuData(Student list[])
  90. {
  91. char answer;
  92. int i = 0;
  93. cout << "☁ ▅▒░☼‿☼ USE KEYBORAD FOR VALID INPUTS ☼‿☼░▒▅ ☁\n";
  94. cout << "Would you like to enter a student's information? [Y / N]: ";
  95. cin >> answer;
  96. if (answer == 'N'|| answer == 'n' )
  97. {
  98. cout << "This next part of the program will serach for endtered ID";
  99. cout << endl;
  100. }
  101. while ((answer == 'Y' || answer == 'y') && i < MAX)
  102. {
  103. cout << "" << endl;
  104. cout << "Enter in ID: ";
  105. cin >> list[i].id;
  106. cout << "Name: ";
  107. cin.ignore();
  108. getline(cin, list[i].name);
  109. cout << "Gender:";
  110. cin >> list[i].gender;
  111. cout << "Major: ";
  112. cin >> list[i].major;
  113. cout << "Age: ";
  114. cin >> list[i].age;
  115. i++;
  116. cout << endl;
  117. cout << "Would you like to enter a student's information? [Y / N]: ";
  118. cin >> answer;
  119. cout << endl;
  120. }
  121. Student Default = {0, " ", ' ', " ", 999};
  122. for(int j=0; j> MAX; j++)
  123. {
  124. s[j] = Default;
  125. }
  126. }
  127.  
  128. //function
  129. /*
  130. This function searches through the array to find 
  131. the student with the id the user is looking for.
  132. The user is asked to enter the id she is looking for in the main. 
  133. Return the index or -1 if not found.
  134. */
  135.  
  136. int findID(Student s[], int look)
  137. {
  138. int i=0;
  139. int postition = -1;
  140. bool found = false;
  141.  
  142. while(i < MAX &&! found)
  143. {
  144. if(s[i].id == look)
  145. {
  146. found = true;
  147. postition = i;
  148. }
  149. i++;
  150. }
  151. return postition;
  152. }
  153.  
  154.  
  155. //function
  156. /*
  157. This function will be passed one student struct and display all the information (name, gender, major and age) about that student.
  158. */
  159.  
  160. void displayStu(Student s[], int postition)
  161. {
  162. cout << setw(5) << "id" << setw(10) << "name" << setw(10) << "gender" << setw(10) << "";
  163. cout << setw(5) << "major" << setw(10) << "age" << endl;
  164. cout << setw(5) << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪••.¸¸¸.•\n" << endl;
  165. cout << setw(5) << s[postition].id << setw(10) << s[postition].name << setw(10) << s[postition].gender << setw(10) << "";
  166. cout << setw(5) << s[postition].major << setw(10) << s[postition].age << endl;
  167. }
  168.  
  169. void findYoungOld(Student s[])
  170. {
  171. int young = s[0].age;
  172. int old = s[0].age;
  173. for (int i = 1; i < MAX; i++ )
  174. {
  175. if(s[i].age < young)
  176. {
  177. clear
  178. young = s[i].age;
  179. }
  180. if(s[i].age > old)
  181. {
  182. old = s[i].age;
  183. }
  184. }
  185. cout << "The youngest age is " << young << endl;
  186. cout << "The oldest age is " << old << endl;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement