Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
White Dwarf Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Nest
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions, OSR, & D&D Variants
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
EN Publishing
Twitter
BlueSky
Facebook
Instagram
EN World
BlueSky
YouTube
Facebook
Twitter
Twitch
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions, OSR, & D&D Variants
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Upgrade your account to a Community Supporter account and remove most of the site ads.
Community
General Tabletop Discussion
*Geek Talk & Media
C++ Help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Macbeth" data-source="post: 1483349" data-attributes="member: 11259"><p>For a project in my CS class, I have created the following code to create a binary tree, and use that tree to encrypt information, using the scheme:</p><p>0 - move one node left</p><p>1 - move one node right</p><p>2 - take the information from the current node.</p><p></p><p>Now I know that the code probably has all kinds of logic errors, but at this point it won't compile! I get a "PCH creation point" error every time. in the past this has usually been becuase I missed a semicolon, but damn if I know where that is. So I'm asking for somebody to pleas tell me where this error is coming from! I'll fix the (likely plentifil) logic errors on my own, i just want to know why the damn thing won't compile:</p><p></p><p>CryptoTree.h:</p><p>[code]</p><p>#include <cstdlib></p><p>#include <ctime></p><p>#include <iostream></p><p>#include <string></p><p></p><p>using namespace std;</p><p></p><p></p><p>class Node {</p><p>public:</p><p> char data;</p><p> Node *left;</p><p> Node *right;</p><p></p><p> Node (char inp) {</p><p> data = inp;</p><p> left = NULL;</p><p> right = NULL;</p><p> }</p><p>};</p><p></p><p></p><p>/*//////////////////////////////*/</p><p></p><p></p><p>class CryptoTree {</p><p></p><p>protected:</p><p> Node *head;</p><p></p><p></p><p> Node *nodeSearch (char info) {</p><p> Node *temp = head;</p><p> Node *decide = head;</p><p></p><p> while (decide != NULL) {</p><p> temp = decide;</p><p> if (info < temp->data) {</p><p> decide = decide->left;</p><p> } else {</p><p> decide = decide->right;</p><p> }</p><p> }</p><p> </p><p></p><p> int search (Node *position, char info) {</p><p> if (position != NULL) {</p><p> if (search (position->left, info) == 1 || position->data == info || search (position->right, info) == 1){</p><p> return(1);</p><p> }</p><p> }</p><p> return(0);</p><p> }</p><p></p><p> string outSearch(Node *pos, char info, string out) {</p><p> string leftstring = out + "0";</p><p> string rightstring = out + "1";</p><p></p><p> if ( pos != NULL ){</p><p> if(pos->data == info){</p><p> return(out);</p><p> } else {</p><p> out = outSearch(pos->left, info, leftstring);</p><p> out = outSearch(pos->right, info, rightstring);</p><p> }</p><p> </p><p> }</p><p> return(out);</p><p> } </p><p></p><p></p><p> int treeFull(){</p><p> int i;</p><p> for ( i = 48; i < 91; i++) {</p><p> if( search(head, ((char)i)) == 0){</p><p> return(0);</p><p> }</p><p> }</p><p> return(1);</p><p> }</p><p> </p><p> </p><p></p><p> void keyPrint(Node *target, string code) {</p><p> </p><p> string leftcode = code + "0";</p><p> string rightcode = code + "1";</p><p> </p><p> if(target->left != NULL){</p><p> keyPrint(target->left, leftcode);</p><p> }</p><p> cout << code << "2 - " << target->data << endl;</p><p> if(target->right != NULL){</p><p> keyPrint(target->right, rightcode);</p><p> }</p><p></p><p> return;</p><p> }</p><p></p><p>public:</p><p> CryptoTree () {</p><p> srand(static_cast<unsigned>(time(0)));</p><p> char rand;</p><p> int irand;</p><p></p><p> while(treeFull == 0){</p><p> irand = (48 + ((int) 43 * rand() / (RAND_MAX + 1.0)));</p><p> rand = (char)irand;</p><p> insert(rand);</p><p> }</p><p> </p><p> } // constructor</p><p></p><p> void insert (char inp) {</p><p> Node *temp = new Node (inp);</p><p></p><p> if (head == NULL) {</p><p> head = temp;</p><p> } else {</p><p> Node *seek = nodeSearch (temp->data);</p><p> </p><p> if (temp->data < seek->data) {</p><p> seek->left = temp;</p><p> } else {</p><p> seek->right = temp;</p><p> }</p><p> }</p><p> return;</p><p> } // insert</p><p></p><p></p><p> void returnKey(){</p><p> string init;</p><p> init = " ";</p><p> cout << "Encryption Key:" << endl;</p><p> printKey(head, init);</p><p> return;</p><p> }</p><p></p><p></p><p> string encrypt(string input){</p><p> char targ;</p><p> string starter = "";</p><p> int max = input.length();</p><p> int j;</p><p> </p><p> for( j = 0; j < max; j++){ </p><p> targ = input[j];</p><p> starter = starter + outSearch(head, targ, starter);</p><p> }</p><p> return(starter);</p><p> }</p><p></p><p> string decrypt(string input){</p><p> int max;</p><p> int k;</p><p> node *trav;</p><p> string out;</p><p> trav = head;</p><p> max = input.length();</p><p> out = ""; </p><p></p><p> for(k = 0; k < max; k++){</p><p> if(input[k] == 2){</p><p> out = out + (trav->data);</p><p> }else if(input[k] == 0){</p><p> trav = trav->left;</p><p> }else{</p><p> trav = trav->right;</p><p> }</p><p> }</p><p></p><p> return(out);</p><p> }</p><p></p><p></p><p>};</p><p>[/code]</p><p></p><p>cryptoTest.cpp:</p><p>[code]</p><p>#include "Crypto.h"</p><p></p><p></p><p>int main() {</p><p> CryptoTree Trial;</p><p></p><p> Trial.returnKey();</p><p></p><p></p><p> return(0);</p><p>}</p><p>[/code]</p><p></p><p>I know the lack of commenting is horrible, I was goign to comment it once I had working code. I'll try commenting it now, and post an easier to read version in a while, if nobody can read the code as is.</p></blockquote><p></p>
[QUOTE="Macbeth, post: 1483349, member: 11259"] For a project in my CS class, I have created the following code to create a binary tree, and use that tree to encrypt information, using the scheme: 0 - move one node left 1 - move one node right 2 - take the information from the current node. Now I know that the code probably has all kinds of logic errors, but at this point it won't compile! I get a "PCH creation point" error every time. in the past this has usually been becuase I missed a semicolon, but damn if I know where that is. So I'm asking for somebody to pleas tell me where this error is coming from! I'll fix the (likely plentifil) logic errors on my own, i just want to know why the damn thing won't compile: CryptoTree.h: [code] #include <cstdlib> #include <ctime> #include <iostream> #include <string> using namespace std; class Node { public: char data; Node *left; Node *right; Node (char inp) { data = inp; left = NULL; right = NULL; } }; /*//////////////////////////////*/ class CryptoTree { protected: Node *head; Node *nodeSearch (char info) { Node *temp = head; Node *decide = head; while (decide != NULL) { temp = decide; if (info < temp->data) { decide = decide->left; } else { decide = decide->right; } } int search (Node *position, char info) { if (position != NULL) { if (search (position->left, info) == 1 || position->data == info || search (position->right, info) == 1){ return(1); } } return(0); } string outSearch(Node *pos, char info, string out) { string leftstring = out + "0"; string rightstring = out + "1"; if ( pos != NULL ){ if(pos->data == info){ return(out); } else { out = outSearch(pos->left, info, leftstring); out = outSearch(pos->right, info, rightstring); } } return(out); } int treeFull(){ int i; for ( i = 48; i < 91; i++) { if( search(head, ((char)i)) == 0){ return(0); } } return(1); } void keyPrint(Node *target, string code) { string leftcode = code + "0"; string rightcode = code + "1"; if(target->left != NULL){ keyPrint(target->left, leftcode); } cout << code << "2 - " << target->data << endl; if(target->right != NULL){ keyPrint(target->right, rightcode); } return; } public: CryptoTree () { srand(static_cast<unsigned>(time(0))); char rand; int irand; while(treeFull == 0){ irand = (48 + ((int) 43 * rand() / (RAND_MAX + 1.0))); rand = (char)irand; insert(rand); } } // constructor void insert (char inp) { Node *temp = new Node (inp); if (head == NULL) { head = temp; } else { Node *seek = nodeSearch (temp->data); if (temp->data < seek->data) { seek->left = temp; } else { seek->right = temp; } } return; } // insert void returnKey(){ string init; init = " "; cout << "Encryption Key:" << endl; printKey(head, init); return; } string encrypt(string input){ char targ; string starter = ""; int max = input.length(); int j; for( j = 0; j < max; j++){ targ = input[j]; starter = starter + outSearch(head, targ, starter); } return(starter); } string decrypt(string input){ int max; int k; node *trav; string out; trav = head; max = input.length(); out = ""; for(k = 0; k < max; k++){ if(input[k] == 2){ out = out + (trav->data); }else if(input[k] == 0){ trav = trav->left; }else{ trav = trav->right; } } return(out); } }; [/code] cryptoTest.cpp: [code] #include "Crypto.h" int main() { CryptoTree Trial; Trial.returnKey(); return(0); } [/code] I know the lack of commenting is horrible, I was goign to comment it once I had working code. I'll try commenting it now, and post an easier to read version in a while, if nobody can read the code as is. [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Geek Talk & Media
C++ Help
Top