设计一个控制台应用程序,定义若干个学生对象,每个学生对象包括学号、姓名、语文成绩、数学成绩和英语成

2022-04-13 教育 88阅读
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;

namespacestatictest

{
classStudent

{
intno;

stringname;

intdeg1;

intdeg2;

intdeg3;

staticintsum1=0;

staticintsum2=0;

staticintsum3=0;

staticintsn=0;

publicStudent(intn,stringna,intd1,intd2,intd3)
{

no=n;name=na;

deg1=d1;deg2=d2;deg3=d3;

sn++;

}

publicvoiddisp()

{//(double)(deg1+deg2+deg3)/3

Console.WriteLine("学号:{0}姓名:{1}语文:{2}数学:{3}英语:{4}平均分:{5:f}",no,name,deg1,deg2,deg3,(double)(deg1+deg2+deg3)/3);
}

publicstaticdoubleavg1(){return(double)sum1/sn;}

publicstaticdoubleavg2(){return(double)sum2/sn;}

publicstaticdoubleavg3(){return(double)sum3/sn;}

};

classprogram

{
staticvoidMain(string[]args)

{
Students1=newStudent(1,"王华",67,89,90);

Students2=newStudent(1,"黎明",68,90,91);

Students3=newStudent(1,"张兵",69,89,92);

Students4=newStudent(1,"王超",70,92,93);

Console.WriteLine("输出结果");

s1.disp();s2.disp();s3.disp();s4.disp();

Console.WriteLine("语文平均分:{0}数学平均分:{1}英语平均分:{2}",Student.avg1(),Student.avg2(),Student.avg3());
Console.ReadKey();
}

}

}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com