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

内容发布更新时间 : 2024/12/23 10:53:10星期一 下面是文章的全部内容请认真阅读。

共享知识 分享快乐

{return 3.14*r*r;} };

void main() { Circle C(5); cout <<\ <<\} //4-1

class student { int no; char name[20]; public: student(); int getno()const; char*getname(); };

#include student::student() { no=1; strcpy(name,\}

int student::getno ()const { return no; }

char*student::getname() { return name; }

int main() { student s1; s1.getno(); s1.getname(); const student s2; s2.getno(); return 0;

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

共享知识 分享快乐

} //4-3

#include class object { float a; float weight; public: object(float w); ~object(){cout<<\};

class box:public object { float b; float height,widt; public: box(float w,float h,float wi):object(w),height(h),widt(wi){cout<<\height\ ~box(){cout<<\};

object::object(float w) { weight=w; cout<<\}

int main() { box b(1.1,2.2,3.3); return 0; } //4-4

#include\

using namespace std; class baseclass {

public: baseclass(){cout<<\ virtual ~baseclass(){cout<<\};

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

共享知识 分享快乐

class derivedclass:public baseclass {

public: derivedclass(){cout<<\ ~derivedclass(){cout<<\};

int main() { derivedclass obj; baseclass *p; p=&obj; return 0; } //4-5

#include\#include using namespace std; class Doument { char *name; public:

Doument(char *na) { name=new char [strlen (na)+1]; strcpy(name,na); } virtual void print() const {cout<<\姓名:\};

class Book:public Doument { int pagecount; char *name; public: Book(int p,char *na):Doument(na) { p=pagecount; name=new char [strlen (na)+1]; strcpy(name,na); } void print() const {cout<<\页码:\姓名:\};

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

共享知识 分享快乐

void disp(Doument& i) { i.print(); }

int main() { Book b(23,\小明\ disp(b); return 0; } //5-1

#include%using namespace std; class point {private: int x; int y; int z; static int num; public: point(int a,int b,int c); int print(); };

int point::num=0; int main() { point p1(1,2,3); p1.print(); point p2(5,3,2); p1.print(); point p3(3,6,4); p1.print(); return 0; }

point::point(int a,int b,int c) { x=a; y=b; z=c; num++; }

int point::print() {

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

共享知识 分享快乐

cout<<\第\个点\ return 0; } //5-2

#include #include using namespace std; class Stu { char name[15]; int age; float score; public: static int count; static float sum; Stu(char *p,int a,float s):age(a),score(s) { strcpy(name,p); count++; sum+=score; } Stu() { cout<<\ cin>>name>>age>>score; count++; sum+=score; } };

int Stu::count=0; float Stu::sum=0; void main() { Stu p(\子机\ cout<<\ <<\} //5-3

#include using namespace std; class Point { float x,y,z; public:

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