
学生信息管理系统的数据结构程序设计源程序,用链表实现
#include
#include
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student *next;
};
int n;
struct student *creat()
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student*) malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNow, these %d records are:\n",n);
p=head;
if(head!=NULL)
do
{
printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if (head==NULL) {printf("\nlist null!\n");
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("%ld not been found!\n",num);
return(head);
}
struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{
head=p0;p0->next=NULL;
}
else
{
while((p0->num>p1->num) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->numnum)
{
if(head==p1) head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;p0->next=NULL;
}
}
n=n+1;
return(head);
}
void main()
{
while(1)
{
struct student *head,stu;
long del_num;
printf("intput records:\n");
head=creat();
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
head=del(head,del_num);
print(head);
printf("\ninput the inserted record:");
scanf("%ld,%f",&stu.num,&stu.score);
head=insert(head,&stu);
print(head);
}
}
求一份学生管理系统课程设计报告,数据结构课程设计
为什么要中间拿那么多空格隔开呢?逗号或“|”都比那好弄。 如果这题是老师出的,老师一定脑袋有问题。 //============== 效果图查询自己写 需要的控件 private System.Windows.Forms.Button button1; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.RichTextBox richTextBox2; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; 后台 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Text;using System.IO; namespace WindowsFormsApplication1{ public partial class cj : Form { public StreamWriter SW; public cj() { InitializeComponent(); string Header = "姓名" + " " + "学号" + " " + "语文" + " " + "数学" + " " + "英语" + "\n"; richTextBox1.AppendText(Header); richTextBox2.AppendText(Header); CheckDirectory(); } private void button1_Click(object sender, EventArgs e) { string strFile; strFile = System.Windows.Forms.Application.StartupPath + "\\3.txt"; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "文本文件(*.txt)|*.txt"; openFileDialog1.DefaultExt = "txt"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string FileName = openFileDialog1.FileName; if (Path.GetExtension(FileName) != ".txt") { MessageBox.Show("格式不对"); } else { FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); StreamReader sReader = new StreamReader(openFileDialog1.FileName, Encoding.Default); if (sReader.ReadLine().Split('\n').Length > 0) { richTextBox1.AppendText(sReader.ReadToEnd()); } richTextBox1.AppendText("\n"); // StreamWriter ssw = new System.IO.StreamWriter(FileName, true, System.Text.Encoding.Default); } } } private void WriteLog(string msg) { string strFile; strFile = System.Windows.Forms.Application.StartupPath + "\\data\\3.log"; // StreamWriter SW; try { SW = new System.IO.StreamWriter(strFile, true); SW.WriteLine(msg); } catch (Exception ex) { WriteLog(ex.Message); } finally { SW.Flush(); SW.Close(); } } private void button2_Click(object sender, EventArgs e) { richTextBox1.Text = "姓名" + " " + "学号" + " " + "语文" + " " + "数学" + " " + "英语" + "\n"; } private void CheckDirectory() { if (Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\data") == false) { Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\data"); } if (Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\data") == false) { Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\data"); } } private void button3_Click(object sender, EventArgs e) { string rowdata = ""; int m = richTextBox1.Lines.Length; string[] lines = new string[m]; for (int i = 1; i < m-1; i++) //每一行 { lines[i] = richTextBox1.Lines[i]+"\n"; string[] cj = lines[i].Split(' '); if (cj != null) { rowdata = " "; for (int j = 0; j < cj.Length; j++) //每一列 { if (cj[j].ToString() != "") { rowdata = rowdata + cj[j].ToString()+","; } } rowdata.TrimEnd(','); string[] ncj = rowdata.Split(','); string str2 = ncj[2].ToString(); string str3 = ncj[3].ToString(); string str4 = ncj[4].ToString().TrimEnd('\n'); // if ((int.Parse(str2) + int.Parse(str3) + int.Parse(str4) < 180)) if ((int.Parse(str2)<60 || int.Parse(str3)<60 || int.Parse(str4) < 60)) { richTextBox2.AppendText(lines[i]); } } } if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\data\\3.txt") == true) { File.Delete(System.Windows.Forms.Application.StartupPath + "\\data\\3.txt"); } File.AppendAllText(System.Windows.Forms.Application.StartupPath + "\\data\\3.txt", richTextBox1.Text); if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\data\\4.txt") == true) { File.Delete(System.Windows.Forms.Application.StartupPath + "\\data\\4.txt"); } File.AppendAllText(System.Windows.Forms.Application.StartupPath + "\\data\\4.txt", richTextBox2.Text); MessageBox.Show("数据合成OK,在data文件夹"); } } }