[YTU]_2432 (C++习题 对象数组输入与输出)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_2432 (C++习题 对象数组输入与输出)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目描述
建立一個對象數(shù)組,內(nèi)放n(n<10)個學(xué)生的數(shù)據(jù)(學(xué)號、成績),用指針指向數(shù)組首元素,輸出第奇數(shù)(1,3,5,7)個學(xué)生的數(shù)據(jù)。
輸入
n和n個學(xué)生的學(xué)號、成績
輸出
奇數(shù)學(xué)生的數(shù)據(jù)
樣例輸入
5 101 78.5 102 85.5 103 98.5 104 100.0 105 95.5樣例輸出
101 78.50 103 98.50 105 95.50#include <iostream> #include <iomanip> using namespace std; class Student { public:void input();void display();int name;double score; }; void Student::input() {cin>>name>>score; } void Student::display() {cout<<name<<' '<<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;總結(jié)
以上是生活随笔為你收集整理的[YTU]_2432 (C++习题 对象数组输入与输出)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2499( 处理成绩(c++
- 下一篇: [YTU]_2383 ( 矩形类定义【C