#include <iostream>//for cin, cout
#include <string>//For string
using namespace std;
string swapLetters(string name);
void displayNames(string studentNames[25]);
int main() {
string studentNames[25];
for(int i=0;i<25;i++){
cout << "Enter name "<<(i+1)<<": ";
getline(cin,studentNames[i]);
}
cout<<endl << "The names before swapping: "<<endl;
displayNames(studentNames);
for(int i=0;i<25;i++){
studentNames[i]=swapLetters(studentNames[i]);
}
cout<<endl << "The names after swapping: "<<endl;
displayNames(studentNames);
system("pause");
return 0;
}
string swapLetters(string name){
char tmp=name[name.length()-1];
name[name.length()-1]=name[0];
name[0]=tmp;
return name;
}
void displayNames(string studentNames[25]){
for(int i=0;i<25;i++){
cout <<(i+1)<<". "<< studentNames[i]<<endl;
}
}
Comments