Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
  • 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

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

How does a share dividend differ from a share split?

Answered: 1 week ago

Question

Distinguish the difference between a prototype and a concept.

Answered: 1 week ago

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago