Question

4 tunction calculator 1. fett function calculator (num op num) ? The coding language should be written in scheme and please i

In the coding language scheme, please including a comment what the program is doing and random output of n for executions.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
//A c++ program to depict the calculator functioning using any four 
//operators and two operands given by the user.
# include <iostream>
//provides basic input and output services for C++ programs. 
//iostream uses the objects cin , cout , cerr , and clog for sending data to and from 
//the standard streams input, output, error (unbuffered), and log (buffered) respectively
using namespace std;

float calculate(float num1, char op, float num2) //function defintion to calculate operands according to the chosen operator
{
    float answer;

    switch (op) {

        case '+':
            answer = num1 + num2;
            break;

        case '-':
            answer = num1 - num2;
            break;

        case '/':
            answer = num1 / num2;
            break;

        case '*':
            answer = num1 * num2;
            break;

        default:
            return(0);
    }

    cout <<"\t\tAnswer = "; return answer;
}

int main()
//the execution of program starts from the main function.
//int is describing the return type of the main function.
 {
    float num1;
    float num2;
    char op;
   
   cout << "Enter operator for following four operators:->" <<endl;
   cout<<"Addition-> +"<<endl;
   cout<<"Subtraction-> -"<<endl; 
   cout<<"Multiplication-> *"<<endl;
   cout<<"Division-> / "<<endl;
   cout<<"Your chosen operator:";//input for the operand
   cin >> op;

  cout << "Enter two operand: First operand: ";
  cin >> num1;//input for first number
  cout << "\t\tSecond operand: ";
  cin >> num2;//input for second number
  
    cout << calculate(num1, op, num2) << endl;//function call
return 0;
}
Add a comment
Know the answer?
Add Answer to:
In the coding language scheme, please including a comment what the program is doing and random...
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
  • Python 3.7.2 for language Please comment for each line of code good naming is important 1....

    Python 3.7.2 for language Please comment for each line of code good naming is important 1. Answer the question: what is the Python regular expression pattern that would match a hex color (https://en.wikipedia.org/wiki/Web_colors ) (for example, the pattern that would match an email address is '[\w.-]+@[\w.-]') Write an algorithm for step 3. As part of your algorithm, be sure to describe the pattern you're using to find the win/loss result for each game. Write a program that looks at the...

  • I need help with my C coding homework. If possible can you please comment to help...

    I need help with my C coding homework. If possible can you please comment to help me understand whats going on in the code. Thanks in advance. Create a C program (3 points): o At the top of the file include the following comments: Your name The purpose (core concept found below) of the program The date created o Create two int variables: Initialize each to different values. o Create three pointers: Point the first two pointers to the first...

  • Any programming language may be used. Please indicate what language you have chosen. You are an...

    Any programming language may be used. Please indicate what language you have chosen. You are an analytics developer, and you need to write the searching algorithm to find the element. Your program should perform the following: Implement the Binary Search function. Write a random number generator that creates 1,000 elements, and store them in the array. Write a random number generator that generates a single element called searched value. Pass the searched value and array into the Binary Search function....

  • Coding Challenge: Write ONLY IN SCALA LANGUAGE PLEASE DONT ANSWER IF YOU'RE ANSWERING WITH SOME OTHER...

    Coding Challenge: Write ONLY IN SCALA LANGUAGE PLEASE DONT ANSWER IF YOU'RE ANSWERING WITH SOME OTHER LANG BACKGROUND Sometimes items cannot be shipped to certain zip codes, and the rules for these restrictions are stored as a series of ranges of 5 digit codes. For example if the ranges are: [94133,94133] [94200,94299] [94600,94699] Then the item can be shipped to zip code 94199, 94300, and 65532, but cannot be shipped to 94133, 94650, 94230, 94600, or 94299. Any item might...

  • The program is written in c. How to implement the following code without using printf basically...

    The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...

  • Written in C++ language Write a program that keeps track of a telephone directory. The program...

    Written in C++ language Write a program that keeps track of a telephone directory. The program should create a structure, Person, with the following data: struct Person { string firstName; string lastName; string phoneNumber; }; The program should then create a vector of Person structs, called directory. Your program should have functions to: - Read the vector data from a data file “telephoneData.txt” into the vector directory. - Print the details of all Persons in the vector. You may use...

  • Problem: Design and write a C language program that can be used to calculate Voltage, Current...

    Problem: Design and write a C language program that can be used to calculate Voltage, Current and Total Resistance for a Series or Parallel or a Series Parallel circuit. The program should display the main menu that contains the three types of circuit calculations that are available and then the user will be prompted to select a circuit first. After the circuit has been selected the program should then display another menu (i.e., a submenu) requesting the necessary data for...

  • Design and implement a C Language program that measures the performance of given processors. There are...

    Design and implement a C Language program that measures the performance of given processors. There are several metrics that measure the performance of a processor. We will be using the following 3 measures: 1.CPI (clock cycles per instruction) = #clock cycles /#instructions 2.CPU execution time = #instructions x CPI x clock cycle time . cylce time = 1/CPU clock rate in hertz units 3.MIPS (mega instructions per second)= #instrucrions/ CPU X 1000000 Typically, processors’ performance is measured using a wide...

  • please write this program in C++(Linux). Also write all the explanation of codes, the comment for...

    please write this program in C++(Linux). Also write all the explanation of codes, the comment for your code. Description You are an avid reader and have decided that you would like to keep track of the books that you read. You will define a structure called book_list that will hold 1. a number associated with each book (int) 2. book title (string), 3. author (string), 4. a description of the book (string), 5. a date when the book was read...

  • c++ only. Please follow directions. What does the following program print and why? Comment each line...

    c++ only. Please follow directions. What does the following program print and why? Comment each line of code to explain what it is doing.   #include <iostream> using namespace std; int main() { int track[ ] = { 10, 20, 30, 40 }; int * ptr; ptr = track; track[1] += 30; cout << * ptr << " "; *ptr -= 10; ptr++; cout << * ptr << " "; ptr += 2; cout << * ptr << " "; cout...

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