抱歉...為各位添麻煩了...
以自行想辦法解決了...
文章關鍵字

ScarFlame wrote:
如題~~ 拜託各...(恕刪)

逐行註解是最簡單的
幫你註解好囉
///* Rectangle intersection! */
//#include <stdio.h>
//#define P(a) ((float)a/1000)
//#define ABS(x) (x)>0?(x):(-x)
//#define MAX(x,y) (x>y)?(x):(y)
//#define MIN(x,y) (x<y)?(x):(y)
//
//typedef struct {
//int x;
//int y;
//}Point;
//typedef struct {
//Point ll;//lower left point of this rectangle
//Point ur;//upper right point
//unsigned int color;
//unsigned int node;
//unsigned int area;
//} Rect;
//
//Rect r1, r2, r3;
//
//Rect inputRect(void);
//Rect goodRect(Rect);
//Rect intersectRects(Rect, Rect);
//void outRect(Rect);
//
//FILE *fptr;
//
//int main(void){
//int i;
//
//if ((fptr= fopen("newyear.dat", "w"))== NULL)
//puts("***Open File Failed!\n");
//else
//puts("Open File OK!\n");
//
//for(i=0; i<15; i++) r1=inputRect();
//return 0;
//
//r1= inputRect();
//outRect(r1);
//
//r2= inputRect();
//outRect(r2);
//
//fclose(fptr);
////r3= intersectRects(r1, r2);
////outRect(r3);
//
//return 0;
//}
//
//Rect goodRect(Rect inR)
//{
//Rect r;
//
//r= inR;
//
//r.ll.x= MIN(inR.ll.x,inR.ur.x);
//r.ll.y= MIN(inR.ll.y,inR.ur.y);
//r.ur.x= MAX(inR.ll.x,inR.ur.x);
//r.ur.y= MAX(inR.ll.y,inR.ur.y);
//r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);
//return(r);
//}
//
//Rect inputRect(void){
//Rect r1;
//float inX, inY;
//
//puts("Please Input Rectangle 1 X1,Y1");
//scanf("%f %f", &inX, &inY);
//r1.ll.x= (int) (inX*1000);
//r1.ll.y= (int) (inY*1000);
//puts("Please Input X2,Y2");
//scanf("%f %f", &inX, &inY);
//r1.ur.x= (int) (inX*1000);
//r1.ur.y= (int) (inY*1000);
//
//r1= goodRect(r1);
//fprintf(fptr, "%f %f\n",(float)r1.ll.x/1000, (float)r1.ll.y/1000 );
//fprintf(fptr, "%f %f\n",(float)r1.ur.x/1000, (float)r1.ur.y/1000 );
//return r1;
//}
//
//void outRect(Rect r)
//{
//printf("The rectangle is:(%f,%f),(%f,%f)\n",
//P(r.ll.x),P(r.ll.y),P(r.ur.x),P(r.ur.y));
//printf("The area of this rectangle is %f\n\n", P(r.area)/1000);
//return;
//}
//
//Rect intersectRects(Rect r1, Rect r2)
//{
//Rect r;
//
//r.ll.x= MAX(r1.ll.x,r2.ll.x); r.ll.y=MAX(r1.ll.y,r2.ll.y);
//r.ur.x= MIN(r1.ur.x,r2.ur.x); r.ur.y=MIN(r1.ur.y,r2.ur.y);
//r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);
//return r;
//}
風~~
holyduck wrote: 逐行註解是最簡單的 幫你註解好囉 /...(恕刪)


註解的太漂亮了。
哈~本日最好笑!holyduck大,真有你的!
不要說 01 的網友都是無情無義的,看我對你多好,連空白行都解釋得清清楚楚
喵~~ 滑鼠不能當飯吃,但可以混飯吃
中英對照,午餐完看這篇有利消化..
樓主直接發問哪裡不懂比較快,但請先翻閱相關指令,其實程式碼本身已經註解的很清楚囉..
sryang wrote:
不要說 01 的網友...(恕刪)
我還以為是要問寫註解的技巧
ScarFlame wrote:
如題~~ 拜託各...(恕刪)
holyduck wrote:
逐行註解是最簡單的幫...(恕刪)


sryang wrote:
不要說 01 的網友...(恕刪)


兩位太有才了...噴飯


另外這是作業嗎?


還有逐行註解太累了拉(我幫你一次註解全部,不用謝了)
/*
/* Rectangle intersection! */
#include <stdio.h>
#define P(a) ((float)a/1000)
#define ABS(x) (x)>0?(x):(-x)
#define MAX(x,y) (x>y)?(x):(y)
#define MIN(x,y) (x<y)?(x):(y)

typedef struct {
int x;
int y;
}Point;
typedef struct {
Point ll;//lower left point of this rectangle
Point ur;//upper right point
unsigned int color;
unsigned int node;
unsigned int area;
} Rect;

Rect r1, r2, r3;

Rect inputRect(void);
Rect goodRect(Rect);
Rect intersectRects(Rect, Rect);
void outRect(Rect);

FILE *fptr;

int main(void){
int i;

if ((fptr= fopen("newyear.dat", "w"))== NULL)
puts("***Open File Failed!\n");
else
puts("Open File OK!\n");

for(i=0; i<15; i++) r1=inputRect();
return 0;

r1= inputRect();
outRect(r1);

r2= inputRect();
outRect(r2);

fclose(fptr);
//r3= intersectRects(r1, r2);
//outRect(r3);

return 0;
}

Rect goodRect(Rect inR)
{
Rect r;

r= inR;

r.ll.x= MIN(inR.ll.x,inR.ur.x);
r.ll.y= MIN(inR.ll.y,inR.ur.y);
r.ur.x= MAX(inR.ll.x,inR.ur.x);
r.ur.y= MAX(inR.ll.y,inR.ur.y);
r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);
return(r);
}

Rect inputRect(void){
Rect r1;
float inX, inY;

puts("Please Input Rectangle 1 X1,Y1");
scanf("%f %f", &inX, &inY);
r1.ll.x= (int) (inX*1000);
r1.ll.y= (int) (inY*1000);
puts("Please Input X2,Y2");
scanf("%f %f", &inX, &inY);
r1.ur.x= (int) (inX*1000);
r1.ur.y= (int) (inY*1000);

r1= goodRect(r1);
fprintf(fptr, "%f %f\n",(float)r1.ll.x/1000, (float)r1.ll.y/1000 );
fprintf(fptr, "%f %f\n",(float)r1.ur.x/1000, (float)r1.ur.y/1000 );
return r1;
}

void outRect(Rect r)
{
printf("The rectangle is:(%f,%f),(%f,%f)\n",
P(r.ll.x),P(r.ll.y),P(r.ur.x),P(r.ur.y));
printf("The area of this rectangle is %f\n\n", P(r.area)/1000);
return;
}

Rect intersectRects(Rect r1, Rect r2)
{
Rect r;

r.ll.x= MAX(r1.ll.x,r2.ll.x); r.ll.y=MAX(r1.ll.y,r2.ll.y);
r.ur.x= MIN(r1.ur.x,r2.ur.x); r.ur.y=MIN(r1.ur.y,r2.ur.y);
r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);
return r;
}
*/
吼, 你們很壞耶, 依小弟看案情不單純,
看清楚樓主是說"拜託逐行註解!! (是用DEV C++寫的)"
所以應該是以下如此~~

/* Rectangle intersection! */ //(是用DEV C++寫的)
#include <stdio.h>//(是用DEV C++寫的)
#define P(a) ((float)a/1000)//(是用DEV C++寫的)
#define ABS(x) (x)>0?(x):(-x)//(是用DEV C++寫的)
#define MAX(x,y) (x>y)?(x):(y)//(是用DEV C++寫的)
#define MIN(x,y) (x<y)?(x):(y)//(是用DEV C++寫的)
//(是用DEV C++寫的)
typedef struct {//(是用DEV C++寫的)
int x;//(是用DEV C++寫的)
int y;//(是用DEV C++寫的)
}Point;//(是用DEV C++寫的)
typedef struct {//(是用DEV C++寫的)
Point ll;//lower left point of this rectangle//(是用DEV C++寫的)
Point ur;//upper right point//(是用DEV C++寫的)
unsigned int color;//(是用DEV C++寫的)
unsigned int node;//(是用DEV C++寫的)
unsigned int area;//(是用DEV C++寫的)
} Rect;//(是用DEV C++寫的)
//(是用DEV C++寫的)
Rect r1, r2, r3;//(是用DEV C++寫的)
//(是用DEV C++寫的)
Rect inputRect(void);//(是用DEV C++寫的)
Rect goodRect(Rect);//(是用DEV C++寫的)
Rect intersectRects(Rect, Rect);//(是用DEV C++寫的)
void outRect(Rect);//(是用DEV C++寫的)
//(是用DEV C++寫的)
FILE *fptr;//(是用DEV C++寫的)
//(是用DEV C++寫的)
int main(void){//(是用DEV C++寫的)
int i;//(是用DEV C++寫的)
//(是用DEV C++寫的)
if ((fptr= fopen("newyear.dat", "w"))== NULL)//(是用DEV C++寫的)
puts("***Open File Failed!\n");//(是用DEV C++寫的)
else//(是用DEV C++寫的)
puts("Open File OK!\n");//(是用DEV C++寫的)
//(是用DEV C++寫的)
for(i=0; i<15; i++) r1=inputRect();//(是用DEV C++寫的)
return 0;//(是用DEV C++寫的)
//(是用DEV C++寫的)
r1= inputRect();//(是用DEV C++寫的)
outRect(r1);//(是用DEV C++寫的)
//(是用DEV C++寫的)
r2= inputRect();//(是用DEV C++寫的)
outRect(r2);//(是用DEV C++寫的)
//(是用DEV C++寫的)
fclose(fptr);//(是用DEV C++寫的)
//r3= intersectRects(r1, r2);//(是用DEV C++寫的)
//outRect(r3);//(是用DEV C++寫的)
//(是用DEV C++寫的)
return 0;//(是用DEV C++寫的)
}//(是用DEV C++寫的)
//(是用DEV C++寫的)
Rect goodRect(Rect inR)//(是用DEV C++寫的)
{//(是用DEV C++寫的)
Rect r;//(是用DEV C++寫的)
//(是用DEV C++寫的)
r= inR;//(是用DEV C++寫的)
//(是用DEV C++寫的)
r.ll.x= MIN(inR.ll.x,inR.ur.x);//(是用DEV C++寫的)
r.ll.y= MIN(inR.ll.y,inR.ur.y);//(是用DEV C++寫的)
r.ur.x= MAX(inR.ll.x,inR.ur.x);//(是用DEV C++寫的)
r.ur.y= MAX(inR.ll.y,inR.ur.y);//(是用DEV C++寫的)
r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);//(是用DEV C++寫的)
return(r);//(是用DEV C++寫的)
}//(是用DEV C++寫的)
//(是用DEV C++寫的)
Rect inputRect(void){//(是用DEV C++寫的)
Rect r1;//(是用DEV C++寫的)
float inX, inY;//(是用DEV C++寫的)
//(是用DEV C++寫的)
puts("Please Input Rectangle 1 X1,Y1");//(是用DEV C++寫的)
scanf("%f %f", &inX, &inY);//(是用DEV C++寫的)
r1.ll.x= (int) (inX*1000);//(是用DEV C++寫的)
r1.ll.y= (int) (inY*1000);//(是用DEV C++寫的)
puts("Please Input X2,Y2");//(是用DEV C++寫的)
scanf("%f %f", &inX, &inY);//(是用DEV C++寫的)
r1.ur.x= (int) (inX*1000);//(是用DEV C++寫的)
r1.ur.y= (int) (inY*1000);//(是用DEV C++寫的)
//(是用DEV C++寫的)
r1= goodRect(r1);//(是用DEV C++寫的)
fprintf(fptr, "%f %f\n",(float)r1.ll.x/1000, (float)r1.ll.y/1000 );//(是用DEV C++寫的)
fprintf(fptr, "%f %f\n",(float)r1.ur.x/1000, (float)r1.ur.y/1000 );//(是用DEV C++寫的)
return r1;//(是用DEV C++寫的)
}//(是用DEV C++寫的)
//(是用DEV C++寫的)
void outRect(Rect r)//(是用DEV C++寫的)
{//(是用DEV C++寫的)
printf("The rectangle is:(%f,%f),(%f,%f)\n",//(是用DEV C++寫的)
P(r.ll.x),P(r.ll.y),P(r.ur.x),P(r.ur.y));//(是用DEV C++寫的)
printf("The area of this rectangle is %f\n\n", P(r.area)/1000);//(是用DEV C++寫的)
return;//(是用DEV C++寫的)
}//(是用DEV C++寫的)
//(是用DEV C++寫的)
Rect intersectRects(Rect r1, Rect r2)//(是用DEV C++寫的)
{//(是用DEV C++寫的)
Rect r;//(是用DEV C++寫的)
//(是用DEV C++寫的)
r.ll.x= MAX(r1.ll.x,r2.ll.x); r.ll.y=MAX(r1.ll.y,r2.ll.y);//(是用DEV C++寫的)
r.ur.x= MIN(r1.ur.x,r2.ur.x); r.ur.y=MIN(r1.ur.y,r2.ur.y);//(是用DEV C++寫的)
r.area= (r.ur.x-r.ll.x)*(r.ur.y-r.ll.y);//(是用DEV C++寫的)
return r;//(是用DEV C++寫的)
}//(是用DEV C++寫的)
//(是用DEV C++寫的)
//(是用DEV C++寫的)
.c連結檔(Dropbox空間):連結在此//(是用DEV C++寫的)

我一直以為這種類似學校作業求解答的文章只會在某知識plus出現...
關閉廣告
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!