第九天学习内容 结构体
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace day09
{
class Program
{
struct student
{
public int no;
public string name;
public int csharp;
public int web;
public int database;
public int sum;
public info xinxi;
public int[] shuzu;
}
struct info
{
public string jiguan;
public string dianhua;
}
enum meiju: int
{
one=3,
two=6,
three,
four=two,
}
static void Main(string[] args)
{
//用哈希表录入学生信息计算总分和平均分,并输出不及格的学生信息
/* Hashtable ht = new Hashtable();
Console.Write("请输入学生人数:");
int num = Convert.ToInt32(Console.ReadLine());
double sum = 0;
for (int i = 0; i < num; i++)
{
ArrayList cjb = new ArrayList(); //新建名为cjb的集合 每循环一次就新建一个cjb的集合
Console.Write("请输入学生姓名:");
cjb.Add(Console.ReadLine()); //为其中第一个元素赋值为学生姓名
Console.Write("请输入学生成绩:");
cjb.Add(Console.ReadLine()); //为其中第二个元素赋值为学生成绩
ht.Add(i,cjb); //为哈希表赋值,key为循环次数,values为cjb这个集合
sum += Convert.ToDouble(cjb[1]); //计算总分
}
Console.WriteLine("学生的总成绩为"+sum+","+"平均成绩为"+(sum/num));
//IDictionaryEnumerator ide = ht.GetEnumerator();
//while (ide.MoveNext())
//{
// Console.WriteLine(ide.Key+" "+ide.Value); //枚举类型,全部读取
//}
foreach (ArrayList cjb in ht.Values)
{
if (Convert.ToDouble(cjb[1]) < 60) //判断cjb集合中学生成绩小于60的
{
Console.WriteLine("不及格的学生姓名为" + cjb[0] + "," + "成绩为" + cjb[1]); //输出
}
}
//用结构体录入学生信息并打印
student xs = new student();
Console.Write("请输入人数:");
int n = Convert.ToInt32(Console.ReadLine());
ArrayList al = new ArrayList();
for (int i = 0; i < n; i++) //循环输入学生信息
{
Console.Write("请输入学生学号:");
xs.no = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生姓名:");
xs.name = Convert.ToString(Console.ReadLine());
Console.Write("请输入学生c#成绩:");
xs.csharp = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生web成绩:");
xs.web = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生数据库成绩:");
xs.database = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生的籍贯:");
xs.xinxi.jiguan = Convert.ToString(Console.ReadLine());
Console.Write("请输入学生的电话号码:");
xs.xinxi.dianhua = Convert.ToString(Console.ReadLine());
xs.shuzu = new int[2];
xs.shuzu[0] = 1;
xs.shuzu[1] = 2; //定义了一个新数组并赋值
xs.sum = xs.csharp + xs.web + xs.database;
al.Add(xs); //将输入的学生信息赋值给al集合中的第i个元素
}
for (int i = 0; i < n; i++)
{
student temp = (student)al[i]; //将al集合类型强制转换成student类型,并复制给temp
Console.WriteLine("学号:"+temp.no+"\t姓名:"+temp.name+"\tc#成绩:"+temp.csharp+"\tweb成绩:"+temp.web+"\t数据库成绩:"+temp.database+"\t籍贯:"+temp.xinxi.jiguan+"\t电话号码"+temp.xinxi.dianhua+"\t总成绩:"+temp.sum+temp.shuzu[1]);
}
*/
Console.ReadKey();
}
}
}