#include using namespace std; class score{ private: int id; string name; int usual_score; int final_score; int total_score; public: score(int i=0,string n="",int u=0,int f=0,int t=0):id(i),name(n),usual_score(u),final_score(f),total_score(t){count();} void count(){total_score=usual_score0.4+final_score0.6;} void ShowScore(){cout<<id<<" "<<name<<" "<<usual_score<<" "<<final_score<<" "<<total_score<<endl;} }; int main(){ score *p1=new score[3];//不带初始化的对象数组 score p2[3]={score(201701101,"Li Hongmei",90,80),score(201701102,"Zhang San",80,90),score(201701103,"Wang Wu",70,85)};//带初始化的静态对象数组 for(int i=0;i<3;i++){ p1[i]=score(201701100+i,"Tom",75,85); p1[i].ShowScore(); p2[i].ShowScore(); } delete []p1; return 0; }


原文地址: https://www.cveoy.top/t/topic/bKf8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录