2015东南大学计算机系复试C++自己做的题解
2016-03-17 22:22
239 查看
明天就是复试的笔试环节,先做了去年的笔试题,除了没看懂题目的第三题,其他都做出来了。
这是题目:
第一题:
第二题:
第四题:
第五题:
这是题目:
第一题:
#include<iostream> #include<iomanip> #include<cmath> using namespace std; int main() { double x,i=1.0; double temp=1.0,sum=1.0,temp1=0.0; cin>>x; while(1) { temp1=temp; temp*=x/i; sum+=temp; ++i; //cout<<temp<<" "<<temp1<<" "<<i<<endl; if(fabs(temp-temp1)<=1e-7 && temp != temp1) break; } cout<<setprecision(10)<<std::fixed<<sum<<endl; }
第二题:
#include<iostream> using namespace std; void func(string s,int length) { if(length>=0) { if(s[length-1]<='9' && s[length-1]>='0') { cout<<s[length-1]; func(s,length-1); } else { func(s,length-1); } } } int main() { string s; getline(cin,s); func(s,s.length()); return 0; }
第四题:
#include<iostream> #include<string> using namespace std; void FindRepStr(char str[] , const char findStr[] , const char replaceStr[]) { string s1(str),s2(findStr),s3(replaceStr); int pos; pos = s1.find(s2); while(pos!=-1) { s1.replace(pos,s2.length(),s3); pos = s1.find(s2); } cout<<s1<<endl; } int main() { //cin输入字符串太麻烦了,偷个懒 char * str = "helloworld"; char * s2 = "l"; char * s3 = "app"; FindRepStr(str , s2 , s3); return 0; }
第五题:
#include<iostream> #include<string> using namespace std; class Teacher { public : int number; string name; string sex; int birthday; int inday; //构造函数 Teacher(int Number,string Name,string Sex, int Birthday=19000000,int Inday) { number = Number; name = Name; sex = Sex; birthday = Birthday; inday = Inday; cout<<"编号为:"<<number<<" 姓名为:"<<name<< " 性别为:"<<sex<<" 生日为:"<<birthday <<" 入职日期为:"<<inday<<endl; } //复制构造函数 Teacher(const Teacher &t) { number = t.number; name = t.name; sex = t.sex; birthday = t.birthday; inday = t.inday; } //2016是否退休 bool Retire_2016() { if(((2016 - birthday/10000) > 55 && sex == "male") ||(((2016 - birthday/10000) > 60) && sex == "female")) { cout<<"应退休的教师姓名为: "<<name<<" 编号为: "<<number<<endl; return true; } else return false; } //是否继续聘用女教师 bool Continue_retire_female() { if( (2016 - birthday/10000) > 60 && sex == "female" && (2016 - inday/10000) < 35) { cout<<"继续聘用的女教师姓名为:"<<name<<" 编号为: "<<number<<endl; return true; } else return false; } }; int main() { int number,birthday,inday; string name,sex; //自己选择测试数据的数量 int n; cin>>n; for(int i=0;i<n;i++) { cin>>number>>name>>sex>>birthday>>inday; Teacher t(number,name,sex,birthday,inday); if(t.Retire_2016()) { //cout<<"应退休的教师姓名为: "<<t.name<<" 编号为: "<<t.number<<endl; if(t.Continue_retire_female()) //cout<<"继续聘用的女教师姓名为:"<<t.name<<" 编号为: "<<t.number<<endl; continue; } } //测试复制构造函数 Teacher t(number,name,sex,birthday,inday); Teacher t2(t); cout<<t2.name<<" "<<t2.number<<endl; return 0; }
相关文章推荐
- HTTP协议1之协议详解--转
- scapy实现一个端口扫描器(基于tcp三次握手扫描)——简析
- 《python计算机视觉编程》读书笔记------1
- iOS开发网络篇—监测网络状态
- 数组中的逆序对
- 二叉树的深度
- 平衡二叉树
- 丑数
- 连续子数组的最大和
- 数组中出现次数超过一半的数字
- 二叉搜索树的后序遍历序列
- TCP报文大小
- 计算机网络——9.IPv6基础
- TCP与UDP的区别及其报头结构
- Android volley 使用OkHttp3.0
- IOS 网络浅析-(四 get&post)
- TCP实现聊天室
- 数据结构(java语言描述)顺序栈的使用
- 一.OSI与TCP
- linux c/c++网络编程----select模型