#include <stdio.h>
#include "MathShape.h"
#include "Arrays.h"
#include "Sort.h"
int main(void)
{
//代码一
int arr[] = {1, 4, 7 -1, 12, 8, 32, -2, 8, 9, 66, 55, 44, 77, 45, 32};
int len = sizeof(arr)/sizeof(int);
printIntArray(arr, len);
printf("-----starting quickSorting-----\n");
quickSortMine(arr, len, 0, len - 1);
printf("-----ending quickSorting-----\n");
printIntArray(arr, len);
//代码二
struct Shape sh;
struct Shape* shape = &sh;
shape -> type = Rectangle;
printf("pls insert a value for 'rectangle-width'\n");
scanf("%d",&shape -> shapeData.rectangle.width);
printf("pls insert a value for 'rectangle-height'\n");
scanf("%d",&shape -> shapeData.rectangle.height);
double result = calculate(shape);
printf("-----now the result of calculating Rectangle is %lf-----\n", result);
// shape - circle
shape -> type = Circle;
printf("pls insert a value for 'circle-radius'\n");
scanf("%d", &shape -> shapeData.circle.radius);
// shape - circle : result
printf("-----now the result of calculating Circle is %lf-----\n", calculate(shape));
// shape - square
shape -> type = Square;
printf("pls insert a value for 'square-sides'\n");
scanf("%d", &shape -> shapeData.square.sides);
// shape - sqaure : result
printf("-----now the result of calculating Square is %lf-----\n", calculate(shape));
//other
//
return 0;
}
Array.h
#ifndef ARRAYS_H
#define ARRAYS_H
void printIntArray(int arr[], int len);
int isValid(int arr[], int len);
#endif
Arrays.c
#include <stdio.h>
#include "Arrays.h"
int isValid(int arr[], int len)
{
return arr != NULL && len > 0;
}
void printIntArray(int arr[], int len)
{
if(!isValid(arr, len))
{
printf("Invalid Array Parameter!!!!");
return;
}
int *arrP = arr;
for(int i = 0; i < len; i++, arrP++)
{
if(i == 0) printf("[ ");
printf("%d", *arrP);
if(i < len - 1) printf(", ");
if(i == len -1) printf("]\n");
}
}