-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframe.cpp
More file actions
37 lines (28 loc) · 723 Bytes
/
frame.cpp
File metadata and controls
37 lines (28 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <vector>
#include <string>
int longestLenStr(std::vector<std::string> words)
{
int longest = words[0].length();
for (std::string word : words)
if (word.length() > longest)
longest = word.length();
return longest;
}
void printInFrame(std::vector<std::string> words)
{
int width = longestLenStr(words);
for (int i = 0; i < width +4; i++)
std::cout<<'*';
std::cout <<std::endl;
for (auto word : words){
std::cout<<"* "<<word;
unsigned int spaces = width - word.length();
for (int i = 0; i < spaces; i++)
std::cout<<" ";
std::cout<< " *\n";
}
for (int i = 0; i < width +4; i++)
std::cout<<'*';
std::cout<<std::endl;
}