A friend of mine works for a software company and has mentioned that he knows someone who is a beginner in C++ (me!). There is a position available so they have sent me a task to complete (attached below) but quite frankly I don't know where to begin. I am good at understanding programs but to create this seems a bit too deep for me. So should I give it a go with some help or should I keep my head in the books?
Thanks
Coding Task: Colour Chart
Introduction
This is a C++ coding test for potential programmers. It is expected that this task should take a few hours to complete.
Task description
Overview
When designing graphics hardware it is useful to be able to display various test patterns and colour ramps. The task is to write a command-line application to generate some of these test patterns.
In the simplest case this program will produce a colour ramp starting with one colour on one side of the screen and changing smoothly to a second colour on the other side.
In the most complex case there will be a different colour in each corner of the screen and each pixel on the screen will show the appropriate mix of these four colours.
Input
The program should read the following values from the command line:
• Name of display device
• Top Left Colour value
• Top Right Colour value
• Bottom Right Colour value [optional, defaults to Top Right]
• Bottom Left Colour value [optional, defaults to Top Left]
Output
The program should fill the screen with a colour ramp as defined by the input values. Each corner of the screen should have the specified colour and the pixels in the middle should be the appropriate linear mix of those colours.
Pixels are specified as 16-bit numbers in RGB565 format. The bits for each colour are assigned as follows:
The image is output on the display device using the Display class which is provided. The get_size method returns the size of the display and the draw_raster method is used to draw a row of pixels on the screen.
Assessment
The results of this task will be assessed in the following areas:
• Correct operation for all input values
• Clarity and flexibility of design
• Consistent coding style and appropriate use of C++ features
• Appropriate error handling
You must provide full source code and a brief description of the input formats. The program will be tested under Visual C++ with a variety of input values.
The implementation of the Display class is provided below.
Notes
Correct behaviour is much more important than good performance.
This is a test program so you can assume an intelligent user who knows what they are doing.
This task is harder than it appears: there are a number of pitfalls and difficult cases to allow for. In particular, make sure that the colours are spread evenly when there are only a few different colours across the screen.
Feel free to contact us if anything is unclear or if you would like further guidance.
Display Class implementation
Header file
class Display {
public:
Display();
bool connect(const char *display_name);
void get_size(int &width, int &height);
void draw_raster(int x, int y,
const unsigned short *pixels, int width);
};
Implementation file
#include <cstdio>
#include <cassert>
#include <memory.h>
void Display::draw_raster(int x, int y,
const unsigned short *pixels, int width)
{
memcpy(&frame_buffer[y*W+x], pixels, width*sizeof(unsigned short));
}
If you have no idea at all, then I guess it's a bit too early for you to go for a job like this. This is just an interview question; some of the problems you'll encounter at work will be a lot harder!
But you could still give it a go. Though you really need to do it yourself (with the help of references, and Google, of course--to find out information.)
should I keep my head in the books?
Studying books, etc is good.
But you should be doing you own small development project, as well as experimenting with small programs, to put into practice what you've learnt.
If you haven't already done so, you could also check out the code in open source projects at sourceforge.net, code.google.com, codeplex.com, etc (look for the projects that allow you to browse code.) To see how much of the code you can follow. Maybe even get involved with one?
Thanks for the replies. It is actually my friend that is pushing this on me but I think he is just dreaming. I know I can be a good programmer but I do need more time and practice.
@Fredbill30 reported for not providing useful or relevant answer.
@wasizzle You need to read the instructions. They have you provided you with the display methods, all you need to do is provide the code that generates the colours and pass it in to the display class.
Firstly, you need to try and compile the code they've given you and just write all white to the screen. Looking at the code they've giving you this should be a fairly straightforward task