Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,379 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,194 people online right now. Registration is fast and FREE... Join Now!




C++ char help

 
Reply to this topicStart new topic

C++ char help, converting signed char to unsigned char: hey guys i am almost done wi

airplaneman23
post 31 Aug, 2008 - 09:36 AM
Post #1


New D.I.C Head

*
Joined: 31 Aug, 2008
Posts: 2

cpp
#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 = false;
}

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

}

// 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) {

}

}

// 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() {

}

private:

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

}
}

// 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;
}


Mod edit: Please [code=cpp] paste your code between these tags [/code]
Thanks, gabehabe smile.gif

This post has been edited by gabehabe: 31 Aug, 2008 - 10:47 AM
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 31 Aug, 2008 - 10:41 AM
Post #2


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 502



Thanked 44 times

Dream Kudos: 25
My Contributions


Please:

1. Edit your post to enclose the code in [code] tags.
2. Post your specific question in the body of the post, not in the description.

Thanks!

User is offlineProfile CardPM

Go to the top of the page

airplaneman23
post 31 Aug, 2008 - 10:53 AM
Post #3


New D.I.C Head

*
Joined: 31 Aug, 2008
Posts: 2

Done. I have the main part of the program done, I just need some help writing some of the functions towards the top.

MOD EDIT: Removed the quoted text. Please don't quote the entire post. Thanks. - [ b 2 c ]
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 06:21AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month