学生信息录入系统的插入,删除

    <fieldset>
        <legend>学生信息录入系统</legend>
        <div>
            <span>姓名:</span>
            <input type="text" placeholder="请输入姓名" v-model="newStudent.name">
        </div>

        <div>
            <span>年龄:</span>
            <input type="text" placeholder="请输入年龄" v-model="newStudent.age">
        </div>

        <div>
            <span>性别:</span>
            <select v-model="newStudent.sex">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div>
            <span>手机:</span>
            <input type="text" placeholder="请输入手机号码" v-model="newStudent.phone">
        </div>
        <button @click="createNewStudent()">创建新用户</button>
    </fieldset>
 
    <table>
        <thead>
            <tr>
                <td>姓名</td>
                <td>性别</td>
                <td>年龄</td>
                <td>手机</td>
                <td>删除</td>
            </tr>
        </thead>
        <tbody>
        <tr v-for="(p,index) in persons">
            <td>{{p.name}}</td>
            <td>{{p.sex}}</td>
            <td>{{p.age}}</td>
            
            <td>
                <button @click="deleteStudentMsg(index)">删除</button>
            </td>
        </tr>
        </tbody>
    </table>
</div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <script>
        new Vue({
            el:'#app',
            data:{
                persons:[
                    {name:'张三',age:20,sex:'男',},
                    {name:'李四',age:20,sex:'男',},
                    {name:'王五',age:20,sex:'男',},
                    {name:'赵六',age:20,sex:'女',},
                ],
                newStudent : {name:'',age:0,sex:'男',phone:''}
            },
            methods: {
                //创建一条新纪录
               createNewStudent(){
               
                    if(this.newStudent.name ==='') {
                        alert('姓名不能为空');
                        return;
                    }

                    
                    if(this.newStudent.age <= 0) {
                        alert('请输入正确的年龄');
                        return;
                    }

                    if(this.newStudent.phone ==='') {
                        alert('手机号码不正确');s
                        return;
                    }


                    //往数组中添加一条新纪录
                    this.persons.unshift(this.newStudent);
                    //清空记录
                    this.newStudent = {name:'',age:0,sex:'男',phone:''}
                },
                //删除一条学生记录
                deleteStudentMsg(index) {
                    this.persons.splice(index,1);
                }
            }
        });
    </script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <stdio.h> #include "string.h" int N,i; FILE *fp; struct student {char num[10]; char name[8]; char sex[5]; int age; char addr[15]; int score; }stu[100]; void input() /*输入学生数据的资料*/ {printf("Input the student data %d:\n",i+1); /*输入一个学生的数据*/ printf("NO.:"); scanf("%s",stu[i].num); /*输入号数*/ printf("name:"); scanf("%s",stu[i].name); /*姓名*/ printf("sex:"); scanf("%s",stu[i].sex); /*性别*/ printf("age:"); scanf("%d",&stu[i].age); /*年龄*/ printf("address:"); scanf("%s",stu[i].addr); /*家庭地址*/ printf("score:"); scanf("%d",&stu[i].score); /*分数*/ printf("\n"); } void add() /*在ouru的文件后添加学生数据*/ { if((fp=fopen("ouru","ab"))==NULL) /*以读写的二进制形式打开ouru文件*/ {printf("Cann't open the file\n"); return;} printf("How many data do you want:"); /*输入需要添加几个学生的数据和具体的资料*/ scanf("%d",&N); for(i=0;i<N;i++) /*向ouru文件中加入添加学生的数据的个数*/ input(); for(i=0;i<N;i++) if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) printf("File error\n"); fclose(fp); } void save() /*保存学生的数据到ouru文件中*/ { int i; if((fp=fopen("ouru","wb"))==NULL) /*打开ouru文件*/ {printf("Cann't open the file\n"); return;} for(i=0;i<N;i++) /*把学生的数据写入到ouru 文件中*/ if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) printf("File write error\n"); fclose(fp); } void insert() /*在ouru文件中插入学生的数据*/ {char positions[10]; int a,b; if((fp=fopen("ouru","r+"))==NULL) /*以读写打开ouru文件*/ {printf("Can not open file!"); return;} for(i=0;(fread(&stu[i],sizeof(struct student),1,fp))!=0;i++); /*读取文件并计算文件中有多少个学生的数据*/ printf("Which position do you want to insert:"); scanf("%s",positions); for(a=0;a<i;a++) /*确定插入的位置*/ if(strcmp(positions,stu[a].num)==0)break; a=a+1; fseek(fp,sizeof(struct student)*(a+1),0); /*将指针指向要插入位置的后一位*/ for(b=a;b<i;b++) fwrite(&stu[b],sizeof(struct student),1,fp); /*将插入后的学生数据向后移动一位*/ i=a; input(); fseek(fp,sizeof(struct student)*a,0); /*将指针指向要插入的位置*/ fwrite(&stu[a],sizeof(struct student),1,fp); /*将插入的数据保存到ouru文件里*/ fclose(fp);} void change() /*修改ouru文件中的某个学生的数据*/ { char positions[10]; if((fp=fopen("ouru","rb+"))==NULL) /*以读写打开二进制ouru文件*/ {printf("Can not open the file\n"); return;} printf("What data do you want to modify:"); /*输入要修改学生的号码*/ scanf("%s",positions); for(i=0;(fread(&stu[i],sizeof(struct student),1,fp))!=0;i++) /*找出要修改的数据*/ if(strcmp(stu[i].num,positions)==0) {fseek(fp,sizeof(struct student)*i,0); /*将指针指向要修改的资料*/ input(); fwrite(&stu[i],sizeof(struct student),1,fp); /*将修改的数据保存*/ break;} fclose(fp); } void del() /*删除ouru中的某个学生的数据*/ {int a,b,f; char positions[10]; if((fp=fopen("ouru","rb+"))==NULL) /*以读写打开ouru文件*/ {printf("Can not open file!"); return;} printf("Input the deleted number:"); /*输入要删除的学生号码*/ scanf("%s",positions); for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++); /*查找文件中有多少个学生的数据*/ f=i; for(a=0;a<i;a++) /*找出要删除的学生的数据并把后面的数据全都向前移一位*/ {if(strcmp(positions,stu[a].num)==0) { for(b=a;b<i;b++) {strcpy(stu[b].num,stu[b+1].num); strcpy(stu[b].name,stu[b+1].name); strcpy(stu[b].sex,stu[b+1].sex); stu[b].age=stu[b+1].age; strcpy(stu[b].addr,stu[b+1].addr); stu[b].score=stu[b+1].score;} f=f-1; break;} } fclose(fp); fopen("ouru","w"); /*将删除后的结果保存到ouru文件里*/ for(a=0;a<f;a++) fwrite(&stu[a],sizeof(struct student),1,fp); fclose(fp);} void examine() /*查看ouru文件中的资料*/ {int i; if((fp=fopen("ouru","r"))==NULL) /*以只读的方式打开ouru文件*/ {printf("Cannot open the file\n"); return;} printf("\n"); printf("num name sex age addr score\n"); /*读取各个学生数据的同时把它们显示出来*/ for(i=0;(fread(&stu[i],sizeof(struct student),1,fp))!=0;i++) {printf("%-10s%-10s%-8s%-9d%-17s%d\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].addr,stu[i].score);} printf("\n"); fclose(fp); } main() {int choose; /*显示主界面*/ printf("********************************************************************************\n"); printf("--------------------------------------------------------------------------------\n\n"); printf(" Welcome to the student system\n"); printf(" Producer:ouru\tRegistration number:03011123\n"); printf("\n\n--------------------------------------------------------------------------------\n"); printf("********************************************************************************\n"); printf("Please the choice:\n"); printf("\t\t\t1. Input the student data\n"); printf("\t\t\t2. Add the new studetn data\n"); printf("\t\t\t3. Change a data\n"); printf("\t\t\t4. Insert a new data\n"); printf("\t\t\t5. Delete the student data\n"); printf("\t\t\t6. Manifestation student data\n"); printf("\t\t\t7. Main menu\n"); printf("\t\t\t8. exit\n\n\n"); scanf("%d",&choose); /*选择想要操作的选项*/ while(choose!=8) /*当选择8的时候不再循环并退出*/ { switch(choose) {case 1:printf("Please input the student total:"); /*当choose为下面的数时执行相应的功能*/ scanf("%d",&N); for(i=0;i<N;i++) input(); save();break; case 2:add();break; case 3:change();break; case 4:insert();break; case 5:del();break; case 6:examine();break; case 7:printf("\n\n\nPlease the choice:\n"); printf("\t\t\t1. Input the student data\n"); printf("\t\t\t2. Add the new studetn data\n"); printf("\t\t\t3. Change a data\n"); printf("\t\t\t4. Insert a new data\n"); printf("\t\t\t5. Delete the student data\n"); printf("\t\t\t6. Manifestation student data\n"); printf("\t\t\t7. Main menu\n"); printf("\t\t\t8. exit\n\n\n");break; default :printf("error\n");} scanf("%d",&choose); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值