Computing.Net > Forums > Programming > Sets and Lists

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sets and Lists

Reply to Message Icon

Name: aqulopez44
Date: September 1, 2008 at 11:20:09 Pacific
OS: xp
CPU/Ram: 3 gb
Product: custom
Comment:

I am working on a c++ project and I am having trouble understanding. This should be pretty as each code you need to insert should only be one or two lines. Here is what I have to do and what I have already figured out on my own, if anyone could help I would really appreciate it.

You will write the member functions of the class set. For the simplicity of lab you can do these functions inline. There are 6 functions for write their prototypes are:

void insert(char c);
void insert(const char chars[]);
bool isMember(char c);
void remove(char c);
string toSrting();
in indexFromChar(char c)

put a specific character into the set, if the character is already in the set, there are no changes
void insert(char c)

a function that removes a character from the set
remove(char c)

insert a null-terminated array of characters into the set. This is a c-string, you can insert character by character into the set.
vod insert(const char chars[])

a function that takes all of the characters that are in the set and converts them to a c++ string.
toString()

a function that returns a string containing all of the characters in this set is ASCII-valus order. NOTE this will act funny with non-printable characters
string toString()

a function that maps characters 1-1 to their position in the array (range 0-255) remember that the signed chars have valu -128 to 127.
int indexFormChar(char c)

THIS IS THE CODE. I PUT A COMMENT OF CODE WHERE I NEED THE HELP.

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

// chars are 8-bit, meaning there can only be 256 of them
const int NUMBER_OF_UNIQUE_CHARS = 256;


class CharSet {
public:

// constructors initializes the set to empty
CharSet() {
for (int i = 0; i < NUMBER_OF_UNIQUE_CHARS; i++)
isInSet[i] = false;
}

// put a specific character into the set
// if the character is already in the set, no change
void insert(char c) {
//YOUR CODE HERE
}

// check if a specific character in in the set
bool isMember(char c) {
//YOUR CODE HERE
}

// remove a character from the set
// if the character is not in the set, no change
void remove(char c) {
//YOUR CODE HERE
}

}

// insert a null-terminated (c-string) of characters
// into the set
void insert(const char chars[]) {
//YOUR CODE HERE
}

// return a string containing all of the characters in
// this set in ASCII-value order

string toString() {
//YOUR CODE HERE
}

private:

// maps characters to the range 0-255 in a 1-1 manner
int indexFromChar(char c) {
//YOUR CODE HERE
}
}

// maps the range 0-255 into characters in a 1-1 manner
char charFromIndex(int i) {
unsigned char uc = i;
return (char)uc;
}

// an array of 256 bools, each reresents wheter a specific
// character is in the set or not
bool isInSet[NUMBER_OF_UNIQUE_CHARS];
};


//////////////////////////////////////...
//
// TEST CODE FOR CHARSET
//
//////////////////////////////////////...
int main() {

// BEGIN TEST ONE: RANDOM NAME
CharSet s1;

// insertions galore, some duplicates
s1.insert('B');
s1.insert('e');
s1.insert('n');

s1.insert('H');
s1.insert('e');
s1.insert('s');
s1.insert('c');
s1.insert('o');
s1.insert('t');
s1.insert('t');

// test the tostring method
// NOTE: we output what we expect to get when testing
cout << endl << "Expecting s1 to contains \"BHcenost\"" << endl;
cout << "s1 actually contains \"" << s1.toString() << "\"" << endl << endl;

// test the ismember method
cout << "Expecting: false - true - true" << endl;
cout << "Got: "<< s1.isMember('b') << " - " << s1.isMember('e')
<< " - " << s1.isMember('n') << endl << endl;

// BEGIN TEST TWO THE COMPLETE ALPHABET
CharSet s2;


s2.insert("The quick brown fox jumps over the lazy dog.");

s2.remove(' ');
s2.remove('.');
s2.insert('t');
s2.remove('T');


cout << "Expecting s2 to contain \"abcdefghijklmnopqrstuvwxyz\"" << endl;
cout << "s2 actually contains \"" << s2.toString() << "\"" << endl << endl;
}



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: September 1, 2008 at 18:39:44 Pacific
Reply:

//YOUR CODE HERE
No, not MY code, YOUR code. I ain't going to do your homework for you.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Sets and Lists

C++ setting and getting members www.computing.net/answers/programming/c-setting-and-getting-members/6792.html

VB file name parser and sorter www.computing.net/answers/programming/vb-file-name-parser-and-sorter/15622.html

Ping list of computers from a txt file www.computing.net/answers/programming/ping-list-of-computers-from-a-txt-file/19843.html