Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming language. Create a calculator application with textual input. The calculator has 10 memory slots with identifiers from 0 to 9. You can read

C programming language.

Create a calculator application with textual input. The calculator has 10 memory slots with identifiers from 0 to 9. You can read integer numbers to the slots and you can perform arithmetic operations on them. All these operations are controlled textually. The initial value of the slots is 0. Let's take the following example:

read 10 1 read 20 3 read 30 7 add 1 2 9 mul 3 1 6 print 9 print 6

The meaning of these lines:

  • Read value 10 to slot #1.
  • Read value 20 to slot #3.
  • Read value 30 to slot #7.
  • Add the values of slots #1 and #2, and store the result in slot #9. This way the value of slot #9 will be 10.
  • Multiply the values of slots #3 and #1, and store the result in slot #6. This way the value of #6 will be 200.
  • Print the value of slot #9 which is 10.
  • Print the value of slot #6 which is 200.

You have to support the following operations as functions:

  • read (reading a value to a slot, 2 parameters: value and the number of slot)
  • print (printing a value of a slot, 1 parameter: the number of slot)
  • add, sub, mul, div (addition, subtraction, multiplication, integer division, 3 parameters: slots of two operands and slot of the result.

These functions are given the array of slots as parameter and that many further arguments as indicated above.

Create a functions for computing the sum and average of numbers which get the array of slots as a parameter.

Write a test code in the main program which performs some operations on some slots. Also test the sum and average functions.

Place the array of slots to the heap memory. Make sure that there is no memory leak in the program.

Place functions to a separate translation unit. Use the "include guard" idiom.

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

Step: 3

blur-text-image

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions