1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 class Re_public_area 5 { 6 private: 7 8 可以不写吗? 9 10 public: 11 double leftx, lefty, width,height; 12 void Re_public_area (); 13 void generation() 14 }; 15 Re_public_area:: Re_public_area (double x, double y, double width1, double height1) 16 { 17 leftx=x; 18 lefty=y; 19 width=width1; 20 height=height1 21 }; 22 int maint() 23 { 24 using std::cout; 25 double area 26 Re_public_area re1(1.0,2.0,4.0,2.0); 27 Re_public_area re2(3.0,4.0,4.0,3.0); 28 n=std::min(re1.leftx+re1.width,re2.leftx+re2.width)- std::max(re1.leftx,re2.leftx); 29 m=std::min(re1.lefty+re1.height,re2.leftx+re2.height)-std::max(re1.height,re2.heiht); 30 if (n<=0||m<=0) 31 area=0; 32 eles 33 area=n*m 34 cout<<”Rectangular intersection area”<<area<<end1; 35 }
1 #include<iostream> 2 int main () 3 using namespace std; 4 { 5 int Li[]={1,2,3,4,5,6,7}; 6 int size = sizeof(Li)/sizeof(int); 7 int x=4; 8 ret=check(Li,n,x); 9 char c= ret ? “NO”:”YES”; 10 cout <<”answer:”<<c<<end1; 11 return 0; 12 } 13 int check(int *a,int len,int x) 14 { 15 int i; 16 if (!a || len<2) 17 cout<<“Too few elemets.\n”; 18 for (i=0;i<len;i++) 19 { 20 if ( !binary_search(a,len,i,a[i]+x)) 21 return0; 22 } 23 } 24 int binary_search(int*a,int len, int expect,int target) 25 { 26 int low=0, high=len ,mid=0; 27 while (low<high){ 28 middle=(low+high)/2; 29 if (target ==a[middle]) 30 return 0; 31 else if (target <a[middle]) 32 high=middle; 33 else if (target > a[middle]) 34 low =middle+1; 35 } 36 return -1; 37 }
第一个:
#include<iostream> #include<algorithm> using namespace std; class Re_public_area { private: public: double leftx, lefty, width,height; void Re_public_area (double x,double y,double width1,double height1); void generation(); }; Re_public_area:: Re_public_area (double x, double y, double width1, double height1) { leftx=x; lefty=y; width=width1; height=height1; }; int main() { using std::cout; double area; Re_public_area re1(1.0,2.0,4.0,2.0); Re_public_area re2(3.0,4.0,4.0,3.0); double n=std::min(re1.leftx+re1.width,re2.leftx+re2.width)- std::max(re1.leftx,re2.leftx); double m=std::min(re1.lefty+re1.height,re2.leftx+re2.height)-std::max(re1.height,re2.height); if (n<=0||m<=0) area=0; else area=n*m; cout<<"Rectangular intersection area"<<area<<endl; }
第二个,我不准备帮你查错误。
因为第一个程序我发现,是一个完全不会c/c++语言的人在copy别人的程序,都是最基本的分号,定义,的错误。
所以让别人帮你勘误,不如你认认真真按照源代码仔仔细细打一遍,或者百度c/c++的基本语法。
两个程序
– zjy20170604 6年前@zjy20170604:等我有空了,把你提的问题都看看,之前没空。。
– Shendu.cc 6年前