Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C Read ptr-func.c. Once you understand what it is doing, create a new file calc.c which implements a simple calculator. The calculator will perform

in C

Read ptr-func.c. Once you understand what it is doing, create a new file calc.c which implements a simple calculator. The calculator will perform the four basic arithmetic operations +, -, * and /. The program should prompt the user for the operation to perform in an endless loop. For example:

calc > 3 + 6 9 calc > 

You must implement the calculator such that there is one calc function which takes as arguments the numerical values of the two operands and a pointer to the specified function (add for +, etc), plugs the two values into the referenced function, and returns the result.

Your program should work independent of spaces in the input. For instance, both 1+2 and 1 + 2 should work. This is actually very easy to do with scanf, check out its manual page!

 ptr.func.c #include  void myProc(int); void myCaller(void (*)(int), int); int main(void) { myProc(10); // call myProc with argument 10 myCaller(myProc, 10); // and do the same again ! return 0; } void myCaller(void (*f)(int), int param) { (*f)(param); /* call function *f with param */ } void myProc(int d) { /* do something with d */ printf("In myProc(). "); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

which of the following is true of class 4 lasers

Answered: 1 week ago

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago