string loop rectangle display

I have been writing a code to display a "mailing label" with user input. The "label" is a rectangle outlined with "X" and inside that the information will be displayed. I have seem to be stuck on the part of the code where I replace one of my cout<< " "; loops with the string "name", "address", "city" , "state", "zip"

My working code is below, please remember that this is from another project which includes other useless information such as the string length which I probably will need later on.


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  	
#include <iostream>
#include <string>

using namespace std;

class Rectangle
{
private:
      int width;
      int height;
      int top;
      int left;
           char name[20];
           char address[20];
           char city[20];
           char state[20];
           char zip[20];
public:
      Rectangle();
      void SetRectangle();
      void Display();
};
Rectangle::Rectangle()
{

      SetRectangle();
}
void Rectangle::SetRectangle()
{
      cout<<"Please enter the width: "<<endl;
      cin>>width;
      cout<<"Please enter the height: "<<endl;
      cin>>height;
      cout<<"Please enter how far from the top: "<<endl;
      cin>>top;
      cout<<"Please enter how far from the left: "<<endl;
      cin>>left;
           cout<<"Please enter full name with '_' for spaces: "<<endl;
           cin>>name;
           cout<<"Please enter street address with '_' for spaces: "<<endl;
           cin>>address;
           cout<<"Please enter full city name: "<<endl;
           cin>>city;
           cout<<"Please enter state name: "<<endl;
           cin>>state;
           cout<<"Please enter full zipcode: "<<endl;
           cin>>zip;
      system("cls");
}
void Rectangle::Display()
{
std::string str (name);
std::string str1 (address);
std::string str2 (city);
std::string str3 (state);
std::string str4 (zip);
for (int y = 0; y < top; y++)
  {
      cout<<endl;
  }
for (int x = 0; x < left; x++)
          {
              cout<<" ";
          }
       cout << "X";
for (int i = 0; i < width - 2; i++)
 {

     cout << "X";

 }
 cout << "X\n";

 for (int i = 0; i < height - 2; i++)
 {
          for (int x = 0; x < left; x++)
          {
              cout<< " ";
          }
     cout << "X";

     for (int j = 0; j < width - 2; j++)
     {
              //  if (j < 2)
                        cout << " ";
              // else if

      }
     cout << "X\n";
 }
 for (int x = 0; x < left; x++)
          {
              cout<<" ";
          }
 cout << "X";

 for (int i = 0; i < width - 2; i++)
 {

     cout << "X";

 }
 cout << "X\n";

 cout<<name<<endl<<address<<" "<<city<<" "<<state<<" "<<zip<<endl;
 std::cout << "The size of str is " << str.length() << " characters.\n";
 std::cout << "The size of str is " << str1.length() << " characters.\n";
 std::cout << "The size of str is " << str2.length() << " characters.\n";
 std::cout << "The size of str is " << str3.length() << " characters.\n";
 std::cout << "The size of str is " << str4.length() << " characters.\n";

}
int main()
{
      Rectangle r1;
      r1.Display();
      system("pause");
  return 0;
}

Last edited on
Topic archived. No new replies allowed.