1#include <iostream>2#include <cstring>3#include <stdio.h>4 using namespacestd;5 classstu{6 Private:7 Charname[ +];8 Charid[ +];9 intAge ;Ten intscore[4]; One intAvg_score; A Public: - voidGetDate (CharName[],CharId[],intAge ); - voidSCORE_AVRG (intScore1[],intScore2[],intScore3[],intscore4[]); the voidprintfdate (); - }; - - voidStu::getdate (CharName[],CharId[],intAge ) + { -strcpy (Name,name);//modification of member variables within a class using data transfer parameters + strcpy (id,id); AAge=Age ; at } - - voidstu::p rintfdate () - { -cout<<name<<","<<age<<","<<ID<<","<<avg_score<<Endl; - } in - voidSTU::SCORE_AVRG (intScore1[],intScore2[],intScore3[],intscore4[]) to { +Avg_score= (score1[0]+score2[0]+score3[0]+score4[0])/4; - } the * intMainintargcChar*argv[]) $ {Panax Notoginseng Charname[ +]; - Charid[ +]; the CharA; + intAge=0; A intscore[4]; theStu M;//In any case, you need to define a class's variables to modify the member functions of the class. +Cin.getline (Name, +,',');//here "," is the Terminator -Cin>>age>>A; $Cin.getline (ID, +,','); $cin>>score[0]>>a>>score[1]>>a>>score[2]>>a>>score[3]; -M.getdate (Name,id,age);//data modification variable, parameter array address -M.SCORE_AVRG (&score[0],&score[1],&score[2],&score[3]); the m.printfdate (); - return 0;Wuyi}
Using Cin.getline for C + + use examples