PPP2 Chapter 14 Exercise 1

I was working on this exercise since before and got some help for it on the PPP-public group on Google Groups to get to where I am on it now. But there's one thing I still haven't gotten any help on, and that's getting Frowny's mouth right. Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Osman Zakir
// 5 / 30 / 2017
// Bjarne Stroustrup: Programming: Principles and Practice Using C++ 2nd Edition
// Chapter 14 Exercise 1
// Exercise Specificaitons:
/**
 * Define two classes Smiley and Frowny, which are both derived from class
 * Circle and have two eyes and a mouth. Next, derive classes from Smiley
 * and Frowny which add an appropriate hat to each.
 */

#include <iostream>
#include "../../Graph.h"
#include "../../Simple_window.h"

class Smiley : public Circle
{
public:
	using Circle::Circle; // use Circle's constructors
	void draw_lines() const;
};

class Frowny : public Circle
{
public:
	using Circle::Circle; // use Circle's constructors
	void draw_lines() const;
};

int main()
{
	constexpr int win_width = 600, win_height = 400;
	constexpr int win_x = 100, win_y = 100;
	const Point win_tl{ win_x, win_y };
	Simple_window win{ win_tl, win_width, win_height, "Smiley and Frowny" };

	constexpr int emoticon_radius = 100;
	Smiley smiley{ Point{ win_width / 2 - 150, win_height / 2 }, emoticon_radius };
	Frowny frowny{ Point{ win_width / 2 + 150, win_height / 2 }, emoticon_radius };

	smiley.set_color(Color::black);
	frowny.set_color(Color::black);

	win.attach(smiley);
	win.attach(frowny);
	win.wait_for_button();
}

void Smiley::draw_lines() const
{
	// the eyes
	fl_arc(point(0).x + radius() / 2, 
		point(0).y + (radius() / 2) + (radius() / 6.3), radius() / 5, radius() / 5, 0, 360);

	fl_arc(point(0).x + radius() * 1.3, 
		point(0).y + (radius() / 2) + (radius() / 6.3), radius() / 5, radius() / 5, 0, 360);

	// draw the mouth
	fl_arc(point(0).x + radius() / 1.3, 
		point(0).y + radius(), radius() / 2, radius() / 2, 240, 300);

	// for drawing the "face"
	Circle::draw_lines();
}

void Frowny::draw_lines() const
{
	// the eyes
	fl_arc(point(0).x + radius() / 2,
		point(0).y + (radius() / 2) + (radius() / 6.3), radius() / 5, radius() / 5, 0, 360);

	fl_arc(point(0).x + radius() * 1.3,
		point(0).y + (radius() / 2) + (radius() / 6.3), radius() / 5, radius() / 5, 0, 360);

	// draw the mouth
	fl_arc(point(0).x + radius() / 1.3,
		point(0).y + radius() * 1.5, radius() / 2, radius() / 2, 56, 240);

	// for drawing the "face"
	Circle::draw_lines();
}


Output screenshot: https://1drv.ms/i/s!As6LkLqTe7Ps8GxGkag_yqyXOpLJ . Any help would be appreciated. Thanks in advance.
Last edited on
1
2
3
	// draw the mouth
	fl_arc(point(0).x + radius() / 1.3,
		point(0).y + radius() * 1.5, radius() / 2, radius() / 2, 56, 240);

IIRC, the last two arguments control the starting and ending angles for the arc. Looks like you just need to play around with this until you get it. I think 45 and 135 should work.
Yes, that helped. 45 and 135. Thanks. You think Smiley looks fine, by the way? Or should I do something to that, too?
Topic archived. No new replies allowed.