Very Lost and Very need of help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 05l8kr
    New Member
    • Sep 2006
    • 35

    Very Lost and Very need of help

    I'm suppose to edit the function called swap_values so that it receives three numbers (not two nubmers) called first , second, and third. These numbers will not be in any special order (for example enter 20.0, 3.1 and 9.3). The function swap-values will need to be edited to use more "if" statements to place the smallest vlaue in the variable named first, the second smallest number in the variable named second, and the largest number in the variable named third.
    You are also to edit the cout statements to print all three nubmers in the correct order (the variable first will be printed first and have in it the smallest number, the variable second will be pritned next and will have the middle number in it and the variable third will be prited last and have the largest number in it). Than take the cout statements (that print the three numbers in order) and create another another function called print_inorder. This new function will print the numbers in order from smallest to largest.
    Code:
    # include <iostream.h> 
    // recall function definitions can be written either before or after the main 
    void swap_values (float &a, float &b) 
    { 
    float temp; 
    
    temp = a; 
    a = b; 
    b = temp; 
    } 
    
    void main (void) 
    { 
    
    void swap_values (float &, float &); //prototype 
    
    float first = 10000.0; 
    float second = 0.00001; 
    
    swap_values(first, secondl); // function call statement 
    
    cout << “Big contains “ << big << endl; 
    cout << “Small contains “ << small << endl; 
    } //end of code to swap two numbers
    At the top of the program insert comments that contain the assignment number, question number, and your name
    Edit the addThree function and change its name to useTwo.
    Edit the useTwo function accept only two float numbers
    Within the useTwo function add additional code to
    calculate the sum, product, quotient and subtraction value of the two floats entered.
    Return the 4 math answers calculated in the useTwo function to the main along with the two floats used to get the answers.
    Edit the printResults to receive 6 floats, the two numbers entered in the useTwo function the the 4 math answers calcualted in the useTwo fucntion. The printResults function should be edited to include the code to print all 6 numbers, formatted, and clearly labeled.
    Code:
    # include <iostream.h> 
    // recall function definitions can be written either before or after the main 
    void addThree (float &a, float &b, float &c, float &s) 
    { 
    cout<<”enter number 1: “; 
    cin>>a; 
    cout<<”enter number 2: “; 
    cin>>b; 
    cout<<”enter number 3: “; 
    cin>>c; 
    s = a + b + c; 
    } 
    
    void printResults (float a, float b, float c, float s) 
    { 
    cout<<”number 1 = “<<a<<endl; 
    cout<<”number 2 = “<<b<<endl; 
    cout<<”number 3 = “<<c<<endl; 
    cout<<”sum = “<<s<<endl; 
    } 
    
    void main (void) 
    { 
    
    void addThree (float &a, float &b, float &c, float &s) ; // prototype 
    void printResults (float a, float b, float c, float s); // prototype 
    
    float num1, num2, num3, sum; 
    
    addThree (num1, num2, num3, sum); // call statement 
    printResults(num1, num2, num3, sum);// call statement 
    } //End of Code
  • 05l8kr
    New Member
    • Sep 2006
    • 35

    #2
    Any help please

    Comment

    • sivadhas2006
      New Member
      • Nov 2006
      • 142

      #3
      Hi,

      You want to create print_inorder function to print the values from smaller to bigger right?

      Regards,
      M.Sivadhas.

      Comment

      • vimase
        New Member
        • Oct 2006
        • 5

        #4
        can u be more specific as to what you want to do?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by karlracki
          I'm suppose to edit the function called swap_values so that it receives three numbers (not two nubmers) called first , second, and third. These numbers will not be in any special order (for example enter 20.0, 3.1 and 9.3). The function swap-values will need to be edited to use more "if" statements to place the smallest vlaue in the variable named first, the second smallest number in the variable named second, and the largest number in the variable named third.
          So there are basically 2 things to do

          1. Alter the prototype of swap_values. Can you do this re-wrte swap_values prototype to accept 3 parameters?

          2. Change the logic that it implements.

          As an initial step to altering the logic it may be worth writing down (in English) the new logic that this function will implement. Once you you have an idea of the logic it needs to implement then you can actually have an attempt at implementing it.

          Comment

          • seforo
            New Member
            • Nov 2006
            • 60

            #6
            For sure this is what you want
            #include <iostream>
            using namespace std;

            void swap_values(flo at & first, float & second, float &third)
            {
            float first_holder,se cond_holder,thi rd_holder;
            if(first > second && first > third)
            {
            third_holder = third;
            first_holder = first;
            third = first;
            if(third_holder < second)
            first = third_holder;
            else
            {
            first = second;
            second = third_holder;
            }
            }
            else if(second > first && second > third)
            {
            third_holder = third;
            second_holder = second;
            third = second;
            if(first < third_holder)
            second = third_holder;
            else
            {
            second = first;
            first = third_holder;
            }
            }
            else
            {
            if(first > second)
            {
            first_holder = first;
            second_holder = second;
            first = second_holder;
            second = first_holder;
            }
            }
            }
            void print_inorder(f loat first, float second, float third)
            {
            cout<<"The first number is "<<first<<e ndl;
            cout<<"The second number is "<<second<<endl ;
            cout<<"The third number is "<<third<<e ndl;
            }
            int main()
            {
            float first,second,th ird;
            cout<<"Enter the first number ";
            cin>>first;
            cout<<"Enter the second number ";
            cin>>second;
            cout<<"Enter the third number ";
            cin>>third;
            swap_values(fir st,second,third );
            print_inorder(f irst,second,thi rd);
            return 0 ;
            }

            Comment

            • 05l8kr
              New Member
              • Sep 2006
              • 35

              #7
              Originally posted by seforo
              For sure this is what you want
              #include <iostream>
              using namespace std;

              void swap_values(flo at & first, float & second, float &third)
              {
              float first_holder,se cond_holder,thi rd_holder;
              if(first > second && first > third)
              {
              third_holder = third;
              first_holder = first;
              third = first;
              if(third_holder < second)
              first = third_holder;
              else
              {
              first = second;
              second = third_holder;
              }
              }
              else if(second > first && second > third)
              {
              third_holder = third;
              second_holder = second;
              third = second;
              if(first < third_holder)
              second = third_holder;
              else
              {
              second = first;
              first = third_holder;
              }
              }
              else
              {
              if(first > second)
              {
              first_holder = first;
              second_holder = second;
              first = second_holder;
              second = first_holder;
              }
              }
              }
              void print_inorder(f loat first, float second, float third)
              {
              cout<<"The first number is "<<first<<e ndl;
              cout<<"The second number is "<<second<<endl ;
              cout<<"The third number is "<<third<<e ndl;
              }
              int main()
              {
              float first,second,th ird;
              cout<<"Enter the first number ";
              cin>>first;
              cout<<"Enter the second number ";
              cin>>second;
              cout<<"Enter the third number ";
              cin>>third;
              swap_values(fir st,second,third );
              print_inorder(f irst,second,thi rd);
              return 0 ;
              }
              There should be two different codes

              Comment

              Working...