博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTA第三次上机
阅读量:6230 次
发布时间:2019-06-21

本文共 7412 字,大约阅读时间需要 24 分钟。

#include 
#include
#include
using namespace std;class polygon{ protected: int number; private: int side_length[100]; public: polygon(int a = 0):number(a){memset(side_length, 0, sizeof(side_length));}; int perimeter();//计算多边形边长 void display();//输出多边形边数和周长 int* reachsidelen();};int polygon::perimeter(){ int i; int tot = 0; for (i = 1; i <= number; i++) { tot += side_length[i]; } return tot;}void polygon::display(){ cout << number << " " << perimeter() << endl;}int* polygon::reachsidelen(){ return side_length;}class rectangle : protected polygon{ protected: int height; int width; public: rectangle(int a = 0, int b = 0, int c = 0):polygon(a), height(b), width(c){}; int perimeter();//计算矩形边长 void display();//输出多边形边数和周长};int rectangle::perimeter(){ int tot = 0; tot = height * 2 + width * 2; return tot;}void rectangle::display(){ cout << number << " " << perimeter() << endl;}class equal_polygon : protected polygon{ protected: int side_len; public: equal_polygon(int a = 0, int b = 0):polygon(a), side_len(b){}; int perimeter();//计算等边多边形边长 void display();//输出多边形边数和周长};int equal_polygon::perimeter(){ int tot = 0; tot = number * side_len; return tot;}void equal_polygon::display(){ cout << number << " " << perimeter() << endl;}int main(){ int b[105]; int i,j; int cnt = 0; cin >> cnt; int ope; while(cnt --) { memset(b, 0, sizeof(b)); cin >> ope; if(ope == 0) { int tot = 1; int idata; while(cin >> idata) { if(idata == -1)break; b[tot++] = idata; } tot --; polygon P(tot); int *p = P.reachsidelen(); for (i = 1; i <= tot; i++) { *(p + i) = b[i]; } P.display(); } else if(ope == 1) { int iwide, ilen; cin >> iwide >> ilen; rectangle R(4, ilen, iwide); R.display(); } else if(ope == 2) { int inumber, ilen; cin >> inumber >> ilen; equal_polygon E(inumber, ilen); E.display(); } } return 0;}

#include 
#include
#include
using namespace std;class Point_1D{ protected: float x;//1D 点的x坐标public: Point_1D(float a = 0): x(a){}; float distance( );//计算当前点到原点的距离};float Point_1D::distance(){ float d = x; if(d < 0) d = -d; return d;}class Point_2D : protected Point_1D{ protected: float y; public: Point_2D(float a = 0, float b = 0): Point_1D(a), y(b){}; float distance( );};float Point_2D::distance(){ float d; d = sqrt(x * x + y * y); return d;}class Point_3D : protected Point_2D{ protected: float z; public: Point_3D(float a = 0, float b = 0, float c = 0): Point_2D(a, b), z(c){}; float distance( );};float Point_3D::distance(){ float d; d = sqrt(x * x + y * y + z * z); return d;}int main(){ int ope; while(cin >> ope) { if(ope == 0)break; if(ope == 1) { float ix; cin >> ix; Point_1D p1(ix); cout << "Distance from Point " << ix << " to original point is " << p1.distance() << endl; } else if(ope == 2) { float ix, iy; cin >> ix >> iy; Point_2D p2(ix, iy); cout << "Distance from Point(" << ix << "," << iy << ") to original point is " << p2.distance() << endl;; } else if(ope == 3) { float ix, iy, iz; cin >> ix >> iy >> iz; Point_3D p3(ix, iy, iz); cout << "Distance from Point(" << ix << "," << iy << "," << iz << ") to original point is " << p3.distance() << endl;; } } return 0;}

用了sstream,主函数太长了。。

#include 
#include
#include
using namespace std;class Date{ protected: int year; int month; int day; public: Date(int a = 0, int b = 0, int c = 0):year(a), month(b), day(c){};};class Time{ protected: int hour; int minute; int second; public: Time(int a = 0, int b = 0, int c = 0):hour(a), minute(b), second(c){};};class Schedule : protected Date, protected Time{ protected: int ID; public: Schedule(int y = 10000, int m = 0, int d = 0, int h = 0, int min = 0, int s = 0, int id = 0): Date(y, m, d), Time(h, min, s), ID(id){}; bool operator < (const Schedule & s2); void display();};void Schedule::display() //The urgent schedule is No.1: 2014/6/27 8:0:1{ cout << ID << ": " << year << "/" << month << "/" << day << " " << hour << ":" << minute << ":" << second << endl;}bool Schedule::operator < (const Schedule & s2){ int dtot1 = 0, tot1 = 0; int dtot2 = 0, tot2 = 0; dtot1 = year * 365 + month * 30 + day; dtot2 = s2.year * 365 + s2.month * 30 + s2.day; tot1 = hour * 3600 + minute * 60 + second; tot2 = s2.hour * 3600 + s2.minute * 60 + s2.second; if(dtot1 < dtot2)return true; else if(dtot1 > dtot2)return false; else { if(tot1 < tot2)return true; else return false; }}int main(){ int id; int i; int record; Schedule sch; while(cin >> id) { if(id == 0)break; string date, time; cin >> date >> time; stringstream stream; string s1, s2; int y = 0, m = 0, d = 0, h = 0, min = 0, s = 0; bool flag = false; for(i = 0; i < date.length(); i++) { if(date[i] == '/') { if(flag) { stream << s1; stream >> m; stream.clear(); s1 = ""; } else { stream << s1; stream >> y; stream.clear(); s1 = ""; flag = true; } } else s1 += date[i]; } stream << s1; stream >> d; stream.clear(); bool flag2 = false; for(i = 0; i < time.length(); i++) { if(time[i] == ':') { if(flag2) { stream << s2; stream >> min; stream.clear(); s2 = ""; } else { stream << s2; stream >> h; stream.clear(); s2 = ""; flag2 = true; } } else s2 += time[i]; } stream << s2; stream >> s; stream.clear(); Schedule sch1(y, m, d, h, min, s, id); if(sch1 < sch)sch = sch1; } cout << "The urgent schedule is No."; sch.display(); return 0;}

转载地址:http://dwxna.baihongyu.com/

你可能感兴趣的文章
Java解决主从数据库延迟问题_MySQL主从数据库同步延迟问题解决
查看>>
java将jfif格式转换成ipg_jfif是什么格式?Win10将图片JFIF格式转成JPG格式的方法
查看>>
socket.io java 点对点_netty-socket.io点对点通讯和聊天室通讯
查看>>
python java thrift_Apache Thrift PythonJava“连接被拒绝”
查看>>
java测试邮箱是否_javaWEB邮件测试
查看>>
java里booelan_Java Web应用开发技术与案例教程 教学课件 张继军 第4章_JDBC数据库访问技术.ppt...
查看>>
php mysql记录用户行为_用户参与记录存储的演变_PHP教程
查看>>
python中使用缩进来体现代码之间的逻辑关系_Python使用缩进来体现代码之间的逻辑关系。...
查看>>
python图像对比度拉伸_python库skimage 图像直方图均衡化、自适应均衡化、对比度拉伸实现...
查看>>
java判断是不是disable_Java Compiler disable()方法与示例
查看>>
php 发送 二进制,PHP处理二进制数据的实现方法
查看>>
用php写上传文件的代码,php多文件上传实现代码
查看>>
php发送邮件怎么配置,php 配置smtp发送邮件
查看>>
java文件名要和什么一致,Java源程序的文件名一定要与文件中某个类的名称一致。...
查看>>
c php结合,腾讯熊月:企点将php嵌入到高性能C/C++框架运行的探索实践
查看>>
php图片克隆,php实现对象克隆的方法
查看>>
java myqq ui,用Java Swing写一个登录界面
查看>>
java添加录音,java录音程序
查看>>
php xml 没有报文头,解决php输出xml设置header头Content-type:text/xml的方法
查看>>
php简化URL路径,php – 修改(简化)主题标题以便在url中显示
查看>>