1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void LengthAndPosition(string, string, string ,string, int& , int& , int& , int& );
string full, first, middle, last;
int firstLength, lastLength,totalLength,commaPosition;
int main() {
cout<<"Please enter your first name, middle initial, and last name: ";
cin>>first>>middle>>last;
full = first+middle+last;
LengthAndPosition(full, first, middle, last, firstLength, lastLength, totalLength, commaPosition);
cout<<"The "<<firstLength<<" characters of the first name are: "<<first<<endl;
cout<<"The "<<lastLength<<" characters of the last name are: "<<last<<endl;
cout<<"In the phone book, the name would be: "<<last<<", "<<first<<" "<<middle<<endl;
cout<<"The length of the name is: "<<totalLength<<endl;
cout<<"The comma is at position: "<<commaPosition<<endl;
cout<<"After the swap, the last name is "<<first<<" and the first name is "<<last<<endl;
return 0;
}
void LengthAndPosition(string full, string first, string middle, string last, int& firstLength, int& lastLength, int& totalLength, int& commaPosition){
firstLength = first.length();
lastLength = last.length();
totalLength = full.length();
commaPosition = last.length();
}
|