oj刷(1)4对象数组
2015-06-29 16:58
148 查看
建立一个对象数组,内放n(n<10)个学生的数据(学号、成绩),用指针指向数组首元素,输出第奇数(1,3,5,7)个学生的数据。
Input
n和n个学生的学号、成绩Output
奇数学生的数据#include <iostream> #include<iomanip> using namespace std; class Student { public: Student(int n=0,double s=0):num{n},score(s){} void input(); void display(); private: int num; double score; }; void Student::input() { cin>>num>>score; } void Student::display() { cout<<num<<" "<<score<<endl; } int main() { const int NUM=10; Student stud[NUM]; int n,i; cin>>n; for(i=0; i<n; i++) stud[i].input(); cout<<setiosflags(ios::fixed); cout<<setprecision(2); Student *p=stud; for(i=0; i<n; p+=2,i+=2) p->display(); return 0; }
相关文章推荐
- 第十六周oj刷题——Problem G: E2 驾驭const
- JS中getElementById()、getElementsByName()、getElementsByTagName()_的区别和应用
- talend hive数据导入到mysql中
- Win7下chm文件无法打开问题解决方法
- Redhat6 双网卡绑定
- 使用websocket发送图片文件
- 日志框架实现实时修改,实时生效,具体框架思路(7)
- css3实现web app翻页过度效果
- NN(BP)算法
- C/C++求职宝典21个重点笔记(常考笔试面试点)
- 手机 Fildder真机抓包
- passing the word
- php基础教程-必备基础知识
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
- Interview Q&A - Java中sleep()和wait()有什么区别
- JAVA之关于This的用法
- [转]剑指offer面试题总结
- NDK 10分钟入门教程
- MySQL表空间的碎片整理
- poj 2777