编写一个控制台应用程序项目Proj6-18用于求学生的GPA。GPA是英文平均分的简称。美国大学的GPA满分是4分。

编写一个控制台应用程序项目Proj6-18用于求学生的GPA。GPA是英文平均分的简称。美国大学的GPA满分是4分。,第1张

编写一个控制台应用程序项目Proj6-18用于求学生的GPA。GPA是英文平均分的简称。美国大学的GPA满分是4分。 using System;
using System.Collections.Generic;
using System.Text;
namespace Proj6_18
{
class Student
{
int sno;
string sname;
Course[] course;
int[] score;
double sgpa1;
double sgpa2;
public int psno
{
get
{ return sno; }
set
{ sno = value; }
}
public string psname
{
get
{ return sname; }
set
{ sname = value; }
}
public void setcourse(params Course[] course1)
{
course = new Course[course1.Length];
for (int i = 0; i < course1.Length; i++)
course[i] = course1[i];
}
public void setscore(int[] score1)
{
score = new int[score1.Length];
for (int i = 0; i < score1.Length; i++)
score[i] = score1[i];
}
public void computegpa()
{
int i;
double s, sumc = 0, sumgpa1 = 0, sumgpa2 = 0;
for (i = 0; i < score.Length; i++)
{
if (score[i] >= 90)
s = 4.0;
else if (score[i] >= 80)
s = 3.0;
else if (score[i] >= 70)
s = 2.0;
else if (score[i] >= 60)
s = 1.0;
else
s = 0.0;
sumgpa1 += course[i].pcredits * s;
sumgpa2 += course[i].pcredits * score[i];
sumc += course[i].pcredits;
}
sgpa1 = sumgpa1 / sumc;
sgpa2 = sumgpa2 * 4 / sumc / 100;
}
public void dispstud() //输出学生e68a84e8a2ade799bee5baa6e997aee7ad9431333335313863信息
{
Console.WriteLine("学号:{0}\t姓名:{1}", sno, sname);
Console.WriteLine(" 课程\t学分\t分数");
for (int i = 0; i < course.Length; i++)
Console.WriteLine(" {0}\t{1}\t{2}", course[i].pcname, course[i].pcredits, score[i]);
}
public void dispgpa() //输出GPA
{
Console.WriteLine("常见算法GPA={0:n},标准算法GPA={1:n}", sgpa1, sgpa2);
}
}
class Course
{
string cname;
int credits;
public Course() { }
public Course(string name, int xf)
{
cname = name;
credits = xf;
}
public string pcname
{
get
{ return cname; }
set
{ cname = value; }
}
public int pcredits
{
get
{ return credits; }
set
{ credits = value; }
}
}
class Program
{
static void Main(string[] args)
{
Course[] course1 = new Course[] {new Course("课程1",4),new Course("课程2",3),
new Course("课程3",2),new Course("课程4",6),new Course("课程5",3)};
int[] score1 = new int[] { 92, 80, 98, 70, 89 };
Student s1 = new Student();
s1.psno = 1; s1.psname = "王华";
s1.setcourse(course1);
s1.setscore(score1);
s1.computegpa();
s1.dispstud();
s1.dispgpa();
}
}
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/3706646.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-15
下一篇 2022-10-15

发表评论

登录后才能评论

评论列表(0条)

保存