Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER IN C LANGUAGR main.c has already shown, please answer Calculator.h and Calculator.c Given main(), create the Calculator struct that emulates basic functions of

PLEASE ANSWER IN C LANGUAGR

main.c has already shown, please answer Calculator.h and Calculator.c

Given main(), create the Calculator struct that emulates basic functions of a calculator: add, subtract, multiple, divide, and clear. The struct has one data member called value for the calculator's current value.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedmain.c :

#include

#include "Calculator.h"

int main() { Calculator calc = InitCalculator(); double num1; double num2;

scanf("%lf", &num1); scanf("%lf", &num2);

// 1. The initial value printf("%.1lf ", GetValue(calc));

// 2. The value after adding num1 calc = Add(num1, calc); printf("%.1lf ", GetValue(calc));

// 3. The value after multiplying by 3 calc = Multiply(3, calc); printf("%.1lf ", GetValue(calc));

// 4. The value after subtracting num2 calc = Subtract(num2, calc); printf("%.1lf ", GetValue(calc));

// 5. The value after dividing by 2 calc = Divide(2, calc); printf("%.1lf ", GetValue(calc));

// 6. The value after calling the Clear() method calc = Clear(calc); printf("%.1lf ", GetValue(calc));

return 0; }

7.7 LAB 1-3: Calculator Given main(), create the Calculator struct that emulates basic functions of a calculator: add, subtract, multiple, divide, and clear. The struct has one data member called value for the calculator's current value. Implement the Calculator struct and related function declarations in Calculator.h, and implement the related function definitions in Calculator.c as listed below: - InitCalculator(Calculator c) - initialize the data member to 0.0 - Calculator Add(double val, Calculator c) - add the parameter to the data member - Calculator Subtract(double val, Calculator c) - subtract the parameter from the data member - Calculator Multiply(double val, Calculator c) - multiply the data member by the parameter - Calculator Divide(double val, Calculator c) - divide the data member by the parameter - Calculator Clear(Calculator c ) - set the data member to 0.0 - double GetValue(Calculator c) - return the data member Given two double input values num1 and num2, the program outputs the following values: 1. The initial value of the data member, value 2. The value after adding num1 3. The value after multiplying by 3 4. The value after subtracting num2 5. The value after dividing by 2 6. The value after calling the clear() method Ex: If the input is: 10.05.0 the output is: Current file: Calculator.c Load default template... Current file: Calculator.h Load default template... 1 2 // TODO: Define the Calculator_struct 3 4 // TODO: Declare functions 5 // InitCalculator(), Add(), Subtract(), Multiply(), Divide(), Clear(), Getvalue() 6

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

Database And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions

Question

Develop goals and timetables.

Answered: 1 week ago

Question

Understanding Group Leadership Culture and Group Leadership

Answered: 1 week ago