fabbe680

3.2 v2

Jan 24th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. // Laboration 3, Assignment_2.cpp
  2. // Fabian Tjernström (fatj1700) 2019-01-20
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <sstream>
  7. #include <locale>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.  
  14. string name1, name2, name3;
  15. string first1, first2, first3, last1, last2, last3;
  16. string no1, no2, no3, store;
  17.  
  18. //Input av för- och efternamn.
  19. //Strängarna first1-3 och last1-3 konverteras till gemener för att kunna jämföras.
  20.  
  21. cout << "*** Enter three full names, including first and last. ***" << endl;
  22.  
  23. cin.clear();
  24. getline(cin, name1);
  25. istringstream iss1(name1);
  26. iss1 >> first1 >> last1;
  27. for(int i = 0; i < first1.length(); i++) {
  28. char c = first1[i];
  29. first1[i] = tolower(c);
  30. }
  31. for(int i = 0; i < last1.length(); i++) {
  32. char c = last1[i];
  33. last1[i] = tolower(c);
  34. }
  35.  
  36. cin.clear();
  37. getline(cin, name2);
  38. istringstream iss2(name2);
  39. iss2 >> first2 >> last2;
  40. for(int i = 0; i < first2.length(); i++) {
  41. char c = first2[i];
  42. first2[i] = tolower(c);
  43. }
  44. for(int i = 0; i < last2.length(); i++) {
  45. char c = last2[i];
  46. last2[i] = tolower(c);
  47. }
  48.  
  49. cin.clear();
  50. getline(cin, name3);
  51. istringstream iss3(name3);
  52. iss3 >> first3 >> last3;
  53. for(int i = 0; i < first3.length(); i++) {
  54. char c = first3[i];
  55. first3[i] = tolower(c);
  56. }
  57. for(int i = 0; i < last3.length(); i++) {
  58. char c = last3[i];
  59. last3[i] = tolower(c);
  60. }
  61.  
  62. //Jämför de konverterade strängarna. Först efternamn, sedan förnamn.
  63. //De ursprungliga inmatningarna är sparade i name1-3.
  64.  
  65. no1 = name1;
  66. no2 = name2;
  67. no3 = name3;
  68.  
  69. if(last1 > last2 && last1 != last2) {
  70. store = no1;
  71. no1 = no2;
  72. no2 = store;
  73. }
  74. else if(last1 == last2) {
  75. if(first1 > first2) {
  76. store = no1;
  77. no1 = no2;
  78. no2 = store;
  79. }
  80. }
  81.  
  82. if(last1 > last3 && last1 != last3) {
  83. store = no1;
  84. no1 = no3;
  85. no3 = store;
  86. }
  87. else if(last1 == last3) {
  88. if(first1 > first3) {
  89. store = no1;
  90. no1 = no3;
  91. no3 = store;
  92. }
  93. }
  94.  
  95. if(last2 > last3 && last2 != last3) {
  96. store = no2;
  97. no2 = no3;
  98. no3 = store;
  99. }
  100. else if(last2 == last3) {
  101. if(first2 > first3) {
  102. store = no2;
  103. no2 = no3;
  104. no3 = store;
  105. }
  106. }
  107.  
  108. cout << "----" << endl;
  109. cout << "No.1: " << no1 << endl;
  110. cout << "No.2: " << no2 << endl;
  111. cout << "No.3: " << no3 << endl;
  112.  
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment