Colorful bubbles In this problem, you will use the Bubble class to make images of colorful bubbles. You will use your knowledge of classes and objects to make an instance of the Bubble class (aka instantiate a Bubble), set its member variables, and use its member functions to draw a Bubble into an image. Every Bubble object has the following member variables: X coordinate Y coordinate Size (i.e. its radius) Color Complete main.cc Your task is to complete main.cc to build and draw Bubble objects based on user input. main.cc already does the work to draw the Bubble as an image saved in bubble.bmp. You should follow these steps: First, you will need to create a Bubble object from the Bubble class. Next, you must prompt the user to provide the following: an int for the X coordinate, an int for the Y coordinate, an int for the Bubble's size, and a std::string for the Bubble's color. Next, you must use the user's input to set the new Bubble object's x and y coordinates, the size, and the color using the member functions of the Bubble class. Finally, you can open the bubble.bmp file to see the bubble you've drawn. You should see a circle centered at (x, y) with a radius of size, in the given color. main.cc file #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 = 0;   std::cout << "What size? ";   std::cin >> size;       int x = 0;   std::cout << "What x? ";   std::cin >> x;       int y = 0;   std::cout << "What y? ";   std::cin >> y;       // ========================== YOUR CODE HERE =============================   // 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".   constint image_size = 500;   graphics::Image image(image_size, image_size);   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;   }   return0;   } bubble.cc file #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() const {   return color_;   }       int Bubble::GetX() const {   return x_;   }       int Bubble::GetY() const {   return y_;   }       int Bubble::GetSize() const {   return size_;   }       void Bubble::SetColor(const std::string& color) {   constint max_channel = 255;   constint half_channel = 125;       // Create a map from strings to graphics::Color.   std::map colors;   colors["red"] = graphics::Color(max_channel, 0, 0);   colors["orange"] = graphics::Color(max_channel, half_channel, 0);   colors["yellow"] = graphics::Color(max_channel, max_channel, 0);   colors["green"] = graphics::Color(0, max_channel, 0);   colors["teal"] = graphics::Color(0, max_channel, max_channel);   colors["blue"] = graphics::Color(0, 0, max_channel);   colors["purple"] = graphics::Color(half_channel, 0, max_channel);       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() const {

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

Colorful bubbles

In this problem, you will use the Bubble class to make images of colorful bubbles. You will use your knowledge of classes and objects to make an instance of the Bubble class (aka instantiate a Bubble), set its member variables, and use its member functions to draw a Bubble into an image.

Every Bubble object has the following member variables:

  • X coordinate
  • Y coordinate
  • Size (i.e. its radius)
  • Color

Complete main.cc

Your task is to complete main.cc to build and draw Bubble objects based on user input. main.cc already does the work to draw the Bubble as an image saved in bubble.bmp. You should follow these steps:

  1. First, you will need to create a Bubble object from the Bubble class.
  2. Next, you must prompt the user to provide the following: an int for the X coordinate, an int for the Y coordinate, an int for the Bubble's size, and a std::string for the Bubble's color.
  3. Next, you must use the user's input to set the new Bubble object's x and y coordinates, the size, and the color using the member functions of the Bubble class.
  4. Finally, you can open the bubble.bmp file to see the bubble you've drawn. You should see a circle centered at (x, y) with a radius of size, in the given color.

main.cc file

#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 = 0;
  std::cout << "What size? ";
  std::cin >> size;
   
  int x = 0;
  std::cout << "What x? ";
  std::cin >> x;
   
  int y = 0;
  std::cout << "What y? ";
  std::cin >> y;
   
  // ========================== YOUR CODE HERE =============================
  // 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".
  constint image_size = 500;
  graphics::Image image(image_size, image_size);
  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;
  }
  return0;
 

}

bubble.cc file

