Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Laboration 3, Assignment_2.cpp
- // Fabian Tjernström (fatj1700) 2019-01-20
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <locale>
- using namespace std;
- int main()
- {
- string name1, name2, name3;
- string first1, first2, first3, last1, last2, last3;
- string no1, no2, no3, store;
- //Input av för- och efternamn.
- //Strängarna first1-3 och last1-3 konverteras till gemener för att kunna jämföras.
- cout << "*** Enter three full names, including first and last. ***" << endl;
- cin.clear();
- getline(cin, name1);
- istringstream iss1(name1);
- iss1 >> first1 >> last1;
- for(int i = 0; i < first1.length(); i++) {
- char c = first1[i];
- first1[i] = tolower(c);
- }
- for(int i = 0; i < last1.length(); i++) {
- char c = last1[i];
- last1[i] = tolower(c);
- }
- cin.clear();
- getline(cin, name2);
- istringstream iss2(name2);
- iss2 >> first2 >> last2;
- for(int i = 0; i < first2.length(); i++) {
- char c = first2[i];
- first2[i] = tolower(c);
- }
- for(int i = 0; i < last2.length(); i++) {
- char c = last2[i];
- last2[i] = tolower(c);
- }
- cin.clear();
- getline(cin, name3);
- istringstream iss3(name3);
- iss3 >> first3 >> last3;
- for(int i = 0; i < first3.length(); i++) {
- char c = first3[i];
- first3[i] = tolower(c);
- }
- for(int i = 0; i < last3.length(); i++) {
- char c = last3[i];
- last3[i] = tolower(c);
- }
- //Jämför de konverterade strängarna. Först efternamn, sedan förnamn.
- //De ursprungliga inmatningarna är sparade i name1-3.
- no1 = name1;
- no2 = name2;
- no3 = name3;
- if(last1 > last2 && last1 != last2) {
- store = no1;
- no1 = no2;
- no2 = store;
- }
- else if(last1 == last2) {
- if(first1 > first2) {
- store = no1;
- no1 = no2;
- no2 = store;
- }
- }
- if(last1 > last3 && last1 != last3) {
- store = no1;
- no1 = no3;
- no3 = store;
- }
- else if(last1 == last3) {
- if(first1 > first3) {
- store = no1;
- no1 = no3;
- no3 = store;
- }
- }
- if(last2 > last3 && last2 != last3) {
- store = no2;
- no2 = no3;
- no3 = store;
- }
- else if(last2 == last3) {
- if(first2 > first3) {
- store = no2;
- no2 = no3;
- no3 = store;
- }
- }
- cout << "----" << endl;
- cout << "No.1: " << no1 << endl;
- cout << "No.2: " << no2 << endl;
- cout << "No.3: " << no3 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment