Question

In: Computer Science

- Error Checking - Use of Functions - Menu system - Array Processing

C language and that must contain the following:

- Error Checking

- Use of Functions

- Menu system

- Array Processing

 

Solutions

Expert Solution

#include
float addOp(int a,int b)
{
return (a+b);
}
float subOp(int a,int b)
{
return (a-b);
  
}
float mulOp(int a,int b)
{
return (a*b);
}
float divOp(int a,int b)
{
return (float)a/b;
}
int main()
{
int a,b,ch;
int array[3];
  
float div ;
while(1)
{
printf("\n1. addition ");
printf("\n2. subtraction ");
printf("\n3. multiplication ");
printf("\n4. division ");
printf("\n5. exit ");
printf("\nEnter your choice ");
scanf("%d",&ch);
if(ch!=5)
{
printf("\nenter value of a ");
scanf("%d",&a);
printf("\nenter value of b ");
scanf("%d",&b);
if(ch==1)
{
div=(a+b);
printf("%d + %d= %f ",a,b,div);
}
if(ch==2)
{
div=subOp(a,b);
printf("%d - %d= %f ",a,b,div);
}
if(ch==3)
{
div=mulOp(a,b);
printf("%d * %d =%f ",a,b,div);
}
if(ch==4)
{
if(b==0) //error processing
printf("error division by 0 yields infinity \n");
else
{
div=divOp(a,b);
printf("%d / %d =%f ",a,b,div);
  
  
}
}
  
  
}
else
{
//use of array to store the last input and output
array[0]=a;
array[1]=b;
array[2]=div;
printf("the last input was %d and %d ",array[0],array[1]);
printf("\nThe last output was %f ",div);
break;
  
}
}

return 0;
}

 


Related Solutions

use c++ (4) Perform error checking for the data point entries. If any of the following...
use c++ (4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point. If entry has no comma Output: Error: No comma in string. (1 pt) If entry has more than one comma Output: Error: Too many commas in input. (1 pt) If entry after the comma is not an integer Output: Error: Comma not followed by an integer. (2 pts) Ex:...
Identify and explain the three basic functions of system: Input" Processing and output?
Identify and explain the three basic functions of system: Input" Processing and output?
This is an exercise for a menu-driven program. Program should use shell functions. Write a program...
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a rectangle 3. Calculate the area of a triangle 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ?...
Task 2: Debugging and writing functions In IDLE, use the File -> New Window menu option...
Task 2: Debugging and writing functions In IDLE, use the File -> New Window menu option to open a new editor window for your program, and save it using the name hw4Task2.py. Make sure to specify the .py extension. Copy the following (buggy) code into that file: def mysum(x, y) """ takes two numbers and returns their sum """     total = x + y     print(total) Save the file using Ctrl-S. Then try to run it using F5. What...
Write a program using multiple functions. Make use of an array to store data Make use...
Write a program using multiple functions. Make use of an array to store data Make use of searching techniques Read data from a file Write data to a file Instructions: In this lab, you will be examining a set of stock collected over a twenty four day period. Be sure to make use of an array to store these stocks. You will be required to read in the data points from a file. Write a function to read in the...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array to test, thanks. get_location_of_min This function takes a matrix as a 2-D array of integers with NUM_COLS width, the number of rows in the matrix and two integer pointers. The function finds the location of the minimum value in the matrix and stores the row and column of that value to the memory location pointed to by the pointer arguments. If the minimum value...
1. Identify and explain the three basic functions of system: Input, Processing, and Output? 2. In...
1. Identify and explain the three basic functions of system: Input, Processing, and Output? 2. In details, explain the two types of software?
Functions, Characteristics and Advantages of Transaction Processing System (TPS). Write around 250 words of your own...
Functions, Characteristics and Advantages of Transaction Processing System (TPS). Write around 250 words of your own and please don't take entirely from Google
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT