c++题库编程题 下载本文

内容发布更新时间 : 2024/6/26 13:27:25星期一 下面是文章的全部内容请认真阅读。

共享知识 分享快乐

//2-5

#include #include #include using namespace std; class Triangle

{ int a,b,c;public: double Area() { double s=(a+b+c)/2;

return sqrt(s*(s-a)*(s-b)*(s-c)); }; int Perimeter(){ return a+b+c; }

void Input(){ cin>>a>>b>>c; }}; void main() { Triangle t1; t1.Input();

cout<

#include inline int max(int a,int b) { if(a>b)return a; else return b;} inline int max(int a,int b,int c) { return max(a,max(b,c)); }

void main() { int x=21,y=15,z=22,d; d=max(x,max(y,z)); cout<

#include

int overload(int n); char overload(char n); void main() { int n; char s; cout<<\输入5\ cin>>n;

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

cout<<\ cout<<\输入a\ cin>>s; cout<<\ cout<

int overload(int n) { return n; }

char overload(char n) {

cout<<\return 0; } //2-2

#include%using namespace std; inline char trans(char ch); int main() { char ch; while((ch=getchar())!='\\n') cout<

inline char trans(char ch) { if(ch>='a'&&ch<='z') return ch-32; else return ch+32; } //3-1

#include using std::cout; using std::endl; int Min(int a,int b) { return (a

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

}

int Min(int a,int b,int c) { return (Min(a,b)

int Min(int a,int b,int c,int d) { return (Min(a,b,c)

void main(void) { cout<<\ cout<<\ cout<<\} //3-2

#include using namespace std; void Area(float r) { cout<<\}

void Area(float a,float b) { cout<<\}

void Area(float a,float b,float h) { cout<<\}

void main() { Area(5); Area(3,3); Area(3,5,4); } //3-3

#include using namespace std; void Sort(int a[],int n) { bool flag; for(int i=0;i

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

flag=false; for(int j=1;ja[j]) { int temp=a[j-1]; a[j-1]=a[j]; a[j]=temp; flag=true; } if(!flag) break; } for(int m=0;m

void Sort(float b[],int n) { bool flag; for(int i=0;ib[j]) { float temp=b[j-1]; b[j-1]=b[j]; b[j]=temp; flag=true; } if(!flag) break; } for(int m=0;m

void main() { int a[10]={3,5,1,2,9,0,8,6,4,7}; float b[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}; Sort(a,10); Sort(b,10); }

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

//3-4

#include using namespace std; class Rectangle { float a,b; public: Rectangle() { cout<<\ cin>>a>>b; } Rectangle(float x,float y):a(x),b(y){} float Cir() { return (2*(a+b)); } float Area() { return (a*b); } };

void main() { Rectangle Re; cout<<\ <<\} //3-5

#include using namespace std; class Circle { float r; public: Circle() { cout<<\ cin>>r; } Circle(float x):r(x){} float Cir() {return 2*3.14*r;} float Area()

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