Question

In: Computer Science

Write a C program that runs on ocelot for a mini calculator using only the command...

Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line.
Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-e] value
• The variable value is the starting value.
• Value should be validated to be an integer between 1 and 99. Error message and usage shown if not.
• -a adds num to value.
• -d divides value by num.
• -m multiplies value by num.
• -s subtracts num from value.
• -e squares value. (Note: no num is needed.)
• Output should have exactly 2 decimal places no matter what the starting values are.
• If –e is included, it is executed first.
• Use standard order of operations for all operations.
Code should be nicely indented and commented. Create a simple Makefile to compile your program into an executable called minicalc.The Makefile should be called Makefile with no extension. I should be able to type make at the command line to compile your program.

Solutions

Expert Solution

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

int add( int ,int)

int div( int ,int )

int mul( int ,int )

int sub(int ,int )

int main()

{

int num1, num2, choice ;

printf("1.Addition\n2:Division\n3:Multipliication\n4:Substarction\n0:Exit\n enter your choice:");

scanf("%d",&choice);

switch(choice)

{

case 0:

return 0;

break;

case 1:

printf("enter the first number:\n");

scanf("%d",&num1);

printf("enter the second number:\n");

scanf("%d",&num2);

printf("%d",add(num1,num2));

break;

case 2:

printf("enter first number:\n);

scanf('%d",&num1);

printf("enter second number:\n);

scanf("%d",&num2);

printf("%d",div(num1, num2));

break;

case 3;

printf("enter first number:\n);

scanf("%d",&num1);

printf("enter second number:\n);

scanf("%d",&num2);

printf("%d",mul(num1,num2));

break;

case 4:

printf("enter first number :\n");

scanf("%d",&num1);

printf("enter second number:\n");

scanf("%d",&num2);

printf("%d",sub(num1,num2));

break;

default:

printf("this is not a valid choice");

break;

}

}

// Addition

int add(int a, int b)

{

int c=a+b;

return c;

}

//multiplication

int mul(int x, int y)

{

int z=x * y;

return z;

}

//division

int div(int i ,int j)

{

int k=i / j;

return k;

}

// substraction

int sub(int m, int n)

{

int l= m - n;

return l;

}


Related Solutions

C Program: create a mini calculator with the following usage (using getopt to parse the command...
C Program: create a mini calculator with the following usage (using getopt to parse the command line arguments) Usage: minicalc [-a num] [-m num] [-x] value 1. The variable value is the starting value. 2. Value should be validated to be an integer between 1 and 50 inclusive. Error message and usage shown if not. 3. For the -m option num should be a positive integer between 1 and 10 inclusive. 4. For the -a option num should be a...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator. Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %. Output Requirements: Make your output easy to understand,...
REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will...
REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will calculate the results of Reverse Polish expressions that are provided by the user. You must use a linked list to maintain the stack for this program (NO array implementations of the stack). You must handle the following situations (errors): Too many operators (+ - / *) Too many operands (doubles) Division by zero The program will take in a Polish expression that separates the...
Using C or C++, write a program which implements the command pipeline ”ls -la | tr...
Using C or C++, write a program which implements the command pipeline ”ls -la | tr [a-zA-Z0-9] a”. Use any combination of fork, exec, wait, read, and write necessary to create this functionality. Note: the parent process must be the one to output the data to the console.
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator,...
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator, reading an infix algebraic expression with numbers and simple operations: +, -, *, / , (, and ). The program converts an infix expression into an equivalent postfix expression, and then evaluates the postfix expression, and then prints the result if input expression is correct otherwise prints error messages. Your program must interact with the user until the user quits.    REQUIREMENTS: - Your...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
Given a queue of integers, write an algorithm and the program in c++ that, using only...
Given a queue of integers, write an algorithm and the program in c++ that, using only the queue ADT, calculates and prints the sum and the average of the integers in the queue without changing the contents of the queue.
Write a program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
How to write this mini program in C# - (C sharp please) There are 3 squirrels...
How to write this mini program in C# - (C sharp please) There are 3 squirrels and winter begins in roughly 12 weeks Each week, a squirrel will manage to stash away anywhere from 10 to 20 acorns Each week, display the following: ◦ The number of weeks before winter ◦ The number of acorns each squirrel stashed away that week ◦ The total number of acorns each squirrel has stashed away Bonus: display the number of acorns stashed each...
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT