2010 - Homework #5
Functions
Write your programs in your 2010/5 folder on Odin.
Part-1 We started this program in class together. Name your program: 2010/5/order3.cpp Prompt the user for 3 numbers. After entry, display all 3 numbers in order from low to high. sample output...$ ./a.out Please enter 3 numbers: 6 14 3 Your numbers in-order are: 3 6 14Rules: No assignment operators are allowed in your program. No calls to swap are allowed. No math operators are allowed. There is no input validation. The output text must be just as shown in the sample. One space before each number. Code: Store the input numbers in 3 different variables. Use if-statements to arrange the numbers for output. Start with this code from class Wednesday. A small fix was made to the code from class. Test and adjust your own code. if (a <= b && a <= c && b <= c) { cout << a << " " << b << " " << c << endl; } else if (a <= b && a <= c && c <= b) { cout << a << " " << c << " " << b << endl; } Test with input like this: a b c - - - 2 3 4 <---- a is lowest 3 2 4 <---- b is lowest 3 4 2 <---- c is lowest 3 4 4 <---- a is lowest, but b & c are equal 4 3 3 <---- a is highest, but b & c are equal 4 4 2 <---- c is lowest, but a & b are equal For easier testing of your program, run it like this... This is called directed input.$ ./a.out <<< "3 4 2" Please enter 3 numbers: Your numbers in-order are: 2 3 4
For some extra credit... Make your order3 program get 3 numbers from the command-line. You can leave your cin statements in your program, but if there are 3 numbers on the command-line, then skip around your cin statements using an if-statement. This way, your program can get input in 3 different ways... cin, command-line, or directed input. sample run...$ ./a.out 3 4 2 Your numbers in-order are: 2 3 4Part-2 Finish your lab-5 programs.Part-3 Choose one program from the end of Chapter-6 in our textbook ------------------------------------------------------------ Name your program 2010/5/textbook.cpp Do not choose the ones with strike-out. No user input is required. For input, you should use random number generation. 1. Markup 2. Rectangle Area - Complete the Program 3. Winning Division 4. Safest Driving Area5. Falling Distance6. Kinetic Energy7. Celsius Temperature Table8. Coin Toss 9. Present Value 10. Future Value 11. Lowest Score Drop12. Star Search13. Days Out 14. Order Status 15. Overloaded Hospital 16. Population 17. Transient Population 18. Paint Job Estimator 19. Using Files-Hospital Report 20. Stock Profit 21. Multiple Stock Sales 22. isPrime() Function 23. Prime Number List 24. Rock, Paper, Scissors Game Your program must have... 1. Perfect code styling. 2. Consistent code indenting. 3. Functions written below the main() function. 4. Function prototypes above main(). 5. Beautiful output to the screen.