Question: If you DO use nested if/else statements, though, be sure that you indent and format your code appropriately. Follow the pattern in min2 and min3v1/min3v2





If you DO use nested if/else statements, though, be sure that you indent and format your code appropriately. Follow the pattern in min2 and min3v1/min3v2 in terms of all other issues and how they are handled, including the usage message, etc. Your program should look exactly like these except that it works on 4 inputs (note, there are no trailing whitespacse): /min4 Usage: ./min4 num1 num2 num3 num4 Prints smallest of the four numbers Here is the output of the program with the correct number of inputs: $ ./min4 3456 Here are two more example runs $ ./min4 92 35 12 17 12 $ ./min4 92 -35 12 17 -35 To compile your code use the g++ command as before $g++-std-c++11-o min4 min4.cpp Run your executable with different inputs to test it out. Upload your files to your repo on github using github's web interface. Calculate the minimum of 4 numbers Switch roles with your partner. In this part of the lab you will write a program that compares 4 input numbers and prints out the smallest one. You should not use the min() function in C++ algorithm library or any other outside function that performs the minimum operation for you. Instead, you should base the program on the example programs provided to you that compare fewer inputs Start by examining the given examples, also described below: min2.cpp This program takes two command-line arguments, and converts them to integers. It then calls a function, smallest_of two, that returns the smallest of the two numbers (or the value they share in case of a tie.) It then prints out the result of that function cal min3v1.cpp This is the first of two versions of a program that takes min2.cpp one step further, finding the smallest value from among three numbers. Again, if there is a tie, it prints the tie value. Look at the nested if/else statements and see if you can make sense of the logic. Seek help if you don't. min3v2.cpp This program does EXACTLY the same thing as min3v1.cpp, but does it with much cleaner, simpler code. Notice how we REUSE the smallest_ of two function to build up a smallest_of_three function. Your job in this step is to test min2, min3v1 and min3v2 with many different values and convince yourself that they work properly. In the next step, you will be taking these programs to the next logical step in this sequence Your main task: Write min4.cpp Write a program that works just like min2 and min3v1 and min3v2, except it takes four ints on the command line, and prints the smallest value, handling ties appropriately We encourage you to follow the model of min3v2.cpp if you can understand how this works, since your code will be far cleaner than trying to build this out of nested if/else statements #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
