第五周 课后实践:阅读程序(1)(2)(3)
来源:互联网 发布:淘宝介入怎么操作 编辑:程序博客网 时间:2024/06/06 10:47
(1)问题及代码:
/** Copyright (c) 2014, 烟台大学计算机学院* All rights reserved.* 文件名称:Project4.cpp* 作 者:陈旭* 完成日期:2015年4月 7日* 版 本 号:v1.0** 问题描述:阅读程序,写出程序的运行结果并理解* 输入描述:略* 程序输出:略*/#include <iostream>using namespace std;class base{private: int m;public: base() {}; base(int m){this->m=m;} int get(){return m;} void set(int m){this->m=m;}};//base_endint main(){ base *ptr; ptr=new base[2]; ptr->set(30); ptr=ptr+1; ptr->set(50); base a[2]= {1,9}; cout<<a[0].get()<<","<<a[1].get()<<endl; cout<<ptr->get()<<","; ptr=ptr-1; cout<<ptr->get()<<endl; delete[] ptr; return 0;}
运行结果:
(2)问题及代码:
#include<iostream>using namespace std;class CE{private: int a,b; int getmin(){return (a<b? a:b);}public: int c; void SetValue(int x1,int x2, int x3) { a=x1; b=x2; c=x3; } int GetMin();};int CE::GetMin(){ int d=getmin(); return (d<c? d:c);}int main(){ int x=5,y=12,z=8; CE *ep; ep=new CE; ep->SetValue(x+y,y-z,10); cout<<ep->GetMin()<<endl; CE a=*ep; cout<<a.GetMin()*3+15<<endl; return 0;}
运行结果:
(3)问题及代码:
#include <iostream>using namespace std;class Time{public: Time(int,int,int); void output_time( ); int hour; int minute; int sec;};Time::Time(int h,int m,int s){ hour=h; minute=m; sec=s;}void Time::output_time( ){ cout<<hour<<":"; cout<<minute<<":" <<sec<<endl;}int main( ){ Time t1(10,13,56); int *p1=&t1.hour; //指向数据成员的指针 cout<<*p1<<endl; t1.output_time( ); Time *p2=&t1; //指向对象的指针 p2->output_time( ); void (Time::*p3)( ); //指向成员函数的指针 p3=&Time::output_time; (t1.*p3)( ); return 0;}
运行结果:
0 0
- 第五周 课后实践--阅读程序(2)
- 第五周 课后实践:程序阅读(1)
- 第五周 课后实践:阅读程序(1)(2)(3)
- 第五周 课后实践--阅读程序(3,4,5,6)
- 第十二周 课后实践:阅读程序(1)(2)
- 第五周 课后实践:阅读程序(4)(5)(6)
- 第五周课后实践:阅读程序
- 第十二周 课后实践:程序阅读(3)(4)
- 第二周 课后实践:阅读程序(2)
- 第二周课后实践:阅读程序(2)
- 第二周--课后实践:阅读程序(2)
- 第二周 课后实践 程序阅读(2)
- 第二周 课后实践:阅读程序(1)
- 第二周课后实践:阅读程序(1)
- 第二周--课后实践:阅读程序(1)
- 第十一周 课后实践:阅读程序(1)(2)
- 第八周 课后实践:程序阅读(1)(2)(3)(4)
- 第2周项目-课后实践·阅读程序(1)
- android edittext 点击回车会响应两次的解决方案
- OpenCv中用hough变换检测直线,有图有真相
- hdu 2052 Picture
- python-pygame 安装
- 中国人的一天
- 第五周 课后实践:阅读程序(1)(2)(3)
- sql 删除重复行
- 解决android sdk 下载问题
- 八皇后问题,Java实现,可推广解决N皇后问题
- 【图说word】宏二
- 二维数组中的查找
- 实现购物车多物品数量 总价计算
- sql 内连接和外链接
- NYOJ 题目587 blockhouses(二分图最大匹配)