#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() const {
  return color_;
  }
   
  int Bubble::GetX() const {
  return x_;
  }
   
  int Bubble::GetY() const {
  return y_;
  }
   
  int Bubble::GetSize() const {
  return size_;
  }
   
  void Bubble::SetColor(const std::string& color) {
  constint max_channel = 255;
  constint half_channel = 125;
   
  // Create a map from strings to graphics::Color.
  std::map<std::string, graphics::Color> colors;
  colors["red"] = graphics::Color(max_channel, 0, 0);
  colors["orange"] = graphics::Color(max_channel, half_channel, 0);
  colors["yellow"] = graphics::Color(max_channel, max_channel, 0);
  colors["green"] = graphics::Color(0, max_channel, 0);
  colors["teal"] = graphics::Color(0, max_channel, max_channel);
  colors["blue"] = graphics::Color(0, 0, max_channel);
  colors["purple"] = graphics::Color(half_channel, 0, max_channel);
   
  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() const {
  return"Bubble at (" + std::to_string(x_) + ", " + std::to_string(y_) +
  ") with size " + std::to_string(size_);
  }

bubble.h file

 

To better understand the member variables and member functions contained within the Bubble class, you may refer to this class diagram:
Class diagram
Bubble
int x_;
int y_;
int size_;
graphics::Color color_;
void SetX(int x);
void SetY(int y);
void SetSize(int size);
void SetColor(std::string color);
int GetX();
int GetY();
int GetSize();
graphics::Color GetColor();
std::string ToString();
← Class name
←member variables
← member functions
Transcribed Image Text:To better understand the member variables and member functions contained within the Bubble class, you may refer to this class diagram: Class diagram Bubble int x_; int y_; int size_; graphics::Color color_; void SetX(int x); void SetY(int y); void SetSize(int size); void SetColor(std::string color); int GetX(); int GetY(); int GetSize(); graphics::Color GetColor(); std::string ToString(); ← Class name ←member variables ← member functions
Member variable descriptions
x_- the X coordinate of this Bubble
y - the Y coordinate of this Bubble
size - the size, or the radius, of this Bubble
color_ - the color of this Bubble
Member function descriptions
void SetX(int x); - set or change the X coordinate
void SetY(int y); - set or change the Y coordinate
void SetSize(int size); - set or change the radius of this Bubble
void SetColor(std::string color); - set or change the color of this Bubble
int GetX(); - get the X coordinate
int GetY(); - get the Y coordinate
int GetSize(); - get the size
graphics::Color GetColor(); - get the color
std::string ToString(); - prints out a string representation of this Bubble to the terminal
Note that no constructor is explicitly listed here. If no user-declared constructors of any kind are provided in a class, the compiler will always
declare a default constructor, which is a constructor which accepts no parameters.
Note: you only need to look inside bubble.h (the header file) to know what member functions you may use in the Bubble class. While the
implementation of the Bubble class lives in bubble.cc, it's not necessary that you understand how it works in order to use its member
functions. This is the beauty of header files - you can read the function declarations in a .h file to use functions without knowing how they
work underneath.
Transcribed Image Text:Member variable descriptions x_- the X coordinate of this Bubble y - the Y coordinate of this Bubble size - the size, or the radius, of this Bubble color_ - the color of this Bubble Member function descriptions void SetX(int x); - set or change the X coordinate void SetY(int y); - set or change the Y coordinate void SetSize(int size); - set or change the radius of this Bubble void SetColor(std::string color); - set or change the color of this Bubble int GetX(); - get the X coordinate int GetY(); - get the Y coordinate int GetSize(); - get the size graphics::Color GetColor(); - get the color std::string ToString(); - prints out a string representation of this Bubble to the terminal Note that no constructor is explicitly listed here. If no user-declared constructors of any kind are provided in a class, the compiler will always declare a default constructor, which is a constructor which accepts no parameters. Note: you only need to look inside bubble.h (the header file) to know what member functions you may use in the Bubble class. While the implementation of the Bubble class lives in bubble.cc, it's not necessary that you understand how it works in order to use its member functions. This is the beauty of header files - you can read the function declarations in a .h file to use functions without knowing how they work underneath.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Class
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
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