[YTU]_2432( C++习题 对象数组输入与输出)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_2432( C++习题 对象数组输入与输出)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Description
建立一個對象數(shù)組,內(nèi)放n(n<10)個學生的數(shù)據(jù)(學號、成績),用指針指向數(shù)組首元素,輸出第奇數(shù)(1,3,5,7)個學生的數(shù)據(jù)。
Input
n和n個學生的學號、成績
Output
奇數(shù)學生的數(shù)據(jù)
Sample Input
5 101 78.5 102 85.5 103 98.5 104 100.0 105 95.5Sample Output
101 78.50 103 98.50 105 95.50#include <iostream> #include <iomanip> using namespace std; class Student { public:void input();void display(); private:int xue;double score; }; void Student::input() {cin>>xue>>score; } void Student::display() {cout<<xue<<' '<<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; }《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的[YTU]_2432( C++习题 对象数组输入与输出)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2353 ( 长方柱类【C+
- 下一篇: [YTU]_2433( C++习题 对象