問題定義:設計一個網頁,輸入學生的詳細信息,如學生ID、姓名、性別、流、任意3個科目的分數,根據大學規則計算總分、百分比、成績并顯示。對于這個程序,我制作了 1 個類 Student.cs 來初始化所有變量,但我的顯示 percen() 無法正常工作學生using System;using System.Collections.Generic;using System.Linq;using System.Web; public class Student {int id;string name;string gender;string stream;int[] marks;public int[] Marks1{ get { return marks; } set { marks = value; }}public Student( int id,string name,string gender,string stream,int[] marks){ this.id = id; this.name = name; this.gender = gender; this.stream = stream; this.marks = marks;}public int Id{ get { return id; } set { id = value; }}public string Name{ get { return name; } set { name = value; }}public int[] Marks{ get { return marks; } set { marks = value; }}public string Gender{ get { return gender; } set { gender = value; }}public string Stream{ get { return stream; } set { stream = value; }}public string toString(){ return "name = "+name+"Id - "+id+"gendre = "+gender+"stream = "+stream+"marks - "+marks;}public int calc_total(int []marks){int arr; arr = marks[0] + marks[1] + marks[2]; return arr;} public int persent(int total) { int p = (total / 300) * 100; return p; } }
1 回答

鳳凰求蠱
TA貢獻1825條經驗 獲得超4個贊
只需修改代碼:
public int persent(int total)
{
int p = (total * 100) / 300;
return p;
}
- 1 回答
- 0 關注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消