Realising how simple something is after you've seen the answer.

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 2038 Views - Last Post: 09 December 2014 - 01:30 PM

#1 The Chief  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 12-November 14

Realising how simple something is after you've seen the answer.

Posted 22 November 2014 - 09:08 AM

I'm starting to feel really disheartened with programming at the moment. I've reach the stage in my book where I simply can't do the tasks I'm being given because I just can't think how to code it. It's only after I look on the next page and see the code that I feel like slapping myself because it was so simple.

Take a look at this. The book told me to create a dictionary look-up program and supplied me with the following code.

#include<iostream>
#include<cstring>

using namespace std;

int main(){

	char *dict[][2] = {
		"pencil", "A writing instrument.",
		"keyboard", "An input device",
		"rifle", "A large firearm",
		"airplane", "A fixed wing aircraft",
		"network", "An interconnected group of computers",
		"", ""
	};

        /*Complete the program using pointers.*/

}



I tried for about 30 minutes but just couldn't think for the life of my how to do the for loop. So I looked on the next page and here is the answer.

#include<iostream>
#include<cstring>

using namespace std;

int main(){

	char *dict[][2] = {
		"pencil", "A writing instrument.",
		"keyboard", "An input devide",
		"rifle", "A large firearm",
		"airplane", "A fixed wing aircraft",
		"network", "An interconnected group of computers",
		"", ""
	};

	char word[80];
	int i;

	cout << "Enter word: ";
	cin >> word;

	for (i = 0; *dict[i][0]; i++){
		if (!strcmp(dict[i][0], word)){
			cout << dict[i][1] << "\n";
			break;
		}
	}

	if (!*dict[i][0]) cout << word << " not found.\n";
	return 0;
}



Now I can see the loop it makes perfect sense and I can't believe I couldn't figure it out :dontgetit: I was just wondering if this is normal and it's just a matter of practice? The problem is I forget the structure of code all the time.

Anyone else used to have this problem? Trying not to let it get to me but it's so annoying... maybe I should read through the chapter a few more times.

Is This A Good Question/Topic? 0
  • +

Replies To: Realising how simple something is after you've seen the answer.

#2 Xaos  Icon User is offline

  • D.I.C Regular

Reputation: 80
  • View blog
  • Posts: 403
  • Joined: 20-November 13

Re: Realising how simple something is after you've seen the answer.

Posted 22 November 2014 - 09:15 AM

I think it helps some people to get some simple code, solutions to things like a rock-paper-scissors game, etc. and just go through and look at everything, see how they did it. Do that for alot of different small programs and then go through and try to make something of your own.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Realising how simple something is after you've seen the answer.

Posted 22 November 2014 - 09:33 AM

Take a break. Clear your head. There are several times when I cannot figure out the logic or code that I need that I go out and get some air ( I never said clean air ). You are so focused on the tree you can't see the forest right now.
Was This Post Helpful? 1
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6504
  • View blog
  • Posts: 14,355
  • Joined: 02-June 10

Re: Realising how simple something is after you've seen the answer.

Posted 23 November 2014 - 12:52 PM

Try doing the old fashioned way: Draw out the logic. Make a flow chart.


 {loop}
   |
   ^
  / \   No
 < ? >----  [Do this]
  \ /
   V
   |
   | Yes
   |
 [Do this]


Once you understand what it is your code needs to accomplish down to the smallest grain THEN worry about what line(s) of code are used for each figure in the diagram.
Was This Post Helpful? 1
  • +
  • -

#5 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Realising how simple something is after you've seen the answer.

Posted 23 November 2014 - 12:59 PM

Along the same lines. I have a client that was unsure of what they wanted. It wasn't until we forced them to flowchart the flow of the program that we actually accomplished anything. They were so busy brainstorming that they couldn't focus on the task at hand.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon

Reputation: 5296
  • View blog
  • Posts: 16,508
  • Joined: 25-December 09

Re: Realising how simple something is after you've seen the answer.

Posted 23 November 2014 - 01:07 PM

You may also want to find another book. That book may not be the best book to use to learn the language in question. IMO since this is a C++ book using a three dimensional array for this problem is really questionable. Also when the question stated /*Complete the program using pointers.*/ I wasn't expecting to see the array notation. I would have also expected to see the use of a class or structure to make this problem much simpler.

By the way, can you tell us the name and author of that book?


Jim
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6504
  • View blog
  • Posts: 14,355
  • Joined: 02-June 10

Re: Realising how simple something is after you've seen the answer.

Posted 23 November 2014 - 01:09 PM

View Postastonecipher, on 23 November 2014 - 01:59 PM, said:

Along the same lines. I have a client that was unsure of what they wanted. It wasn't until we forced them to flowchart the flow of the program that we actually accomplished anything. They were so busy brainstorming that they couldn't focus on the task at hand.


PluralSight has a really good video on getting requirements that would have helped in that situation.
Was This Post Helpful? 1
  • +
  • -

#8 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Realising how simple something is after you've seen the answer.

Posted 23 November 2014 - 01:16 PM

Definitely something I need to look into. Now that I am filling the role of project manager as well, there are several areas that I am lacking in.
Was This Post Helpful? 0
  • +
  • -

