Question

Write a C++ Program to print the first letter of your first and last name using...

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

Homework Answers

Answer #1

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!
===========================================================================
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ Program to print the first letter of your first and last name using...
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 my name's Aya amro
Write a program that asks the user for the name of a file. The program should...
Write a program that asks the user for the name of a file. The program should display only the first five lines of the file’s contents. If the file contains less than five lines, it should display the file’s entire contents. by python using while loop
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to...
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
Write a code segment to print your name ten times on the screen using a while...
Write a code segment to print your name ten times on the screen using a while loop. Use one variable called count to act as a counter for the loop. Discuss how would you print your name 1000 times on the screen. NOTE: You can either type your code into the text box or upload a document to the discussion board by clicking the "attach" clip at the bottom left of the discussion box.
Draw a timing diagram for the first four letters of your last name, given the following...
Draw a timing diagram for the first four letters of your last name, given the following specifications about the RS232 serial communications channel:           Baud rate:     115,200 baud           Data length: 8 bits           Parity:           None           Stop bits:      1 The first three letters of your last name should include at least one upper case letter and one or two lower case letters (If your last name is 3 letters or less, use first name). Indicate the bit time for...
1. a)Write a program that displays the name and address of your college in C# b)Write...
1. a)Write a program that displays the name and address of your college in C# b)Write a program that prompts the user for his name and average monthly visa bill. The program displays his name and his annual visa bill. You must match the format exactly: Name: Justin Bieber Annual Visa Bill: $12,000.00 Hint: annual bill = monthly bill * 12 c)Write a program that prompts the user for a letter. The program prints the letter and the number equivalent....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last...
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last name, and year of birth in a single string (in the format: fn;ln;yyyy), then calculates the age tell it to him/her after greeting him/her using the first name. Make sure to capitalize the user's first name, regardless of how he/she typed it in. Hint: review Exercise 1! Example: Enter your first name, last name, and birth year (in format fn;ln;yyyy): alex;smith;1994 Hi Alex, you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT