Write a C++ program to create a class "Wall" with private data members "length & height and public member functions "findArea & Wall
//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
Comments
Leave a comment