Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is from Programming -- Principles and Practice Using C++ by Bjarne Stroustrup Chapter 14 Excersise 1 Modify the following code to: - make the

This is from "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup Chapter 14 Excersise 1

Modify the following code to:

- make the eyes round instead of vertice lines

- colour the faces in yellow colour

- make the mouth as half circle

class Smiley: public Circle { private: Open_polyline lefteye; Open_polyline righteye; Open_polyline mouth;

public:

// Explicitly call Circle's constructor. Then le's constructor gets called Smiley(Point c, int r ) : Circle( c, r ) { lefteye.add( Point(c.x - (r / 3), c.y - (r / 2)) ); lefteye.add( Point(c.x - (r / 3), c.y - (r / 6)) );

righteye.add( Point(c.x + (r / 3), c.y - (r / 2)) ); righteye.add( Point(c.x + (r / 3), c.y - (r / 6)) );

mouth.add( Point(c.x - (r / 1.5), c.y + (r / 6)) ); mouth.add( Point(c.x - (r / 3), c.y + (r / 2)) ); mouth.add( Point(c.x, c.y + (r / 1.65)) ); mouth.add( Point(c.x + (r / 3), c.y + (r / 2)) ); mouth.add( Point(c.x + (r / 1.5), c.y + (r / 6)) );

}

void draw_lines() const { Circle::draw_lines() ; lefteye.draw_lines() ; righteye.draw_lines(); mouth.draw_lines(); } };

class frowny: public Circle { private: Open_polyline lefteye; Open_polyline righteye; Open_polyline mouth;

public:

// Explicitly call Circle's constructor. Then le's constructor gets called frowny(Point c, int r ) : Circle( c, r ) { lefteye.add( Point(c.x - (r / 2.75), c.y - (r / 2)) ); lefteye.add( Point(c.x - (r / 2.75), c.y - (r / 7)) );

righteye.add( Point(c.x + (r / 2.75), c.y - (r / 2)) ); righteye.add( Point(c.x + (r / 2.75), c.y - (r / 7)) );

mouth.add( Point(c.x - (r / 1.75), c.y + (r / 2)) ); mouth.add( Point(c.x - (r / 3), c.y + (r / 3.5)) ); mouth.add( Point(c.x, c.y + (r / 5)) ); mouth.add( Point(c.x + (r / 3), c.y + (r / 3.5)) ); mouth.add( Point(c.x + (r / 1.75), c.y + (r / 2)) );

}

void draw_lines() const { Circle::draw_lines() ; lefteye.draw_lines() ; righteye.draw_lines(); mouth.draw_lines(); } };

class SmileyHat: public Smiley { private: Open_polyline hat ; public: SmileyHat(Point c, int r) : Smiley(c,r) { hat.add( Point(c.x, c.y-r) ) ; hat.add( Point(c.x+r, c.y-r) ) ; }

void draw_lines() const { Smiley::draw_lines() ; hat.draw_lines() ; }

};

int main() { using namespace Graph_lib;

Point tl(100,100);

Simple_window win(tl,600,400,"Canvas");

SmileyHat s( Point(150,150), 50 ) ; frowny f( Point(350,150), 50 ) ;

win.attach (s); win.attach (f);

win.wait_for_button(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting For Managers

Authors: William Webster

1st Edition

0071421742, 978-0071421744

Students also viewed these Databases questions