C++ please. Upvote for good answers Question is located in main.cc ---------------------- bubble.h -------------------------- #include #include "cpputils/graphics/image.h" class Bubble { public: // Member functions of the Bubble class. // These member functions are called "setters" or "setter functions" // because they SET the member variables to the given input. void SetX(int x); void SetY(int y); void SetSize(int size); void SetColor(std::string color);. graphics::Color GetColor(); int GetX(); int GetY(); int GetSize(); std::string ToString(); private: // Member variables of the Bubble class. int x_ = 0; int y_ = 0; int size_ = 0; graphics::Color color_; }; --------------------------------- bubble.cc ------------------------------ #include "bubble.h" #include #include void Bubble::SetX(int x) { x_ = x; } void Bubble::SetY(int y) { y_ = y; } void Bubble::SetSize(int size) { size_ = size; } graphics::Color Bubble::GetColor() { return color_; } int Bubble::GetX() { return x_; } int Bubble::GetY() { return y_; } int Bubble::GetSize() { return size_; } void Bubble::SetColor(std::string color) { const int kMaxChannel = 255; const int kHalfChannel = 125; // Create a map from strings to graphics::Color. std::map colors; colors["red"] = graphics::Color(kMaxChannel, 0, 0); colors["orange"] = graphics::Color(kMaxChannel, kHalfChannel, 0); colors["yellow"] = graphics::Color(kMaxChannel, kMaxChannel, 0); colors["green"] = graphics::Color(0, kMaxChannel, 0); colors["teal"] = graphics::Color(0, kMaxChannel, kMaxChannel); colors["blue"] = graphics::Color(0, 0, kMaxChannel); colors["purple"] = graphics::Color(kHalfChannel, 0, kMaxChannel); if (colors.find(color) == colors.end()) { // Invalid color was passed in. Default to black. std::cout << "Invalid color: " << color << ". Defaulting to black." << std::endl; color_ = graphics::Color(0, 0, 0); } else { color_ = colors[color]; } } std::string Bubble::ToString() { return "Bubble at (" + std::to_string(x_) + ", " + std::to_string(y_) + ") with size " + std::to_string(size_); } ----------------------------------------------------------------------------------------------- main.cc ----------------- #include #include "bubble.h" #include "cpputils/graphics/image.h" int main() { // Prompts the user for input to create the Bubble image. std::cout << "Tell me about your bubble.\n" << "Valid x, y and size are between 0 and 500.\n" << "Valid colors are red, orange, yellow, green, " << "teal, blue, and purple." << std::endl; std::string color; std::cout << "What color? "; std::cin >> color; int size; std::cout << "What size? "; std::cin >> size; int x; std::cout << "What x? "; std::cin >> x; int y; std::cout << "What y? "; std::cin >> y; // ========================== Question here ============================= // TODO: Instantiate a `Bubble` object into a variable called `my_bubble`. // Then, use the member functions to set color, size, and x, y coordinates // based on the user provided input retrieved above. // ======================================================================= // Don't delete this! // This prints out your bubble to the terminal and also // draws it into an image you can view in "bubble.bmp". const int kImageSize = 500; graphics::Image image(kImageSize, kImageSize); if (image.DrawCircle(my_bubble.GetX(), my_bubble.GetY(), my_bubble.GetSize(), my_bubble.GetColor()) && image.SaveImageBmp("bubble.bmp")) { std::cout << my_bubble.ToString() << std::endl; std::cout << "Your bubble was saved to bubble.bmp" << std::endl; } return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ please. Upvote for good answers

Question is located in main.cc

----------------------

bubble.h

--------------------------

#include <string>

#include "cpputils/graphics/image.h"

class Bubble {
public:
// Member functions of the Bubble class.
// These member functions are called "setters" or "setter functions"
// because they SET the member variables to the given input.
void SetX(int x);
void SetY(int y);
void SetSize(int size);
void SetColor(std::string color);.
graphics::Color GetColor();
int GetX();
int GetY();
int GetSize();
std::string ToString();

private:
// Member variables of the Bubble class.
int x_ = 0;
int y_ = 0;
int size_ = 0;
graphics::Color color_;
};

---------------------------------

bubble.cc

------------------------------

#include "bubble.h"

#include <map>
#include <string>

void Bubble::SetX(int x) { x_ = x; }

void Bubble::SetY(int y) { y_ = y; }

void Bubble::SetSize(int size) { size_ = size; }

graphics::Color Bubble::GetColor() { return color_; }

int Bubble::GetX() { return x_; }

int Bubble::GetY() { return y_; }

int Bubble::GetSize() { return size_; }

void Bubble::SetColor(std::string color) {
const int kMaxChannel = 255;
const int kHalfChannel = 125;

// Create a map from strings to graphics::Color.
std::map<std::string, graphics::Color> colors;
colors["red"] = graphics::Color(kMaxChannel, 0, 0);
colors["orange"] = graphics::Color(kMaxChannel, kHalfChannel, 0);
colors["yellow"] = graphics::Color(kMaxChannel, kMaxChannel, 0);
colors["green"] = graphics::Color(0, kMaxChannel, 0);
colors["teal"] = graphics::Color(0, kMaxChannel, kMaxChannel);
colors["blue"] = graphics::Color(0, 0, kMaxChannel);
colors["purple"] = graphics::Color(kHalfChannel, 0, kMaxChannel);

if (colors.find(color) == colors.end()) {
// Invalid color was passed in. Default to black.
std::cout << "Invalid color: " << color << ". Defaulting to black."
<< std::endl;
color_ = graphics::Color(0, 0, 0);
} else {
color_ = colors[color];
}
}

std::string Bubble::ToString() {
return "Bubble at (" + std::to_string(x_) + ", " + std::to_string(y_) +
") with size " + std::to_string(size_);
}
-----------------------------------------------------------------------------------------------

main.cc

-----------------

#include <iostream>

#include "bubble.h"
#include "cpputils/graphics/image.h"

int main() {
// Prompts the user for input to create the Bubble image.
std::cout << "Tell me about your bubble.\n"
<< "Valid x, y and size are between 0 and 500.\n"
<< "Valid colors are red, orange, yellow, green, "
<< "teal, blue, and purple." << std::endl;

std::string color;
std::cout << "What color? ";
std::cin >> color;

int size;
std::cout << "What size? ";
std::cin >> size;

int x;
std::cout << "What x? ";
std::cin >> x;

int y;
std::cout << "What y? ";
std::cin >> y;

// ========================== Question here =============================
// TODO: Instantiate a `Bubble` object into a variable called `my_bubble`.
// Then, use the member functions to set color, size, and x, y coordinates
// based on the user provided input retrieved above.
// =======================================================================

// Don't delete this!
// This prints out your bubble to the terminal and also
// draws it into an image you can view in "bubble.bmp".
const int kImageSize = 500;
graphics::Image image(kImageSize, kImageSize);
if (image.DrawCircle(my_bubble.GetX(), my_bubble.GetY(), my_bubble.GetSize(),
my_bubble.GetColor()) &&
image.SaveImageBmp("bubble.bmp")) {
std::cout << my_bubble.ToString() << std::endl;
std::cout << "Your bubble was saved to bubble.bmp" << std::endl;
}
return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education