c++ help answers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jchimanzi
    New Member
    • Feb 2007
    • 20

    c++ help answers

    Could you please help with answers to the below questions. I am still learning c++ and would appreciate your help

    1. what is the difference between
    int value =2; int value =2;
    cout << ++ value <<endl; AND cout << value++ << endl;?


    2. What are magic numbers? Whay are they considered bad practise. How does c++ language encourage the programmer to avoid using magic numbers?

    3 Intergers are represented as sequence of bits. what is the correct order ( from largest to smallest) of relative sizes in bits of the interger typers


    a long >= char >=short >=int
    b long>= int >=short>=char
    c long >=int >=char>=short
    d long >=char >=int >=short

    4. how can one write a c++ programme which does the following

    a create a vector of size 1000 and have it store the values 0.1, 1.1, 2.1, 3.1,....999.1

    b trucate the vector to a size of 5

    c print out how many values the vector is storing

    d empty out the vector so that it stores no values


    5. rewrite the following code correcting all problems found

    void calculatevalues (const int &a, float *b, int &c)

    {
    d = 20.4;

    if (*a =0)

    *a += 1
    c = a +d;

    else

    b= c/d ;

    c= a- b +d;

    }

    Hint if a =4, b =0.0 and c=5 when this function is called, their values when this fucntion returns should be a=4, b=0.25 and c= 24.15

    6 a The string class in the standard c++ library is a template for any type character of character representation.

    write a function called copy which takes two parameters of the string type. The first parameter is the source string ( or the string to be copied) and the second parameter is the target string ( or the string that recieves the copy). This function need not return anything.

    One is not allowed to use the fuction strcpy (.....)!

    b) show how one would use (or call) your function by writting some c++ code to copy one string inro another.

    7 What are the guidelines or rules for c++ programmers using inline functions?
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. Are you ready for valuable expert assitance?
    Here it is; go to your teacher and work through these questions. If this is a test and you have to do this alone then you are too late. TheScripts is not a place to get your tests completed for you.

    Comment

    • jchimanzi
      New Member
      • Feb 2007
      • 20

      #3
      Originally posted by willakawill
      Hi. Are you ready for valuable expert assitance?
      Here it is; go to your teacher and work through these questions. If this is a test and you have to do this alone then you are too late. TheScripts is not a place to get your tests completed for you.
      SORRY I AM STUDYING C++ ON MY OWN AND THESE ARE SOME OF THE PRACTICAL QUESTIONS AT THE END OF THE MODULE. THE EXAM WILL BE THERE IN DECEMBER. I HAVE TO PRACTISE AS I PROCEED WITH THE STUDIES

      Comment

      • nickyeng
        Contributor
        • Nov 2006
        • 252

        #4
        for your question number 1:
        Code:
        int value = 2;
        
        cout << ++value << endl;
        will output the value as 3.

        Code:
        int value = 2;
        
        cout << value++ << endl;
        would output the value as 2. after output, the value become 3.

        do you get what i mean?
        correct me if i'm wrong. cos i'm new to c++ too.
        haha..

        I noticed that you have many question that are un-answer. Why dont you give a search on google and then if still no find any, ask the seniors here.
        Go through your module notes, and then see if these question's answer you might find it on module notes.

        from Nicky Eng

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          The experts on this site are more than happy to help you with your problems but they cannot do your assignment for you. Attempt the assignment yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

          So break the assignment down into sections. Attempt it yourself first. Then ask questions. Make sure you state that you are doing distance learning and don't have access to a tutor to ask questions of. The experts will help you they just won't do your assignment for you.

          Mary

          Comment

          • jchimanzi
            New Member
            • Feb 2007
            • 20

            #6
            Originally posted by mmccarthy
            The experts on this site are more than happy to help you with your problems but they cannot do your assignment for you. Attempt the assignment yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

            So break the assignment down into sections. Attempt it yourself first. Then ask questions. Make sure you state that you are doing distance learning and don't have access to a tutor to ask questions of. The experts will help you they just won't do your assignment for you.

            Mary
            Thanks for the advice maybe lets only do the following

            5. rewrite the following code correcting all problems found

            void calculatevalues (const int &a, float *b, int &c)

            {
            d = 20.4;

            if (*a =0)

            *a += 1
            c = a +d;

            else

            b= c/d ;

            c= a- b +d;

            }

            Hint if a =4, b =0.0 and c=5 when this function is called, their values when this fucntion returns should be a=4, b=0.25 and c= 24.15

            6 a The string class in the standard c++ library is a template for any type character of character representation.

            write a function called copy which takes two parameters of the string type. The first parameter is the source string ( or the string to be copied) and the second parameter is the target string ( or the string that recieves the copy). This function need not return anything.

            One is not allowed to use the fuction strcpy (.....)!

            b) show how one would use (or call) your function by writting some c++ code to copy one string inro another

            Comment

            • jchimanzi
              New Member
              • Feb 2007
              • 20

              #7
              Originally posted by nickyeng
              for your question number 1:
              Code:
              int value = 2;
              
              cout << ++value << endl;
              will output the value as 3.

              Code:
              int value = 2;
              
              cout << value++ << endl;
              would output the value as 2. after output, the value become 3.

              do you get what i mean?
              correct me if i'm wrong. cos i'm new to c++ too.
              haha..

              I noticed that you have many question that are un-answer. Why dont you give a search on google and then if still no find any, ask the seniors here.
              Go through your module notes, and then see if these question's answer you might find it on module notes.

              from Nicky Eng
              Thanks a lot for your advice may be lets only do the following


              5. rewrite the following code correcting all problems found

              void calculatevalues (const int &a, float *b, int &c)

              {
              d = 20.4;

              if (*a =0)

              *a += 1
              c = a +d;

              else

              b= c/d ;

              c= a- b +d;

              }

              Hint if a =4, b =0.0 and c=5 when this function is called, their values when this fucntion returns should be a=4, b=0.25 and c= 24.15

              6 a The string class in the standard c++ library is a template for any type character of character representation.

              write a function called copy which takes two parameters of the string type. The first parameter is the source string ( or the string to be copied) and the second parameter is the target string ( or the string that recieves the copy). This function need not return anything.

              One is not allowed to use the fuction strcpy (.....)!

              b) show how one would use (or call) your function by writting some c++ code to copy one string inro another

              Comment

              • jchimanzi
                New Member
                • Feb 2007
                • 20

                #8
                Originally posted by mmccarthy
                The experts on this site are more than happy to help you with your problems but they cannot do your assignment for you. Attempt the assignment yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

                So break the assignment down into sections. Attempt it yourself first. Then ask questions. Make sure you state that you are doing distance learning and don't have access to a tutor to ask questions of. The experts will help you they just won't do your assignment for you.

                Mary
                May i post the answers that i had attempted for the questions and maybe you could help me to check if they are correct

                Comment

                Working...