Read and Write to input file using trees in C++?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 2899 Views - Last Post: 09 July 2013 - 07:08 PM Rate Topic: -----

#31 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 04:01 PM

View PostR2B Boondocks, on 09 July 2013 - 11:15 AM, said:

 char nodeType =  //did you look at the link? condition ? result_if_true : result_if_false, thats the set up.  Create a conditional operator statement (the ? after condition should be in code) 
      out << nodeType << " " << root->question << endl; //I gave you this part to replace your cout line.



Yeah I read the link. I don't think I am setting it up right because c++ throw errors when I set the nodeType equal to the '?' or 'Q.' using the condition:

char nodeType = 'Q' ?; result_if_true : result_if_false;


Can you even set a variable to a condition?
Was This Post Helpful? 0
  • +
  • -

#32 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 04:28 PM

What is your result if true/false? Its 'Q' and 'A'.
Was This Post Helpful? 0
  • +
  • -

#33 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 04:52 PM

char nodeType={ return('Q'=='A')?1:0;}
Is that almost right? I don't think I'm using the function right.
Was This Post Helpful? 0
  • +
  • -

#34 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 05:10 PM

I'm assuming you put the one and zero in there for true and false? We weren't looking for true or false we want the resultwhen true and false. We are writing our tree out with questions first so looking for Q (true) and if its false all thats left is A (false). root->ifYes points to our ifYes and if its not null then set with whats after ?.
char nodeType =  (root->ifYes != 0) ? 'Q' : 'A';
               //(   condition    ) ? 'result_if_true : result_if_false;



That should finish things up? I believe you have both read and write functions now.

This post has been edited by R2B Boondocks: 09 July 2013 - 05:11 PM

Was This Post Helpful? 0
  • +
  • -

#35 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 05:24 PM

My output still does not show the animal name. Instead I see a '(' where the animal name should go.
Was This Post Helpful? 0
  • +
  • -

#36 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 05:32 PM

Did you manipulate animal.cpp or node.h in anyway? Perhaps by mistake? You are compiling the program and then running it in cmd (windows) like so:
animal.exe file-name (where file name is say animal.dat)
Was This Post Helpful? 0
  • +
  • -

#37 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 05:47 PM

Ah. I was running the program from the compiler itself. Apparently c++ doesn't like that so I ran from the command prompt. Thanks alot R2B Boondocks!
Was This Post Helpful? 0
  • +
  • -

#38 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 05:52 PM

Not a problem I am glad to help whoever I can :)/>. Hopefully it all made sense to you I'm new to helping others in c++. The program did not work because you didn't specify a file name in the compile build. I'm assuming you're using code blocks. Somewhere in there is an option to add a data file. I think you do file new empty file? Then build it from there.

This post has been edited by R2B Boondocks: 09 July 2013 - 06:10 PM

Was This Post Helpful? 0
  • +
  • -

#39 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 06:22 PM

I spoke to soon. It isn't working anymore . It tries to guess the name of the animal and at the same time tries to ask a question. The text is combined together.
Was This Post Helpful? 0
  • +
  • -

#40 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 06:24 PM

How many submissions do you have left? What you have now should produce a grade of 100. Again, sure the other two files haven't changed?
Was This Post Helpful? 0
  • +
  • -

#41 lamentofking  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 167
  • Joined: 03-July 13

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 06:39 PM

My data file was corrupt. Back on line again! Thanks Boondocks.
Was This Post Helpful? 0
  • +
  • -

#42 R2B Boondocks  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 195
  • Joined: 19-September 12

Re: Read and Write to input file using trees in C++?

Posted 09 July 2013 - 07:08 PM

Excellent news and no problem
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3