- # include <iostream.h>
- int fun(double & ave,int & zxf)
- {
- int n,x,xf;
- double sum=0.0;
- n=0;
- zxf=0;
- do
- {
- cout<<"请输入某门功课成绩(输入负数表示所有功课输入结束):";
- cin>>x;
- cout<<"请输入该门功课的学分:";
- cin>>xf;
- sum+=x*xf;
- zxf+=xf;
- n++;
- }while(x>=0);
- ave=sum/zxf;
- return n-1;
- }
- void main()
- {
- double a;int xf;
- cout<<endl;
- cout<<"功课总门数为:"<<fun(a,xf)<<endl;
- cout<<"总学分为:"<<xf<<" ";
- cout<<" 总平均分="<<a<<endl;
- }