In: Computer Science
1- Write a c++ program that asks the user to enter
his/her name using one variable only. The name must
be then printed out in capital letter with the family name first
and the last name second.
#include <bits/stdc++.h>
using namespace std;
void printInitials(const string& name)
{
if (name.length() == 0)
return;
// Since touuper() returns int, we do typecasting
cout << (char)toupper(name[0]);
// Traverse rest of the string and print the
// characters after spaces.
for (int i = 1; i < name.length() - 1; i++)
if (name[i] == ' ')
cout << " " << (char)toupper(name[i + 1]);
}
// Driver code
int main()
{
string name = "prabhat kumar singh";
printInitials(name);
return 0;
}
Output will be of format:
Input: Lucky Sandhu
Output: L S