For your final Linux project, you will create a menu driven, user-friendly shell
ID: 3768740 • Letter: F
Question
For your final Linux project, you will create a menu driven, user-friendly shell script that allows a user to calculate the results for several common mathematical expressions. In each case, the script will prompt the user for the required input and the provide the output.
The mathematical expressions to be implemented include:
a. Slope of a line given two points (m = (y2-y1)/(x2-x1)
b. average for an undetermined number of input integers (avg = (x1+x2 + x3 + x4 ... +xn)/n
c. Simple interest (Interest = Principle * Rate * time in years)
d. Area of a rectangle (area = length * width)
e. Your mathematical formula
The script should use good design techniques including an easy-to-use interface, separation of functionality and be tested rigorously for logic and other errors.
You should submit both your code, and your word or PDF document with screen captures showing your results of running your code.
Your document should be well-organized, well-written with minimal spelling and grammatical errors. The document should include page numbers, figure titles and numbers and section titles as appropriate.
Your code should include comments describing the code and header comments with your name, date and purpose of the script.
Submit your document and code no later than the assignment due date.
Explanation / Answer
Area of a rectangle:
#include<stdio.h>
#include<conio.h>
int main() {
int length, breadth, area;
printf(" Enter the Length of Rectangle : ");
scanf("%d", &length);
printf(" Enter the Breadth of Rectangle : ");
scanf("%d", &breadth);
area = length * breadth;
printf(" Area of Rectangle : %d", area);
return (0);
}
Slope of a line given two points (m = (y2-y1)/(x2-x1)
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int x1,x2,m,y1,y2;
printf("Enter value x1=");
scanf(x1="%d");
printf("Enter value x2=");
scanf(x2="%d");
printf("Enter value y1=");
scanf(y1="%d");
printf("Enter value y2=");
scanf(y2="%d");
m = (y2-y1)/(x2-x1);
printf(&m="%d");
return(0);
}
Simple interest (Interest = Principle * Rate * time in years)
#include<stdio.h>
#include<math.h>
int main()
{
int amount, rate, time, si;
printf(" Enter Principal Amount : ");
scanf("%d", &Principle);
printf(" Enter Rate of Interest : ");
scanf("%d", &Rate);
printf(" Enter Period of Time : ");
scanf("%d", &time in years);
si = (Principle * Rate * time in years);
printf(" Simple Interest : %d", si);
return(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.