Classes/Member Functions

N/A... Yeah Pan,
Last edited on
It looks like you failed to use ckRange() anywhere.
Please do not remove your question after someone answers it. It's rather rude.

OP:
So this is what my auto grader gave me...

Test 7 -- Test for: Color constructors works
.................................. worth 2 points: FAILED


*******************************************
***** *****
***** Your output is: *****
***** *****
*******************************************
13 25 135
-5 256 -1


*******************************************
***** *****
***** Correct Output *****
***** *****
*******************************************
13 25 135
0 255 0

Test 8 -- Test for: setters
.................................. worth 2 points: FAILED
Test 9 -- Test for: getters
.................................. worth 2 points: FAILED
Test 10 -- Test for: read
.................................. worth 2 points: passed
Test 11 -- Test for: ckValue
.................................. worth 2 points: FAILED

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

Here is my code for Color.cpp http://pastebin.com/82hyWGUd
Here are the specs/Color.h http://pastebin.com/G7U1StsJ

This is our opening project on Classes so I looked over Point.h/Point.cpp which we did in class and followed those forms here. But, it is obvious I am making lots of mistakes. I have looked over the Classes page on the site and watched some videos... Could anyone here help me get started with fixing these issues?


Pastebin one contents:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Color.h"

Color::Color()
{
      red = 0;
      green = 0;
      blue = 0;

} 

Color::Color(int redVal, int greenVal, int blueVal)
{
      red = redVal;
      green = greenVal;
      blue = blueVal;

} 

void Color::setRed(int redVal)
{
	red = redVal;
}


Pastebin 2 contents:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef COLOR_H
#define COLOR_H

#include <iostream>
using namespace std;

//NOTE: red, green, and blue must be within the range of [0,255]
//      if any are out of range, assign either 0 or 255 (whichever is closest)
//      i.e., if value is negative, assign 0
//            if value > 255, assign 255
//            done through ckRange(...)


class Color
{
public:
	Color();                      //default constructor
	Color(int redVal, int greenVal, int blueVal);//constructor taking rgb
	void setRed(int redVal);      // set red value
	void setGreen(int greenVal);  // set green value
	void setBlue(int blueVal);    // set blue value
	
	int getRed() const;           // gets red value
	int getGreen() const;         // gets green value
	int getBlue() const;          // gets blue value
      
    void read(istream& ins);      // in the order of red  green  blue
    void write(ostream& outs) const;

private:
	int red, green, blue;
	int ckRange(int val);         // you also need to implement this one
	                           
	
};

istream& operator >> (istream& ins, Color& color);
ostream& operator << (ostream& outs, Color color);
#endif 


Last edited on
Topic archived. No new replies allowed.