If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

need C++ programming code in visual studio

hi

being new to this forum, am new to c++ programming and my professor giving tough homework .
guy's need your help.r

our assigment is:

Repeat the problem collatz conjecture, 1.19.3, in a new direc-tory collatz1. Now your collatz procedure should compute the collatz sequence and store the results in an array. Write another procedure that takes the com-puted array and prints the collatz sequence. email collatz.h, collatz.cpp and collatztest.cpp. Also include screen shot of the program output as a pdf file.

Re: need C++ programming code in visual studio

Given the requirment for 1.19.9, how would you go about it without writing a program? What detailed steps would you take? Then produce an algorithm for this and a program design in English (or other natural language) that says how the requirements are to be met. Then from the program design code the program and then test/debug.

Code:

do {
algorithm
design
code
test
debug
} while program not correct

If you still have problems when you have produced some code, if you post the code here then we'll provide further guidance. As a hint for the algorithm, consider the number of '#'s displayed for each row number.

I note that there is a hint to use a goto statement when only using an if statement. You should be aware that use of a goto statement is not considered good practice and should only be used when not specifically mandated in exceptional circumstances.

Last edited by 2kaud; February 9th, 2014 at 03:03 PM.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: need C++ programming code in visual studio

The 'goto' solution.
Give this to your instructor with my regards. Then tell him to never ever mention 'goto' to beginners again. If he must mention it, then certainly don't make exercises with it. In nearly 30 years of C++ programming I have needed to use goto a single once where it was warranted. Don't waste student time with this.

Re: need C++ programming code in visual studio

Originally Posted by 2kaud

Aw shucks spoilsport - and I was having so much funnnnn!

Just something I threw together in a hurry.
I wanted to stuff as much "bad" stuff in there as I could without making it needlessly bigger (templates and lambda fun !).
I.m.o. if they get to something like "goto", then they should have technically seen all the stuff I'm using.
my "lint" tool went nuts on this snippet, 54 messages.

Nevertheless. If you want some fun:
1) Obviously... can you figure out why it works ?
2) Find the bit of code that's there that doesn't really do anything.

Re: need C++ programming code in visual studio

Code:

int l(l);

Now that's what I call real sneaky where l is already defined in outer block!

Code:

0 & ')'

just gives 0 of course. Nice way just to decrement l as part of an expression! And the if fails of course when l is -1. You even got an octal comparison on the first if just for a change which only fails when all the required rows have been output.

Last edited by 2kaud; February 11th, 2014 at 03:33 PM.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: need C++ programming code in visual studio

Originally Posted by OReubens

Give this to your instructor with my regards.

Funny.

I usually reserve the obfuscated answers for those new posters that demand an answer to their homework problem. I don't know if I can dig it up again from the CodeGuru archives, but the question I answered was similar to the OP's question. However the OP in my case was very belligerent (at least his words were).

Re: need C++ programming code in visual studio

Originally Posted by Paul McKenzie

I usually reserve the obfuscated answers for those new posters that demand an answer to their homework problem. I don't know if I can dig it up again from the CodeGuru archives, but the question I answered was similar to the OP's question. However the OP in my case was very belligerent (at least his words were).

Paul, are you referring to this outstanding example of c programming clarity?

Re: need C++ programming code in visual studio

Originally Posted by 2kaud

Paul, are you referring to this outstanding example of c programming clarity?

Actually, my technique is to use variables like llll, lllll, llllll (all the letter l), calculations that seemed tricky but were really easy, throw in some ASCII characters that serve as loop counters, and of course, multiple statements per line with as little whitespace as possible.

Sometimes I give a somewhat clear example, but use some advanced aspect of C++ that in no way could the student have come up with the solution. If the student handed a program in like that to the teacher, then get ready for the sweat when the teacher asks them to explain their solution.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.