哥的第一个C++
哥人生的第一个C++,麻烦的类啊。。
#include<iostream> #include<cmath> #include<cstdlib> #include<cstring> using namespace std; class Cs { public: float Ave( ); void Print( ) { cout<<"姓名"<<name<<endl; cout<<"学号"<<No<<endl; cout<<"课程成绩:"<<score[0]<<" "<<score[1]<<" "<<score[2]<<endl; cout<<"平均成绩:"<<ave<<endl; } void setname( char str[] ) { strcpy( name,str ); } void setNo( char str[] ) { strcpy( No,str ); } void setscore( float s1,float s2,float s3 ) { score[0] = s1,score[1] = s2,score[2] = s3; } private: char name[20],No[10]; private: float score[3],ave; }; float Cs::Ave( ) { ave = ( score[0] + score[1] + score[2] ) / 3; return ave; } int main( ) { Cs one,*stu; stu = &one; one.setname( "Lili" ); one.setNo( "10408200314" ); one.setscore( 1,2,3 ); one.Ave(); one.Print( ); system( "pause" ); return 0; }
本人还是新手 ,转载请注明来自Lvsi‘s home