C求圆、梯形、三角形的面积和一元二次方程的根(实虚)

文件列表:

circle.c

circle.h

display.c

display.h

equation.c

equation.h

main.c

menu.c

menu.h

trape.c

trape.h

trangle.c

trangle.h

----------------------------------------------------------------------------

circle.c

#include
#define PI 3.141

double circle_cacl(double radius);
void  circle_output(void);
void run_circle(void);
/*
void main()
{
	run_circle();
}
*/

double circle_cacl(double radius)
{	
	return PI*radius*radius;
}

void  circle_output(double radius)
{
	if(radius>0)
	{
		printf("the circle arae is %lf\n",circle_cacl(radius));
	}
	else
	{
		printf("pleased input the radius than bigger 0\n");
	}
}

void run_circle()
{	
	double radius;
	printf("Input the circle radius:");
	scanf("%lf",&radius);
	circle_output(radius);
}


circle.h

#ifndef _CIRCLE_H
#define _CIRCLE_H

extern double circle_cacl(double radius);
extern void  circle_output(double radius);
extern void run_circle(void);

#endif

display.c

#include

void display(void);
void run_display(void);

void main()
{
	run_display();
}
void display(void)
{
	printf("\t**********COMPUTE SYSTEM***********\t\n");
	printf("\t-----1.Compute the circle area-----\t\n");
	printf("\t-----2.Compute the trape  area-----\t\n");
	printf("\t-----3.Compute the triangle area-----\t\n");
	printf("\t-----4.Compute the equation root-----\t\n");
	printf("\t-----0.Exit the COMPUTE SYSTEM-------\t\n");
	printf("\t**************END******************\n");
	
}

void run_display(void)
{
	display();
}


display.h

#ifndef _DISPLAY_H
#define _DISPLAY_H

extern void display(void);
extern void run_display(void);

#endif


equation.c

#include
#include


double calc_equation_delt(double a,double b,double c);
void calc_equation_real_root(double a,double b,double c);
void calc_equation_vir_root(double a,double b,double c);
void equation_output(double a,double b,double c);
void run_equation(void);
/*
void main()
{
	run_equation();
}
*/
void run_equation(void)
{
	double a, b, c;
	printf("The equation a:");
	scanf("%lf",&a);
	printf("The equation b:");
	scanf("%lf",&b);
	printf("The equation c:");
	scanf("%lf",&c);
	equation_output(a,b,c);
}


double calc_equation_delt(double a,double b,double c)
{
	return b*b-4*a*c;
}


void calc_equation_real_root(double a,double b,double c)
{
	double q,p,delt;
	p=-b/2*a;
	delt=calc_equation_delt(a,b,c);
	q=sqrt(delt)/2.0*a;
	printf("The real_root_1=%lf+%lf\n",p,q);
	printf("The real_root_2=%lf-%lf\n",p,q);
}

void calc_equation_vir_root(double a,double b,double c)
{
	double q,p,delt;
	p=-b/2*a;
	delt=abs(calc_equation_delt(a,b,c));
	q=sqrt(delt)/2.0*a;
	printf("The vir_root_1=%lf+%lfi\n",p,q);
	printf("The vir_root_2=%lf-%lfi\n",p,q);
}

void equation_output(double a,double b,double c)
{
	if(a!=0.0)
	{
		if(calc_equation_delt(a,b,c)>=0)
		{
			calc_equation_real_root(a,b,c);
						
		}
		else
		{
			calc_equation_vir_root(a,b,c);
		}
	}
	else
	{
		printf("Input the a value not equel zero!\n");
	}
}


equation.h

#ifndef _EQUATION_H
#define _EQUATION_H

extern double calc_equation_delt(double a,double b,double c);
extern void calc_equation_real_root(double a,double b,double c);
extern void calc_equation_vir_root(double a,double b,double c);
extern void equation_output(double a,double b,double c);
extern void run_equation(void);

#endif


main.c

#include "menu.h"
void main()
{
	run_menu();
}


menu.c

#include
#include
#include "circle.h"
#include "display.h"
#include "equation.h"
#include "menu.h"
#include "trape.h"
#include "triangle.h"

void menu(void);
void choice_func(void);
void run_menu(void);

void choice_func(void)
{
	int choice;
	printf("Pleased input choice(circle,equation,trape,triangle,exit):");
	scanf("%d",choice);
	switch(choice)
	{
		case 1:run_circle();break;
		case 2:run_equation();break;
		case 3:run_trape();break;
		case 4:run_triangle();break;
		case 0:exit;break;
		default:
			printf("The invilid input choice!/n");break;					  
	}
}

void menu(void)
{
	while(1)
	{
		system("cls");
		run_display();
		choice_func();
		system("pause");
	}
}

void run_menu(void)
{
	menu();
}


menu.h

#ifndef _MENU_H
#define _MENU_H

extern void choice_func(void);
extern void menu(void);
extern void run_menu(void);

#endif


trape.c

#include

double trape_cacl(double top,double bottom,double higher);
void trape_output(double top,double bottom,double higher);
void run_trape(void);

void main()
{
	run_trape();
}

void run_trape(void)
{
	double top, bottom, higher;
	printf("The triangle top:");
	scanf("%lf",&top);
	printf("The triangle bottom:");
	scanf("%lf",&bottom);
	printf("The triangle higher:");
	scanf("%lf",&higher);
	trape_output(top,bottom,higher);
}

double trape_cacl(double top,double bottom,double higher)
{
	return (top+bottom)*higher/2.0;
}

void trape_output(double top,double bottom,double higher)
{
	if(top>0 && bottom>0 && higher>0)
	{
		printf("The trape area:%lf\n",trape_cacl(top,bottom,higher));
	}
	else
	{
		printf("pleased input the radius than bigger 0\n");
	}
}


trape.h

#ifndef _TRAPE_H
#define _TRAPE_H

extern double trape_cacl(double top,double bottom,double higher);
extern void trape_output(double top,double bottom,double higher);
extern void run_trape(void);

#endif


trangle.c

#include
#include

double tri_cacl(double side_1,double side_2,double side_3);
void tri_output(double side_1,double side_2,double side_3);
void run_triangle(void);

void main()
{
	run_triangle();
}
void run_triangle(void)
{
	double side_1, side_2, side_3;
	printf("The triangle side1:");
	scanf("%lf",&side_1);
	printf("The triangle side2:");
	scanf("%lf",&side_2);
	printf("The triangle side3:");
	scanf("%lf",&side_3);
	tri_output(side_1,side_2,side_3);	
	
}

double tri_cacl(double side_1,double side_2,double side_3)
{
	double l,tri_area,templet;
	l=(side_1 + side_2 + side_3)/2.0;
	templet=l*(l-side_1)*(l-side_2)*(l-side_3);
	tri_area=sqrt(templet);
	return tri_area;
}

void tri_output(double side_1,double side_2,double side_3)
{
	if(side_1>0 && side_2>0 && side_3>0)
	{
		if((side_1 + side_2>side_3)&& (side_1 + side_3>side_2) && (side_2 + side_3>side_1))
		{
			printf("The triangle area:%lf\n",tri_cacl(side_1, side_2, side_3));
		}
		else 
		{
			printf("Input the correct value!\n");
		}
	}
	else
	{
		printf("Input the correct value!\n");
	}
			
}


trangle.h

#ifndef _TRIANGLE_H
#define _TRIANGLE_H

extern double tri_cacl(double side_1,double side_2,double side_3);
extern void tri_output(double side_1,double side_2,double side_3);
extern void run_triangle(void);


#endif





你可能感兴趣的:(杂货铺)