-
February 9th, 2014, 02:35 PM
#1
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.
Problem 1.19.9. Write a class called funnychar that outputs the following figure:
#
##
###
####
#####
######
#######
########
#########
##########
Use only for statements. You can use only
count < < '#'; as aprint statement
Use only while statements
Use only do while statements
Use only if statement and cannot have any loop statements like for, while and do while. Hint: Use goto statement.
-
February 9th, 2014, 02:39 PM
#2
Re: need C++ programming code in visual studio
i need solution for problem 1.19.9 friends. please help me
-
February 9th, 2014, 03:10 PM
#3
Re: need C++ programming code in visual studio
Then you should probably get started on it. If you get stuck somewhere, let us know how we can help.
-
February 9th, 2014, 03:33 PM
#4
Re: need C++ programming code in visual studio
No one here is going to write the program for you as this is a homework assignment. Please see
http://forums.codeguru.com/showthrea...ork-assignment
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 04:03 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 10th, 2014, 12:51 AM
#5
Re: need C++ programming code in visual studio
Originally Posted by sam.v
Use only if statement and cannot have any loop statements like for, while and do while. Hint: Use goto statement.
Hopefully, the instructor follows that 'lesson' up with now that you know about goto, here's why you shouldn't use it.
-
February 10th, 2014, 08:39 AM
#6
Re: need C++ programming code in visual studio
Originally Posted by Arjay
Hopefully, the instructor follows that 'lesson' up with now that you know about goto, here's why you shouldn't use it.
Hopefully the instructor gets fired and replaced by an instructor that doesn't even make mention that goto exists.
I mean, seriously ? goto in a language that's OO ?
Even for C that isn't even OO, goto is a construct that doesn't deserve a place in the manuals of beginners.
-
February 10th, 2014, 09:05 AM
#7
Re: need C++ programming code in visual studio
I agree with OReubens: goto is just an artifact of the Basic and earlier Fortran era.
goto should be avoided in every modern programming language, no matter if it is OO-language or not.
Also see http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
Victor Nijegorodov
-
February 11th, 2014, 09:00 AM
#8
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.
Code:
#include <iostream>
int main()
{
int l(0);
there:
if (++l-013) 0; else goto elsewhere;
{
int l(l);
here:
std::cout << char('#'^((--l>>8)&')'));
if (-1-l) goto here; else goto there;
}
elsewhere:
return 0;
}
P.S. This is how NOT to code in C++.
Last edited by OReubens; February 11th, 2014 at 01:24 PM.
-
February 11th, 2014, 09:32 AM
#9
Re: need C++ programming code in visual studio
This is how NOT to code in C++.
Aw shucks spoilsport - and I was having so much funnnnn!
Last edited by 2kaud; February 11th, 2014 at 10:00 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 11th, 2014, 01:21 PM
#10
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.
-
February 11th, 2014, 03:16 PM
#11
Re: need C++ programming code in visual studio
Now that's what I call real sneaky where l is already defined in outer block!
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 04:33 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 11th, 2014, 04:25 PM
#12
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).
Regards,
Paul McKenzie
-
February 11th, 2014, 04:41 PM
#13
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?
Code:
for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 11th, 2014, 08:38 PM
#14
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.
Regards,
Paul McKenzie
-
February 12th, 2014, 07:29 AM
#15
Re: need C++ programming code in visual studio
Originally Posted by 2kaud
Code:
for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);
But... but... This doesn't use goto's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|