The foundation of the building would always be width + 2 stars if the width is an odd number, or 2 stars if the width is an even number
#include <iostream>
#include <string>
using namespace std;
class Building
{
public:
Building(int n)
{
set_width(n);
}
void set_width(int wd) {
if (wd % 2 == 0) {
width = "**";
}
else {
width = to_string(wd) + "**";
}
}
void display() {
cout <<"width = " << width<<endl;
}
private:
string width;
};
int main()
// example
{
Building build(11);
build.display();
build.set_width(10);
build.display();
}
Comments
Leave a comment