留学问答

编写一个控制台应用程序项目Proj6-18用于求学生的GPAGPA是英文平均分的简称美国大学的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;elses = 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} 姓名:{1}", sno, sname);Console.WriteLine(" 课程名 学分 分数");for (int i = 0; i< course.Length; i++)Console.WriteLine(" {0} {1} {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();}}}

当然了,看完上述的分析觉得还不够尽兴的话,也可以再看看大家大盈之家2.0养老年金险的收益评测,再下投保结论:

全网同号:留学查一查,欢迎搜索!


花更少的钱,买对的留学

为你寻找性价比最高的产品

热点问题

最新问题

留学问题标签

美国留学中介
出国留学申请
加拿大留学中介
澳洲留学中介
英国留学中介

请关注留学查一查公众号
咨询客服为您进行顾问预约登记


点击微信 -> 发现 -> 扫一扫
扫描上方二维码进行关注