Question

1. Write a C++ program to output a framed greeting. The program will produce five lines of output. The first line begins the

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <string>

int main()
{
string name;
string pre="Hello, ";
string msg;
while(1)
{
cout<<"Please enter your first name:";
cin >>name ;
msg=pre+name+"!";
int len=msg.length();
//line 1;
for(int i=0;i<len+4;i++)
cout<<"*";
cout<<"\n";
//line 2;
cout<<"*";
for(int i=0;i<len+2;i++)
cout<<" ";
cout<<"*\n";
//line 3;
cout<<"* ";
cout<<msg;
cout<<" *\n";
//line 4
cout<<"*";
for(int i=0;i<len+2;i++)
cout<<" ";
cout<<"*\n";
//line 5;
for(int i=0;i<len+4;i++)
cout<<"*";
cout<<"\n";
  
cout<<"Run again (Y/N): ";
string opt;
cin>>opt;
if(opt=="y"||opt=="Y")
continue;
else
break;
}

return 0;
}

1 2 3 #include <iostream> 4 #include<string>5 using namespace std; 6 7 int main() 9 10 string name; string pre=Hello, ;||


answered by: ANURANJAN SARSAM
Add a comment
Answer #2

#include <iostream>

#include <string>

int main()
{
string name;
string pre="Hello, ";
string msg;
while(1)
{
cout<<"Please enter your first name:";
cin >>name ;
msg=pre+name+"!";
int len=msg.length();
//line 1;
for(int i=0;i<len+4;i++)
cout<<"*";
cout<<"\n";
//line 2;
cout<<"*";
for(int i=0;i<len+2;i++)
cout<<" ";
cout<<"*\n";
//line 3;
cout<<"* ";
cout<<msg;
cout<<" *\n";
//line 4
cout<<"*";
for(int i=0;i<len+2;i++)
cout<<" ";
cout<<"*\n";
//line 5;
for(int i=0;i<len+4;i++)
cout<<"*";
cout<<"\n";
  
cout<<"Run again (Y/N): ";
string opt;
cin>>opt;
if(opt=="y"||opt=="Y")
continue;
else
break;
}

return 0;
}

1 2 3 #include <iostream> 4 #include <string> 5 using namespace std; 6 7 int main() 9 10 string name; string pre=Hello, ;||

Add a comment
Know the answer?
Add Answer to:
1. Write a C++ program to output a framed greeting. The program will produce five lines...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this lab, you will write a C program to encrypt a file. The program prompts...

    In this lab, you will write a C program to encrypt a file. The program prompts the user to enter a key (maximum of 5 bytes), then the program uses the key to encrypt the file. Note that the user might enter more than 5 characters, but only the first 5 are used. If a new line before the five characters, the key is padded with 'a'; Note that the new line is not a part of the key, but...

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • What to submit: your answers to exercises 2. Write a Java program to perform the following...

    What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...

  • Design a modular program using pseudo-code which prompts a user for their first name, followed by...

    Design a modular program using pseudo-code which prompts a user for their first name, followed by their last name; then displays a "Hello" salutation which concatenates their first name with their last name. Sample output (user input shown in red): Please enter your first name: John Please enter your last name: Smith Hello, John Smith! Your program must include a main module and one function; this function prompts the user for either their first name or last name, using a...

  • Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter...

    Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter the last name: Lee Hello Tom Lee. You are 21 years old. Press any key */   Declare an array named: firstName The array is a c_string, i.e., it is a null-terminated character array. The size of the array is 10. Assign a first name to it when it is declared.   Declare an array named: lastName The array is a c_string, The size of the...

  • Write and test a function in C++ that uses the binary search algorithm to search an...

    Write and test a function in C++ that uses the binary search algorithm to search an array of sorted strings – use a do..while loop to allow user to perform multiple searches w/o terminating the program – see sample output below. Use this name array: string names[SIZE] = { "Collins, Bill", "Smith, Bart", "Allen, Jim",         "Griffin, Jim", "Stamey, Marty", "Rose, Geri", "Taylor, Terri",         "Johnson, Jill", "Allison, Jeff", "Looney, Joe", "Wolfe, Bill",         "James, Jean", "Weaver, Jim", "Pore, Bob",...

  • C++ Write a program that asks for a number and then prints as many lines as...

    C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • 12.13 (Count characters, words, and lines in a file) Write a program that will count the...

    12.13 (Count characters, words, and lines in a file) Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in Figure 12.13 D Command Prompt exercise java Exercise12.13 Loan.java ile Loan.jaua has 1919 characters 10 words 71 lines lexercise Figure 12.13 The program displays the number of characters, words, and lines in the given file. This...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT