成绩查询程序

来源:互联网 发布:2011伤感网络歌曲大全 编辑:程序博客网 时间:2024/05/15 18:12

该成绩查询软件安装包

链接: http://pan.baidu.com/s/1mg9xsEk 密码: f839

实现功能:

1 检查用户是否存在:若不存在,则输出用户不存在;若存在,则检查学号是否正确:若正确,则输出成绩,若不正确,则输出学号不正确;

2 实现从文本读取用户名、学号、成绩。

3 一个按钮实现查询,一个实现重新输入,一个实现退出程序

本程序的三个文本:

这里写图片描述

这里写图片描述

这里写图片描述

效果图:

1 用户不存在

这里写图片描述

2 学号不正确

这里写图片描述

3查询成功

这里写图片描述

代码如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace chaxun{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            l4.Text = "";//初始化提示标签l4        }        private void label2_Click(object sender, EventArgs e)        {        }        private void label3_Click(object sender, EventArgs e)        {        }        private void button1_Click(object sender, EventArgs e)        {            String name1 = System.IO.Directory.GetCurrentDirectory() + "//name.txt";//读取文本,本程序文本路径E:\C++程序\chaxun\chaxun\bin\Debug,下同!            String num1= System.IO.Directory.GetCurrentDirectory() + "//num.txt";            String grade1 = System.IO.Directory.GetCurrentDirectory() + "//grade.txt";            String[] na =File.ReadAllLines(name1, Encoding.Default);            String[] nu = File.ReadAllLines(num1, Encoding.Default);            String[] gr = File.ReadAllLines(grade1, Encoding.Default);            int i = 0,k=0;//k=0初始化用户不存在!            do            {                if (t1.Text == na[i])                {                    if (t2.Text == nu[i])//用户存在                    {                        t3.Text = gr[i];                        l4.Text = "查询成功!";                        k = 1;                    }                    else//学号不正确                    {                        k = 2;                        l4.Text = "";                    }                }                i++;            } while (i<=na.Length-1);            if(k!=1)            switch (k)            {                case 0: l4.Text = "用户不存在!"; break;//判断出用户不存在!                case 2:l4.Text = "学号不正确!";break ;//判断出学号不正确!            }        }        private void button2_Click(object sender, EventArgs e)        {            Application.Exit();//退出按钮        }        private void button3_Click(object sender, EventArgs e)//重新输入按钮        {            t1.Text = "";            t2.Text = "";            t3.Text = "";            l4.Text = "";            t1.Focus();        }    }}
0 0