Write a C++
Program to print the first letter of your first and last name using
stars.
Note:
1) Using nested For
Loop
2) The number of lines is
given by user.
3) Using one Outer loop to
print your letters.
4) Print the letters
beside each other
The first letter A and the last letter O
Source Code:
#include <bits/stdc++.h>
using namespace std;
void printInitials(string str)
{
int len = str.length();
str.erase(0, str.find_first_not_of(' '));
str.erase(str.find_last_not_of(' ') + 1);
string t = "";
for (int i = 0; i < len; i++)
{
char ch = str[i];
if (ch != ' ')
t = t + ch;
else
{
cout << (char)toupper(t[0]) << ". ";
t = "";
}
}
string temp = "";
for (int j = 0; j < t.length(); j++)
{
if (j == 0) temp = temp + (char)toupper(t[0]);
else
temp = temp + (char)tolower(t[j]);
}
cout << temp << endl;
}
int main()
{
string str = "Your Name";
printInitials(str);
}
Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! ===========================================================================
Get Answers For Free
Most questions answered within 1 hours.