#include <conio.h>
#include<stdio.h>
#include<math.h> // ***********************************
#include<stdlib.h>
#define PI 3.141592653589793 //* DO NOT CHANGE ANYTHING! *
char res1,res2,r; //***********************************
char statics(void);
int main_menu(void);
int linear_menu(void);
void main_2(void);
void CalculusArea(void);
void CalculusLength(void);
void Gaus(void);
float function(float num[],float largest,int j); /* DECLARATION OF "GLOBAL" VARIABLES*/
float function_smallest(float num[],float smallest,int j);
float sum(float num[],int j);
float variance(float num[],float ave,int j);
char calculus(void);
float deviation( float num[],float ave,int j);
float num[30],lar,small,smallest,total;
float M(float num[],int j);
char nyan[14]={"NYAN HTOO TIN"};
void invalid(void);
void ascending(void);
void welcome(void);
void descending(void);
void D2();
int menu();
float Area,Base,Height,Length,Width,Radius,Base1,Base2,Side,Volume;
int RES,RES2,RES1;
void D3();
void Square();
void complex();
void Rectangle();
void Parallelogram();
void Triangle();
void Circle();
void Trapezoid();
void Cube();
void Pyramid();
void Cylinder();
void Cone();
void Sphere();
void printout();
void display(float num[],int j);
void error(void);
float length(float,float,float,float,int);
float largest,var,temp,ave,VAR,V,s_de,median,tmp,len;
int i,j,k,l,m;
float a[100][101],c[100];
int N,p;
void main()
{
int re;
// welcome();
do
{
re=main_menu();
if(re!=7)
{
switch(re) /* First switch statement for the main_menu*/
{
case 1: do{ /* main case 1 : statistics_calculator*/
statics();
if(res1!='k')
{
switch(res1)
{
///ACCEPTING THE INPUT NO: && CALCULATING TOTAL, AVERAGE, VARIANCE , STANDARD DEVIATION/
case 'a':j=0; /* main_case 1: sub a: */
case 'A':printf("\n How many numbers to enter\t:");
scanf("%d",&j);
if(j>30)
{ system("cls");printf("\n\n\t\t Maximum numbers to be entered is 30\n");j=0;_sleep(1000);}
if(j>0 && j<=30){
for(i=0; i<j; i++)
{
printf(" Enter number %d: ",i+1);
scanf("%f",&num[i]);
}
getche();}
break;
// DISPLAY TOTAL OF THE NUMBERS/
case 'b': /*main_case 1: sub b: */
case 'B': if(j<=0)
{ invalid();
}
if(j>0 && j<=30)
{ display(num,j);
total=sum(num,j);
printf(" \nTotal=%.5f\n",total);
}getche();
break;
case 'c': /*main_case 1: sub c:*/
case 'C': if(j<=0)
{ invalid();
}
if(j>0 && j<=30)
{ display(num,j);
ave=sum(num,j)/j;
printf("\n Average=%.5f\n",ave);
}
getche();
break;
///DISPLAY THE VARIANCE\\
case 'd': /*main_case 1: sub d:*/
case 'D': if(j<=0)
{
invalid();}
if(j>0 && j<=30)
{ display(num,j);
VAR=variance(num,ave,j);
printf("\n Variance:\t%.4f\n",VAR);
}getche();
break;
///DISPLAY THE STANDARD DEVIATION\
case 'e': /*main_case 1: sub e:*/
case 'E': if(j<=0)
{
invalid();}
if(j>0 && j<=30)
{ display(num,j);
s_de=deviation(num,ave,j);
printf("\n Standard deviation:\t%.4f\n",s_de);}
getche();
break;
case 'h':
case 'H': if(j<=0) /*main_case 1: sub h:*/
{
invalid();}
if(j>0){
display(num,j);
ascending();
getche();}
break;
case 'i':
case 'I': /*main_case 1: sub i:*/
if(j<=0)
{
invalid();}
if(j>0 && j<=30)
{
display(num,j);
descending();
getche();
} break;
case 'f':
case 'F': if(j<=0) /*main_case 1: sub f:*/
{ invalid();}
if(j>0 && j<=30)
{
display(num,j);
lar=function(num,largest,j);
printf(" Largest=%.4f\n",lar);
}
getche();
break;
case 'g' :
case 'G':if(j<=0) /*main_case 1: sub g:*/
{ invalid();}
if(j>0 && j<=30){display(num,j);
small=function_smallest(num,smallest,j);
printf(" Smallest=%.4f\n",small);
}
getche();
break;
case 'j':
case 'J': if(j<=0) /*main_case 1: sub j:*/
{ invalid();}
if(j>0 && j<=30)
{
display(num,j);
printf(" Median:%.4f\n",M(num,j));}
getche();
break;
default: break;
}}
}
while(res1!='k'); /* end of statics do_while loop*/
break;
case 2: /* main_case 2:*/
main_2();
break;
case 3: complex(); /*main_case 3:*/
break;
case 4: // main_case 4
do{ system("cls");
calculus();
if(res2!='c')
{
switch(res2)
{
case 'a': CalculusArea();
break;
case 'b': CalculusLength();
break;
default: break;
}
}
}while(res2!='c'); /*end of main_case 3 do_while loop*/
break;
case 5: system("cls");
Gaus();
break;
case 6: do
{ system("cls");
menu();
if(RES!=3){
switch(RES){
case 1: D2();
break;
case 2: D3();
break;
default: printf(" Invalid!\n");_sleep(500);
break;
}}
}
while(RES!=3);
default: break;
}
}}
while(re!=7 ); /* END OF MAIN_MENU*/
system("cls");
printf("\n\n\t\t Thanks for using this program\n\n\n");
printf(" \n\t\tGOODBYE\n\n");
_sleep(1000);
}
/*****************/
/* FUNCTION */
/* */
/*****************/
float length(float A,float B,float x1,float x0,int n)
{
float D,z0=0,z1=0,delx,L,x,E;
int m;
for(m=0;m<=n; m++)
{
delx=(x1-x0)/n;
x=x0+m*delx;
if(m%2==0 && x!=x0 && x!=x1)
{ z1=z1+(float)sqrt((1+(4*A*A*x*x)+(4*A*B*x)+B*B));
}
if(x!=x0 && x!=x1){
z0=z0+(float) sqrt((1+(4*A*A*x*x)+(4*A*B*x)+B*B));}
D=(float)sqrt(1+(4*A*A*x0*x0)+(4*A*B*x0)+B*B);
E=(float)sqrt(1+(4*A*A*x1*x1)+(4*A*B*x1)+B*B);
L=delx*(D+E+4*z0-2*z1)/3;
flushall();
} return L;
}
float function(float num[],float largest,int j)
{
largest=num[0];
for( i=0; i<j;i++)
if(num[i]>largest)
{ largest=num[i];
}
return largest;
}
float function_smallest(float num[],float smallest,int j)
{
smallest=num[0];
for( k=0; k<j; k++)
if(smallest>num[k])
{ smallest=num[k];
}
return smallest;
}
float sum(float num[],int j)
{
float sum=0;
for( l=0; l<j;l++)
{
sum=sum+num[l];
}
return sum;
}
float variance(float num[],float ave,int j)
{ ave=sum(num,j)/j;
var=0;
for( i=0; i<j; i++)
{
var=var+(float)pow((num[i]-ave),2);
}
return (float)var/j;
}
char statics(){
system("cls");
printf("=========================\n");
printf("\nChoose an option\n");
printf(" a) Enter the numbers\n");
printf(" b) Calculate the total\n");
printf(" c) Calculate the average\n");
printf(" d) Variance\n");
printf(" e) Standard deviation\n");
printf(" f) largest number\n");
printf(" g) smallest number\n");
printf(" h) number in ascending order\n");
printf(" i) number in descending order\n");
printf(" j) median\n");
printf(" k) Quit\n");
printf("==========================\n");
printf("Enter your choice :");
scanf("%c",&res1);
flushall();
return res1;
}
int main_menu()
{ int re;
system("cls");
printf("\t*******************************\n");
printf("\t*1) Statistics Calculator *\n");
printf("\t*2) Polynomial Equation solver*\n");
printf("\t*3) Complex number *\n");
printf("\t*4) Calculus *\n");
printf("\t*5) Linear Equation *\n");
printf("\t*6) Geometry Area *\n");
printf("\t*7) Exit *\n");
printf("\t*******************************\n");
printf("Enter option\t:");
scanf("%d",&re);
flushall();
return re;
}
void ascending()
{printf(" Number in ascending order\n");
for ( i=0; i<j; i++){
for ( k=0; k<j-1; k++){
if (num[k] > num[k+1]){
temp = num[k+1];
num[k+1] = num[k];
num[k] = temp;
}
}
}
for( m=0; m<j; m++)
{_sleep(50);
printf(" %.2f\n",num[m]);
}
}
void descending()
{
printf(" Number in descending order\n");
for ( i=0; i<j; i++)
{
for ( k=0; k<j-1; k++)
{
if (num[k] < num[k+1])
{
temp = num[k+1];
num[k+1] = num[k];
num[k] = temp;
}
}
}for(i=0; i<j; i++)
{_sleep(50); printf(" %.2f\n",num[i]);}
}
float M(float num[],int j)
{
float median;
ascending();
if(j%2==0)
{
median=(float)0.5*(num[(j/2)-1]+num[j/2]);
}
if(j%2!=0)
{ median=num[(j+1)/2-1];
}
flushall();
return median;
}
void display(float num[],int j)
{
printf(" The %d numbers you have entered are:",j);
for( i=0;i<j; i++)
{ _sleep(20);
printf("%.4f,",num[i]);
}printf("\n");
}
char calculus(void) {
system("cls");
printf("===================================================\n");
printf("~ Choose an option\n");
printf("~ a) Find definite area of ax^2+bx+c\n");
printf("~ b) Find the length of path of curve ax^2+bx+c\n");
printf("~ c) End\n");
printf("===================================================\n");
scanf("%c",&res2);
flushall();
return res2;
}
void invalid()
{
system("cls");
printf(" \n\n\t\tYou have not entered anything\n\n");
for( i=0; i<20; i++)
{
printf(".");_sleep(30);}
}
float deviation(float num[],float ave,int j)
{ float VAR=variance(num,ave,j); // variance function call to calculate deviation//
return (float)sqrt(VAR);
}
void welcome(void)
{
printf(" \n\n\n\t\tThis program is written by ");
for( i=0; i<13; i++)
{
printf(" %c",nyan[i]);
_sleep(200);
}
printf("\n\n\t\t\tLOADING\n\n\t");
for( k=0; k<20; k++)
{
printf(" *");_sleep(20*k);
}}
void error(void)
{system("cls");
_sleep(100);
fflush(stdin);
printf("\n\n\t\t The key you entered is not recognized!\n\n");
printf(" Try Again\n");
getche();
}
void D2(){
do{
printf("What shape would you like to solve for?(0 to quit)\n");
printf("1). Square\n");
printf("2). Rectangle\n");
printf("3). Parallelogram\n");
printf("4). Triangle\n");
printf("5). Cirlce\n");
printf("6). Trapezoid\n");
scanf("%d",&RES1);flushall();
if(RES1!=0){
switch(RES1){
case 1: Square();
break;
case 2: Rectangle();
break;
case 3: Parallelogram();
break;
case 4: Triangle();
break;
case 5: Circle();
break;
case 6: Trapezoid();
break;
default: printf(" Error. Invalid Input\n");
break;
}
}
printout();
}
while(RES1!=0);
}
//SUBROUTINE Square
void Square()
{
printf(" What is the side length of the square?\n");
scanf("%f",&Length);flushall();
Area=Length*Length;
printf(" The area of the square is %.4f\n",Area);
}
// SUBROUTINE Rectangle
void Rectangle(){
printf(" What is the length of the rectangle?\n");
scanf("%f",&Length);
printf(" What is the width of the rectangle?\n");
scanf("%f",&Width);
Area=Length*Width;
printf(" Area of the rectangle is %.4f\n",Area);
}
// SUBROUTINE Parallelogram
void Parallelogram(){
printf(" What is the base of the Parallelogram?\n");
scanf("%f",&Base);
printf("What is the height of the Parallelogram?\n");
scanf("%f",&Height);
Area=Base*Height;
printf(" The area of the Parallelogram is %.4f\n",Area);
}
//SUBROUTINE Triangle
void Triangle()
{
printf(" What is the base of the triangle?\n");
scanf("%f",&Base);
printf(" What is the height of the triangle?\n");
scanf("%f",&Height);
Area=(float)(0.5*Base *Height);
printf(" The area of the trianle is %.4f\n",Area);
}
//SUBROUTINE Circle
void Circle(){
printf(" What is the radius of the circle?\n");
scanf("%f",&Radius);
Area=(float)(PI*Radius*Radius);
printf(" The area of the circle is %.4f\n",Area);
}
//SUBROUTINE Trapezoid
void Trapezoid(){
printf(" What is the base1 of the Trapezoid?\n");
scanf("%f",&Base1);
printf(" What is the base2 of the Trapezoid?\n");
scanf("%f",&Base2);
printf(" What is the height of the Trapezoid?\n");
scanf("%f",&Height);
Area=(float)(0.5*Height*(Base1+Base2) );
printf(" The area of the Trapezoid is %.4f\n",Area);
}
//SUBROUTINE D3
void D3(){
do{
flushall();
printf(" What shape do you want to solve for?( 0 to quit)\n");
printf("1) Cube\n");
printf("2) Right Pyramid\n");
printf("3) Right Cylinder\n");
printf("4) Right cone\n");
printf("5) Sphere\n");
scanf("%d",&RES2);
if(RES2!=0){
switch(RES2)
{
case 1: Cube();
break;
case 2: Pyramid();
break;
case 3: Cylinder();
break;
case 4: Cone();
break;
case 5: Sphere();
break;
default: printf(" Error! Invalid Input\n");
break;
}
}printout();
}
while(RES2!=0);
}
void Cube()
{
printf(" What is the length of side of cube?\n