need C++ programming code in visual studio
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: need C++ programming code in visual studio

  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Post 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.

  2. #2
    Join Date
    Feb 2014
    Posts
    2

    Re: need C++ programming code in visual studio

    i need solution for problem 1.19.9 friends. please help me

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    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.

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,316

    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 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.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,220

    Re: need C++ programming code in visual studio

    Quote Originally Posted by sam.v View Post
    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.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,827

    Re: need C++ programming code in visual studio

    Quote Originally Posted by Arjay View Post
    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.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,353

    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

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,827

    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 12:24 PM.

  9. #9
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,316

    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 09:00 AM.
    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.

  10. #10
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,827

    Re: need C++ programming code in visual studio

    Quote Originally Posted by 2kaud View Post
    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.

  11. #11
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,316

    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.

  12. #12
    Join Date
    Apr 1999
    Posts
    27,424

    Re: need C++ programming code in visual studio

    Quote Originally Posted by OReubens View Post
    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

  13. #13
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,316

    Re: need C++ programming code in visual studio

    Quote Originally Posted by Paul McKenzie View Post
    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #14
    Join Date
    Apr 1999
    Posts
    27,424

    Re: need C++ programming code in visual studio

    Quote Originally Posted by 2kaud View Post
    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

  15. #15
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,827

    Re: need C++ programming code in visual studio

    Quote Originally Posted by 2kaud View Post
    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center