Question

As we continue with our study of programming fundamentals, here is a short extra credit programming...

As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the median of three input numbers. The median is the middle number when the three numbers are arranged in order by size. However, the user can input the values in any order, so your program must determine which value is between the other two. For example, given an appropriate prompt, if the user enters three "unique" real numbers here is a sample of the console program output... Sample screen output 1 using Code:Blocks: Please enter three numbers: 41.52 27.18 96.03 The median of 41.52, 27.18, and 96.03 is 41.52. Process returned 0 (0x0) execution time : 10.082 s Press any key to continue. 10 points possible if you have the above portion of the program working showing the correct median number given three real number input values. Once you have the three-number case working, extend the program to handle five numbers. An additional 5 extra credit points will be provided if you are able to show the correct median number given five real number input values. Note: You may develop and implement your algorithm incrementally (i.e., with three numbers input and then the remaining two numbers) or choose to write your algorithm based on five input numbers. Input Validation: No input validation is required for this program. Assumption is that the numbers input are real numbers and unique. Be sure to use proper program formatting and appropriate prompts to the user in your code. The output should be labeled clearly and formatted neatly. Save your completed algorithm (source code) by naming your file as follows: LastName_median.cpp. To submit use the file upload option to send your final version of this extra credit programming challenge. Make sure to also include your name and section number in the comment section of source code submitted. (HINT: Construct your algorithm using nested if/else statements with relational and/or logical expressions. I prefer that you not use arrays, vectors, lists or other sorting algorithms. ) OR A simple calculator Write an interactive program that performs as a very simple binary operations calculator. Your calculator should be able to handle the four basic math operations – add, subtract, multiply, and divide – on two input values. Your program should prompt the user to enter three arguments: two double values and a character to represent an operation. For example, if the entry arguments are 35.6, 24.1, and ‘+’, the program output should be “The sum of 35.6 and 24.1 is 59.7.” Provide specific prompts for user input that make it clear to the user how the values must be entered. Be sure to use proper program formatting and appropriate comments in your code. The output should be labeled clearly and formatted neatly. Save your completed algorithm (source code) by naming your file as follows: LastName_calculator.cpp. To submit use the file upload option to send your final version of this extra credit programming challenge. Make sure to also include your name and section number in the comment section of source code submitted. (HINT: Construct your algorithm using a switch statement)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Selected the calculator program : LastName_calculator.cpp

Program:

#include<iostream>

using namespace std;

int main()

{

double a,b; //two double variables

char c; //a character variable

cout<<"Input two numbers followed by the operation symbol"<<endl;

cout<<"\nFor addition use '+'"<<endl;

cout<<"For Subtraction use '-'"<<endl;

cout<<"For multiplication use '*'"<<endl;

cout<<"For division use '/'"<<endl;

cout<<"\nFor example, for addition of two numbers 35.6 and 24.1, the input format is : 35.6 24.1 +"<<endl; // Example for user input

cout<<"\nEnter: ";

cin>>a>>b>>c; //input from user

cout<<"\n";

switch(c) //using switch statement

{

case '+':

cout<<"The sum of "<<a<<" and "<<b<<" is :"<<a+b;

break;

case '-':

cout<<"The difference of "<<a<<" and "<<b<<" is :"<<a-b;

break;

case '*':

cout<<"The product of "<<a<<" and "<<b<<" is :"<<a*b;

break;

case '/':

cout<<"The quotient of "<<a<<" and "<<b<<" is :"<<a/b;

break;

default:

cout << "Error! operator is not correct"; // If the entered operator is other than +, -, * or / error message is shown.

break;

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
As we continue with our study of programming fundamentals, here is a short extra credit programming...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should...

    Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should meet the following requirements: 1. The program shall graphically prompt the user for a file. 2. The program shall read the selected file which will contain 1 integer per line. 3. The program shall sort the values it reads from the file from largest to smallest. 4. The program shall write the values to an output file from largest to smallest in the same...

  • In C++ Please work on the following short programming assignments and upload your solutions on a...

    In C++ Please work on the following short programming assignments and upload your solutions on a single .txt file. 1. Write a function to take two integers and return the maximum number. Then, in the main function, ask the user to enter 2 numbers and output the maximum using the function. 2. Write a program to input 5 integers and store them in an array. Then, show the array in the output. 3. Write a program to input 5 numbers...

  • C++ programming please Write a program that will display random numbers in order from low to...

    C++ programming please Write a program that will display random numbers in order from low to high. 1. Declare an integer array of size 100. Ask the user how many numbers to work with (n). It can be less than 100. 2. Generate random numbers from 10 to 50. 3. Write the random numbers to an output file named random.dat. Close the file. 4. Open random.dat for input and read the data values into your array. Pass your array to...

  • does anyone know how to do this? C++ Your task for this assignment is to use...

    does anyone know how to do this? C++ Your task for this assignment is to use C++ language to implement an insertion sort algorithm. 1. Implement an insertion sort with an array to sort 10 arbitrary numbers using the C++ programming language. The program initializes an array with 10 random 3-digit positive integers. The program then sorts the numbers in the array using the insertion sort algorithm. 2. The program displays the original values in the array before the sort...

  • Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a...

    Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns,...

  • Could anyone please help with this Python code assignment? In this programming assignment you are to...

    Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • Can you send the code and the screenshot of it running? 1) Create a PYHW2 document...

    Can you send the code and the screenshot of it running? 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both flowchart and pseudocode forms for the following two functions: A. Write a Python function that receives a real number argument representing the sales amount for videos rented so far this month The function asks the user for the number...

  • please read directions first. this is supposed to be a hybrid programe add comments please JAVA...

    please read directions first. this is supposed to be a hybrid programe add comments please JAVA please add comments Programming Project 1 and Programming Project 2 "Hybrid" Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT