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:...
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: ?...
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...
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...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give me either partial answers, or incorrect skeleton. PLEASE YOU CAN'T CHANGE WHAT IS THERE, YOU CAN ONLY ADD. void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? void readFile(Candidate candidates[]) –...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking list. void displayCandidate(Candidate candidates[]) – prints the complete information about the candidate . Candidate First(Candidate candidates[]) – returns single struct element: candidate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT