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.
#include <iostream>
#include <string>
usingnamespace 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;
}