#9 The Chief  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 12-November 14

Re: Realising how simple something is after you've seen the answer.

Posted 24 November 2014 - 07:24 AM

View Postjimblumberg, on 23 November 2014 - 01:07 PM, said:

You may also want to find another book. That book may not be the best book to use to learn the language in question. IMO since this is a C++ book using a three dimensional array for this problem is really questionable. Also when the question stated /*Complete the program using pointers.*/ I wasn't expecting to see the array notation. I would have also expected to see the use of a class or structure to make this problem much simpler.

By the way, can you tell us the name and author of that book?


Jim


The booked is called A beginners guide to C++ (Herbert Schildt) I'm on chapter 5 now and chapter 5 is about functions. Classes isn't until chapter 8!

I really haTE the idea of keep trying different books, maybe I should just finish this book and then buy a new one?

This post has been edited by The Chief: 24 November 2014 - 07:29 AM

Was This Post Helpful? 0
  • +
  • -

#10 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2386
  • View blog
  • Posts: 5,008
  • Joined: 11-December 07

Re: Realising how simple something is after you've seen the answer.

Posted 24 November 2014 - 03:41 PM

I would take your reaction as quite encouraging. You see how simple the solution is and feel silly for not thinking of it yourself. That indicates to me that you understand it and I would bet you understand it well enough to apply the same principles in other situations.

The alternative is being confused by the solution, not seeing how it relates to the question or understanding some of it but not not being able to use it in other contexts.

One thing you could do that might be useful is to wait a few days and then go back and redo the question.
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon

Reputation: 5296
  • View blog
  • Posts: 16,508
  • Joined: 25-December 09

Re: Realising how simple something is after you've seen the answer.

Posted 25 November 2014 - 07:29 AM

Quote

The booked is called A beginners guide to C++ (Herbert Schildt) I'm on chapter 5 now and chapter 5 is about functions. Classes isn't until chapter 8!

I really haTE the idea of keep trying different books, maybe I should just finish this book and then buy a new one?


In this case I really recommend you find another book, by another author. This author doesn't have a reputation of producing stellar books. From the WIKI page for this author:

Quote

Reception

Schildt's books have a reputation for being written in a clear style, at least at first glance.[11] Their technical accuracy has been challenged by reviewers, including ISO C committee members Peter Seebach[2] and Clive Feather,[12] C FAQ author Steve Summit,[13] and numerous C Vu reviewers from the ACCU.[14]

Other reviewers have been more positive, with one ACCU reviewer saying about Schildt's C: The Complete Reference, Fourth Edition that Schildt "has learnt something, not enough to receive positive acclaim but enough to remove the 'positively detrimental' epithet".[15]


Again IMO using a three dimensional array early in a beginner's C++ book is a horrible idea.

Jim
Was This Post Helpful? 1
  • +
  • -

#12 The Chief  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 12-November 14

Re: Realising how simple something is after you've seen the answer.

Posted 25 November 2014 - 07:49 AM

mod: removed giant quote

Thanks Jim, could you recommend a more suitable book? The problem is with so many books out there it's almost impossible to decipher which is good and which is not.

Preferably one which is using C++11 because that is what my IDE is.

This post has been edited by modi123_1: 25 November 2014 - 07:57 AM
Reason for edit:: please do not quote the post above you.. it is fine to use the 'reply' button.

Was This Post Helpful? 0
  • +
  • -

#13 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13389
  • View blog
  • Posts: 53,429
  • Joined: 12-June 08

Re: Realising how simple something is after you've seen the answer.

Posted 25 November 2014 - 07:52 AM

It's not that hard with the advent of amazon. Plug in your topic. Find something relatively new with high ratings. Read some of the reviews.. eyeball the index.. compare with a few others.. make a choice. Alternatively find a library and start combing there. (I think someone did a blog post on how to pick a book, but I can't find it).

There is also the pinned thread in the C++ forum.
http://www.dreaminco...338-books-on-c/
Was This Post Helpful? 0
  • +
  • -

#14 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Realising how simple something is after you've seen the answer.

Posted 25 November 2014 - 07:55 AM

If you are a student, the University library is fun. I used to browse thousands of books on programming languages used over the last 40 years.

Admittedly I do not use C++ at all anymore, but I have an older version of this book when I was messing with it http://www.mypearson...s-9780132162739
Was This Post Helpful? 0
  • +
  • -

#15 The Chief  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 12-November 14

Re: Realising how simple something is after you've seen the answer.

Posted 25 November 2014 - 08:07 AM

View Postmodi123_1, on 25 November 2014 - 07:52 AM, said:

It's not that hard with the advent of amazon. Plug in your topic. Find something relatively new with high ratings. Read some of the reviews.. eyeball the index.. compare with a few others.. make a choice. Alternatively find a library and start combing there. (I think someone did a blog post on how to pick a book, but I can't find it).

There is also the pinned thread in the C++ forum.
http://www.dreaminco...338-books-on-c/


That is exactly what I did with this book. It had high reviews, it was new and people recommended it as a decent book. I'm not a student so I don't have access to a decent library.

This post has been edited by The Chief: 25 November 2014 - 08:08 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2