题目要求如下:
---------------------------------------------------------------------------------------------------------------------------
代码如下:
/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者: 沈远宏
* 完成日期:2014 年06月18日
* 版 本 号:v1.0
* 问题描述:Description
建立一个对象数组,内放n(n<10)个学生的数据(学号、成绩),用指针指向数组首元素,输出第奇数(1,3,5,7)个学生的数据。
Input
n和n个学生的学号、成绩
Output
奇数学生的数据
*/#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;
class Student
{
private:
string no;
double score;
public:
void input()
{
cin>>no>>score;
}
void display()
{
cout<<no<<" "<<score<<endl;
}
};
//主函数已给定如下,提交时不需要包含下述主函数
int main()
{
const int NUM=10;
Student stud[NUM];
int n,i;
freopen("12.txt","r",stdin);
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要求结果输出例样: