3. Perform Operations (20 marks) Write a C program to implement calculator using pointers. You should...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. Perform Operations (20 marks) Write a C program to implement calculator using pointers. You should ask the user two operands and what kind of arithmetic operation the user wants to run on them. This shouldn't be just a onetime operation, the user should be able to input the operands and the kind of operation which it wants to be performed on them as long as he wants to. Users may enter 'Q' to quit the program. You need to write separate function for all the operations (+,-, *, /). In these functions you need to pass the variables as pointers and then perform the requested operation and return the result. To calculate the result, you should not use a third variable. For example: Consider the function int sum(int *a, int *b); Here, the addition of two numbers must be stored in 'a' and returned. Implementation Details: */ Function: addition, subtraction, multiplication, division Perform operations on two integers using pointers. Parameters: a: Pointer to the first integer. b: Pointer to the second integer. Returns: void void addition(int *a, int*b); void subtraction(int *a, int*b); void division (int *a, int*b); void multiplication (int *a, int*b); Sample run: Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): + Enter the operands for this operation : 78 Addition of 7 and 8 = 15 Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): - Enter the operands for this operation: 109 9 Subtraction of 109 and 9 = 100 Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): Q Goodbye! 3. Perform Operations (20 marks) Write a C program to implement calculator using pointers. You should ask the user two operands and what kind of arithmetic operation the user wants to run on them. This shouldn't be just a onetime operation, the user should be able to input the operands and the kind of operation which it wants to be performed on them as long as he wants to. Users may enter 'Q' to quit the program. You need to write separate function for all the operations (+,-, *, /). In these functions you need to pass the variables as pointers and then perform the requested operation and return the result. To calculate the result, you should not use a third variable. For example: Consider the function int sum(int *a, int *b); Here, the addition of two numbers must be stored in 'a' and returned. Implementation Details: */ Function: addition, subtraction, multiplication, division Perform operations on two integers using pointers. Parameters: a: Pointer to the first integer. b: Pointer to the second integer. Returns: void void addition(int *a, int*b); void subtraction(int *a, int*b); void division (int *a, int*b); void multiplication (int *a, int*b); Sample run: Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): + Enter the operands for this operation : 78 Addition of 7 and 8 = 15 Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): - Enter the operands for this operation: 109 9 Subtraction of 109 and 9 = 100 Enter the operation you want to perform('+' for Addition,'-' for Subtraction,'*' for Multiplication, '/' for Division, Q to quit): Q Goodbye!
Expert Answer:
Answer rating: 100% (QA)
Here is a C program that implements a calculator using pointers for addition subtraction multiplicat... View the full answer
Related Book For
Systems Analysis And Design
ISBN: 978-1119496489
7th Edition
Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth
Posted Date:
Students also viewed these programming questions
-
Think about the content and topics from each week, and compose an answer to this simple question: Why did I ask you to watch the Ted Talk video (How I Hacked Online Dating)and what does it have to...
-
Explain why individuals should have investment goals, and describe the associated risks and returns for at least two types of investments. Additionally, identify the different types of asset classes...
-
You will design and implement your own data class. The class will store data that has been read as user input from the keyboard (see Getting Input below), and provide necessary operations. As the...
-
TRUE OR FALSE. 6 POINTS EACH. (Always assume "Other things equal.") 1. In economics in the short run, a firm will have both fixed and variable resources. 2. In economics, the short run is defined as...
-
The spectrum of a star is used to measure its radial velocity with respect to the Sun, the component of the star's velocity vector that is parallel to a vector connecting the star's centre to the...
-
Revco Corporation purchases 40 percent of the voting stock of Ronco Pharmaceuticals on January 1,2013, for $5 million in cash. Ron-co's book value at the date of acquisition is $6 million....
-
As shown in Fig. P9.53a, a kayak is a relatively streamlined object. As a first approximation in calculating the drag on a kayak, assume that the kayak acts as if it were a smooth, flat plate \(17...
-
Baker, Inc., supplies wheels for a large bicycle manufacturing company. The bicycle company has recently requested that Baker decrease its delivery time. Baker made a commitment to reduce the lead...
-
A jack-in-the-box (k = 100 N/m) is compressed a distance of 0.10 m into the box. What is the maximum speed that the head (m = 0.3 kg) will reach as it flies out toward a frightened child? At what...
-
You have recently started work as a management accountant at Zilber Hotels, reporting to the financial controller. Draft management accounts have been prepared for the year just finished, and the...
-
Why there are different civil statuses for filing taxes, should one be eliminated or are they all important according to the IRS tax code?
-
Explain four strategies that can be used by staff to minimise risks associated with grief and bereavement support
-
Discuss how HR practices guide a company to meet its social responsibility strategy. Explain the responsibility of HR leadership in relation to establishing and adhering to ethical policies and...
-
Explain the advantages and disadvantages of filling positions with (1) internal candidates and (2) external candidates. Which type of candidate typically performs best?
-
Explain what is going on, who is involved and what is the significance of the passage: "That, or a phantom spirit send you into raptures
-
A block of mass 1 . 3 6 1 . 3 6 kg sliding with a constant velocity of 4 . 9 3 4 . 9 3 m / / s to the north, which collides 1 0 0 % 1 0 0 % elastically with a second, stationary block, of mass 3 . 1...
-
This question has multiple parts. Work all the parts to get the most points. For the reaction below: Br a Predict the product(s). C 1. Mg 2. CO2 3. H3O+ P [1]* ?
-
What is your opinion of advertising awards, such as the Cannes Lions, that are based solely on creativity? If you were a marketer looking for an agency, would you take these creative awards into...
-
How would you improve the form in Figure 9-4? Price $8 4 Figure 9-4 MC 4 56 3 Quantity (in Millions) ATC AVC
-
Describe the types of operational requirements and how they may influence architecture design.
-
What are the key elements of the system proposal?
-
See the option quote on IBM from the CBOE Web site on the next page showing options expiring in March and April 2022. a. Which option contract had the most trades that day? b. Which option contract...
-
You are an options dealer who deals in non-publicly traded options. One of your clients wants to purchase a one-year European call option on HAL Computer Systems stock with a strike price of \($20.\)...
-
It is February 21, 2022, and you have decided to purchase 10 June call contracts on eBays stock with an exercise price of \($57.50.\) Because you are buying, you must pay the ask price. How much...
Study smarter with the SolutionInn App