C++课后习题
文章平均质量分 69
qingyu66
这个作者很懒,什么都没留下…
展开
-
第二题 P033
#includeusing namespace std;int main(){ int a,b,c; a=10; b=23; c=a+b; cout<<"a+b="; cout<<c; cout<<endl; return 0;}转载 2015-05-27 08:39:02 · 180 阅读 · 0 评论 -
Time Date DateTime的继承与派生及运算符重载
#include class Time{ public: Time(){} Time(int h,int m,int s) { hour=h; minute=m; second=s; } friend istream & operator>>(istream &,Ti原创 2015-06-23 18:55:17 · 359 阅读 · 0 评论 -
第七章
1.#include #include using namespace std; void area(float a,float b,float c) { double s,area; if(a+b<=c) cerr<<"a+b<=c,error!"<<endl; else if(b+c<=a) cerr<<"b+原创 2015-06-23 18:53:41 · 196 阅读 · 0 评论 -
第六章
1. #include class Point {public: Point(float x=0,float y=0); void setPoint(float,float); float getX() const {return x;} float getY() const {return y;}原创 2015-06-23 18:52:33 · 234 阅读 · 0 评论 -
第五章
#include using namespace std; class Student{ public: void get_value() {cin>>num>>name>>sex;} void display() { cout<<"num:"<<num<<endl; cout<<"name:"<<na原创 2015-06-23 18:51:11 · 210 阅读 · 0 评论 -
第四章
1.#include using namespace std; class Complex{ public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; i原创 2015-06-23 18:48:51 · 178 阅读 · 0 评论 -
第三章
3.#include using namespace std; class Date { public: Date(int=1,int=1,int=2005); void display(); private: int month; int day; int year; }; Date转载 2015-06-23 18:42:22 · 201 阅读 · 0 评论 -
第八题 P035
#include using namespace std;int main(){ int a,b; cout<<"Please input two numbers:"<<endl; cin>>a>>b; int &x=a; coutb?x:b)<<endl; return 0;}转载 2015-06-05 15:53:34 · 297 阅读 · 0 评论 -
第九题 P035
#include using namespace std;int main(){ int x=1,y=5,z=8; int swap(int &a,int &b,int &c); swap(x,y,z); return 0;}int swap(int &a,int &b,int &c){ int temp; if(a<b) { temp=a;a=b;b=temp;} if原创 2015-06-05 15:57:09 · 260 阅读 · 0 评论 -
第一题 P066
#include using namespace std;class Time{ public: void set_time(void); void show_time(void); private: int hour; int minute; int sec;};Time t;int main(void){ t.set_time(); t.show_ti原创 2015-06-10 06:57:23 · 256 阅读 · 0 评论 -
第二题 P067
#include using namespace std;class Time{ public: void set_time() { cin>>hour; cin>>minute; cin>>sec; } void show_time() { cout<<hour<<":"<<minute<<":"<<sec<<endl; } privat原创 2015-06-10 07:39:15 · 245 阅读 · 0 评论 -
第三题 P067
#include using namespace std;class Time{ public: void set_time(); void show_time(); private: int hour; int minute; int sec;};int main(){ Time t1; t1.set_time(); t1.show_time();原创 2015-06-10 07:47:51 · 231 阅读 · 0 评论 -
用一个异质链表(多态性)保存学生数据
#include #include using namespace std; class Student { public: virtual void get()=0; virtual void display()=0; string name; string num; }; class UnderG原创 2015-06-23 18:56:14 · 299 阅读 · 0 评论 -
三角形
//扩展程序:创建一个三角形类//修改create_object函数,使得程序支持三角形的创建//和求面积、打印等操作#include #include using namespace std;class Shape { public: virtual double getArea() const =0; virtual void print() const =0;原创 2015-06-23 19:17:32 · 232 阅读 · 0 评论 -
第四题 P034
#includeusing namespace std;int main(){ int a=1,b=2,c; c=a+b; cout<<"a+b="<<a+b;}转载 2015-05-27 08:54:49 · 206 阅读 · 0 评论 -
第五题 P034
#include using namespace std;int add(int x,int y){ int z; z=x+y; return (z);}int main(){ int a=2,b=44,c; c=add(a,b); cout<<"a+b="<<c<<endl; return 0;}转载 2015-05-27 09:10:16 · 245 阅读 · 0 评论 -
第三题 P033
#include using namespace std;int main(){ int a,b,c; int f(int x,int y,int z); cin>>a>>b>>c; c = f(a,b,c); cout<<c<<endl; return 0;}int f(int x,int y,int z){ int m; if(x<y) m=x; else m=转载 2015-05-27 08:47:43 · 207 阅读 · 0 评论 -
第七题 P035
#includeusing namespace std;int main(){ int max(int x,int y); int a; cin>>a; cout<<"Max="<<max(a,3)<<endl; return 0;}int max(int x,int y){ return x>y?x:y;}原创 2015-05-27 09:45:25 · 225 阅读 · 0 评论 -
第一题 p033
#include using namespace std;int main(){ coutcoutcoutreturn 0;}转载 2015-05-27 08:17:12 · 198 阅读 · 0 评论 -
第十题 P035
#include using namespace std;#include int main(){ string str1="chensheng ",str2="cool !" ,str; str=str1+str2; cout<<str<<endl; return 0;}原创 2015-06-05 16:05:22 · 201 阅读 · 0 评论 -
第十一题 P035
#include #include using namespace std;int main(){ int i; string str="LIGHT"; for(i=4;i>=0;i--) { cout<<str[i]; } cout<<endl; return 0;}原创 2015-06-05 16:14:48 · 204 阅读 · 0 评论 -
第十二题 P035
#include #include using namespace std;int main(){ int i,j; string temp; string str[5]={ "chen","sheng","is","very","cool"}; for(i=0;i<5;i++) { for(j=i;j<5;j++) { if(str[i]<str[j]) {原创 2015-06-05 16:38:11 · 180 阅读 · 0 评论 -
第十四题 P035
#include using namespace std;templateT bubblesort(T a ,int n){ bool sorted = false; while(!sorted) { sorted = true; for(int i=0;i<n-1;++i) { if(a[i]>a[i+1]) { swap( a[i],a[i+原创 2015-06-06 18:43:40 · 259 阅读 · 0 评论 -
第十三题 P035
#include using namespace std;int max(int max_i[10]) //求三个整数中最大者{ int temp; for(int i=0;i<10;i++) { for(int j=i;j<10;j++) { if(max_i[i]>max_i[j]) { temp=max_i[i]; max_i[i原创 2015-06-06 07:01:09 · 269 阅读 · 0 评论 -
第六题 P035
#include using namespace std;int main(){ int sort(int &x,int &y,int &z); int a,b,c; cout<<"Please input three numbers:"<<endl; cin>>a>>b>>c; sort(a,b,c); cout<<a<<','<<b<<','<<c<<endl; retur转载 2015-05-27 09:35:58 · 263 阅读 · 0 评论 -
第四章
1.#include using namespace std; class Complex{ public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; i原创 2017-03-29 11:27:33 · 190 阅读 · 0 评论