Answer to Question #176630 in C++ for Iyana

Question #176630

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


1
Expert's answer
2021-03-29T08:52:22-0400
#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();
}

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