Description

建立一个对象数组,内放n(n<10)个学生的数据(学号、成绩),用指针指向数组首元素,输出第奇数(1,3,5,7)个学生的数据。

Input

n和n个学生的学号、成绩

Output

奇数学生的数据

Sample Input

5101 78.5102 85.5103 98.5104 100.0105 95.5

Sample Output

101 78.50103 98.50105 95.50

#include<iostream>
#include<iomanip>
using namespace std;
class Student
{public:
void input();
void display();
private:
	int num;
	double cj;

};

void Student::input()
{
	cin>>num>>cj;
}
void Student:: display()
{cout<<num<<' '<<cj<<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;

}


相关文章:

  • 2021-11-06
  • 2021-09-07
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-10-10
猜你喜欢
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-06-13
  • 2021-08-27
  • 2021-10-01
相关资源
相似解决方案