Question
The task for this assignment is to write a C++ program to have the following user-defined data type: struct rgb { unsigned char red; unsigned
The task for this assignment is to write a C++ program to have the following user-defined data type:
struct rgb
{
unsigned char red;
unsigned char green;
unsigned char blue;
};
be able to be:
- read in from a stream (e.g., std::cin),
- i.e., write: std::istream& operator >>(std::istream& is, rgb& colour); (see below)
- written out to a stream (e.g., std::cout),
- i.e., write: std::ostream& operator <<(std::ostream& os, rgb const& colour); (see below)
- stored in a container,
- e.g., std::vector
, std::array ; (see below)
- e.g., std::vector
- processed via algorithms (and other functions) (e.g., std::transform).
- e.g., write: double distance(rgb const& a, rgb const& b); (see below)
The rgb type represents a colour (e.g., for a pixel) with the components red, green, and blue. By convention, these components are values between 0 and 255 inclusively --but such is not enforced by the rgb definition in this assignment.
NOTE: In this assignment nothing will be added, defined, declared, or removed from the rgb structure. Many often think writing a class requires writing constructors, etc. which can be a lot of (often unnecessary) code. This assignment will rely on C++'s default definitions for constructors, etc. Subsequent assignments will define constructors, etc.
As with everything in this course, you cannot use the C language and C Standard Library unless that feature has not suitable C++ implementation, e.g., printf() and scanf() are not allowed to be used in this assignment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started