Jump to content

The_Big_Man

Member
  • Posts

    2
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United Kingdom

About The_Big_Man

The_Big_Man's Achievements

0

Reputation

  1. I have these points to cover and i have done the coding for it . Could someone check it to see if so far its correct and i have have done everything? 1) Define appropriate instance variables for the class Colour 2) Define a set of appropriate constructors for this class 3) Provide "constant" values for each of the nine principal colours listed above that will enable any application that needs to use these colours, say "yellow" to write Colour.yellow etc 4) Define appropriate accessor and setter methods for this class 5) Provide a boolean-valued operation that checks whether two Colour objects have the same value 6) Override the inherited String toString() method to provide an appropriate String representation of a Colour object 7) Provide a method mix() which takes two colours and "mixes" them to produce a new colour whose RGB values are obtained by averaging the individual colour components, for example mixing (20, 30, 40) with (180, 60, 95) produces the colour (100, 45, 67) 8) Provide a method brighter() which creates a new Colour that is a brighter version of this Colour - this should be achieved by increasing each of the current colour's RGB values by 42% up to a maximum of 255 9) Provide a method darker() which creates a new Colour that is a darker version of this Colour - this should be achieved by decreasing each of the current colour's RGB values by 30% class Colour { public static final Colour black = new Color(0,0,0); public static final Colour red = new Colour(255,0,0); public static final Colour blue = new Colour(255,0,0); public static final Colour cyan = new Colour(0,255,255); public static final Colour green = new Colour(0,255,0); public static final Colour grey = new Colour(128,128,128); public static final Colour magenta = new Colour(255,0,255); public static final Colour yellow = new Colour(255,255,0); private static final int MAX = 255; private static final int MIN = 0; private int red; private int green; private int blue; public Colour() { red = 125; green = 55; blue = 66; } public Colour( int n ) { red = n; green = n; blue = n; } public int getRed() { return red; } public int getGreen() { return green; } public int getBlue() { return blue; } public Colour(int r1, int g2, int b3) { this.r1 = r1; this.g2 = g2; this.b3 = b3; } public boolean equals(Colour n) { return ( (this.r1 == c.n1) && (this.g2 == c.g2) && (this.b3 == c.b3) ) || ( (this.r1 == c.r1) && (this.g2 == c.g2) && (this.b3 == c.b3)); } public void Mix(Colour c1, Colour c2) { this.red = (c1.red + c2.red) / 2; this.green = (c1.green + c2.green) / 2; this.green = (c1.blue + c2.blue) / 2; } public String toString() { return string.Format("{0},{1},{2}", this.red, this.green, this.blue); } public brighter() { this.red = this.red - (this.red*042); this.green = this.green - (this.green *042); this.blue = this.blue - (this.blue *042); return brighter(); } public darker() { this.red = this.red + (this.red*030); this.green = this.green + (this.green *030); this.blue = this.blue + (this.blue *030); return darker(); } }
  2. I trying to create a word dictionary that reads in words from a file and inputs them onto the screen e.g word followed by space and then definition all one one line and sorts them in ascending order. These are the codings i have so far. Could you help my in telling what i have to do next and whats missing from this coding and anything thing else: So far i have these codings: //keyValue.h #include <string> class keyValue { private: string word; // primary key value string definition; keyValue* next; keyValue(); // constructor – initialise node friend class OrderedList; }; //orderedList.h #include <string> class OrderedList { public: OrderedList(); // constructor – initialise empty list ~OrderedList(); // destructor /* insert data into the list in ascending word order. If the word is already present in the list, update the existing definition by concatenating the current one */ void insert( string word, string definition); /* return definition associated with key ‘w’. return null string if 'w' is not present in the list */ const string inspect( string w ) const; // whether 'w' is present in the list bool isIn( string w ) const; // whether the list is empty bool isEmpty() const; // take a keyValue object containing a word and // its definition(s). Print it. void printEntry() const; private: keyValue* head; }; //staticHTable.h #include <string> const int TABLE_SIZE = 23; class staticHTable { public: staticHTable(); // constructor – create empty table ~staticHTable(); // destructor /* enter data into table. if the word is already present in the list, update the existing definition by concatenating the current one */ void put(string w, string d); /* return definition associated with key 'w' return null string if 'w’ is not present in the table */ const string get( string w ) const; private: struct { string word; string definition; } sHTable[TABLE_SIZE]; }; //dynamicHTable.h #include <string> const int TABLE_SIZE = 23; class dynamicHTable { public: DynamicHTable(); // constructor – create empty table ~DynamicHTable(); // destructor /* enter data into table. if the word is already present in the list, update the existing definition by concatenating the current one */ void put(string w, string d); /* return definition associated with key 'w'. return null string if 'w’ is not present in the table */ const string get( string w ) const; private: OrderedList dHTable[TABLE_SIZE]; } //file OrderedList.cc #include <iostream> #include <stddef.h> #include "OrderedList.h" using namespace std; KeyValue::KeyValue() { word = "\0"; next = NULL; definition = "\0"; next = NULL; } OrderedList::OrderedList() { head = NULL; } OrderedList::~OrderedList() { KeyValue* current; KeyValue* it; it = head; while (it != NULL) { current = it; it = it->next; delete current; } } bool OrderedList::isEmpty() const { return head == NULL; } void OrderedList::insertBefore(const int newval, const int val) { KeyValue* p = new KeyValue; KeyValue* iterator = NULL; KeyValue* previous = NULL; p->data = newval; p->next = NULL; if (isEmpty()) { cout << "List is empty\n"; } else { for (iterator = head; iterator != NULL; iterator = iterator->next) { if (iterator->data == val) { if (iterator == head) { head = p; } else { previous->next = p; } p->next = iterator; break; } else { previous = iterator; } } } } void OrderedList::printEntry() const { if (isEmpty()) { cout << "List empty" << endl; } else // walk along list { KeyValue* p = NULL; for (p=head; p!=NULL; p=p->next) { cout << p->data << endl; // display data value } } } thanks
×
×
  • Create New...