2-3 ¶
~cpp
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
int pad_rows, pad_cols;
cout<<"Please input blank of rows and cols:";
cin>>pad_rows;
cin>>pad_cols;
cout<<"Please enter your first name: ";
string name;
cin>>name;
const string greeting="Hello, "+name+"!";
const int rows=pad_rows*2+3;
const string::size_type cols=greeting.size()+pad_cols*2+2;
cout<<endl;
for(int r=0;r!=rows;++r)
{
string::size_type c=0;
while(c!=cols)
{
if(r==pad_rows+1&&c==pad_cols+1)
{
cout<<greeting;
c+=greeting.size();
}
else
{
if(r==0||r==rows-1||c==0||c==cols-1)
cout<<"*";
else
cout<<" ";
++c;
}
}
cout<<endl;
}
return 0;
}