栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > 百科 > 教育

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

教育 更新时间: 发布时间: 百科归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

编写一个控制台应用程序项目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();
}
}
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/ask/201282.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号