Answer to Question #332266 in C++ for Honey

Question #332266

Write a C++ program to create a class "Wall" with private data members "length & height and public member functions "findArea & Wall

1
Expert's answer
2022-04-22T04:43:52-0400



//the Wall
#include <iostream>
#include <string.h>
#include <iomanip>
#include  <fstream>
/*
 Wall atributes length and height
Wall like as rectangle so We can find Area by formula 
S=length*height
*/
using namespace std;
class Wall
{
private:
int length;
int height;
public:
Wall()//defoult constructor
{
  this->length=1;
  this->height=1;
}
//Parametrase constructor
Wall(int l,int h)
{
  this->length=l;
  this->height=h;
}
//find area
int findArea()
{
  return length*height;
}
void printWall()
{
  for(int i=0;i<height;i++)
    {
      for(int j=0;j<length;j++)
      if(i==0||i==height-1)
      {
        cout<<"-";
      }
      else if (j==0||j==length-1)
      {
        cout<<"|";
      }
      else 
        cout<<"*";
      cout<<endl;
        
    }
}
  void Report()
  {
    cout<<"Length:="<<length<<endl;
    cout<<"Height:="<<height<<endl;
    cout<<"Area: "<<findArea()<<endl;
    printWall();
  }
};
int main()
{
  cout<<"Please enter length of the Wall:";
  int len;
  cin>>len;
  cout<<"Please enter height of the Wall:";
  int w;
  cin>>w;
  Wall wl(len,w);
  wl.Report();
  return 0;
}
//This code build and run on LUnix online compiler but it will runing all OS

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS