最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言實現(xiàn)學生信息管理系統(tǒng)(文件操作)

 更新時間:2022年06月20日 11:51:47   作者:Demo龍  
這篇文章主要介紹了C語言實現(xiàn)學生信息管理系統(tǒng),增加了文件操作,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言實現(xiàn)學生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

前言:與上篇文章相比,增加了文件操作,可將任意時期的的學生數(shù)據(jù)存儲再文件中,菜單也隨之改動,增加了文件操作一欄,是否存儲到相應(yīng)文件中由使用者決定

新增函數(shù)——文件操作;

//學生數(shù)據(jù)文件儲存?
//儲存任意時期的學生數(shù)據(jù)?
void Store_List(Link head)
{
?? ?//文件操作?
?? ?ofstream ofs;
?? ?ofs.open("Std_Information.txt",ios::out);
?? ?
?? ?if(head==NULL)
?? ?{
?? ??? ?printf("學生為空\n");
?? ??? ?return;?
?? ?}
?? ?else
?? ?{
?? ??? ?Link p=head->next;
?? ??? ?while(p)
?? ??? ?{
?? ??? ??? ?ofs<< "姓名:"<<p->data.studentName<<" ? ?學號:"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ??? ?
?? ?}
}

1.頭文件和預(yù)處理

#include <stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<stdbool.h>
#include<iostream>
#include<fstream>//文件操作所需頭文件?
using namespace std;
#define NO_LENGTH ?20
#define NAME_LENGTH 11

/* 定義學生結(jié)構(gòu)體的數(shù)據(jù)結(jié)構(gòu) */
typedef struct Student{
?? ?char studentNo[NO_LENGTH];
?? ?char studentName[NAME_LENGTH];
?? ?int score;
}st;

/* 定義每條記錄或節(jié)點的數(shù)據(jù)結(jié)構(gòu) */
typedef struct node
{
?? ?struct Student data; //數(shù)據(jù)域
?? ?struct node *next; //指針域
}Node,*Link; ?//Node為node類型的別名,Link為node類型的指針別名

2.定義學生結(jié)構(gòu)體的數(shù)據(jù)結(jié)構(gòu)

typedef struct Student{
?? ?char studentNo[NO_LENGTH];
?? ?char studentName[NAME_LENGTH];
?? ?int score;
}st;

3.定義每條記錄或節(jié)點的數(shù)據(jù)結(jié)構(gòu)

/* 定義每條記錄或節(jié)點的數(shù)據(jù)結(jié)構(gòu) */
typedef struct node
{
?? ?struct Student data; //數(shù)據(jù)域
?? ?struct node *next; //指針域
}Node,*Link; ?//Node為node類型的別名,Link為node類型的指針別名

4.函數(shù)接口代碼.

1.定義提示菜單

//定義提示菜單
void myMenu(){

?? ?printf("*****************************菜單*****************************\n");?
?? ?printf("***********************1 增加學生記錄*************************\n");?
?? ?printf("***********************2 刪除學生記錄*************************\n");?
?? ?printf("***********************3 查找學生記錄*************************\n");?
?? ?printf("***********************4 修改學生記錄*************************\n");?
?? ?printf("***********************5 統(tǒng)計學生人數(shù) ************************\n");?
?? ?printf("***********************6 顯示學生記錄*************************\n");?
?? ?printf("***********************7 信息文件打印*************************\n");
?? ?printf("***********************8 退出系統(tǒng) ****************************\n");?
?? ?
}

2.增加學生記錄

void inputStudent(Link l){
?? ? printf("請輸入學生學號:");
?? ? scanf("%s",l->data.studentNo);
?? ? printf("請輸入學生的姓名:");
?? ? scanf("%s",l->data.studentName);
?? ?printf("請輸入學生的成績:");
?? ? scanf("%s",&(l->data.score));
?? ? //每個新創(chuàng)建的節(jié)點的next域都初始化為NULL
?? ? l->next = NULL;
?? ? system("cls");
}

3.輸入學號接口·

void inputStudentNo(char s[],char no[]){
?? ?printf("請輸入要%s的學生學號:",s);
?? ?scanf("%s",no);
}

4.遍歷表中學生

//遍歷表中學生?
void displayNode(Link head){
?? ?if(head==NULL)
?? ?{
?? ??? ?printf("學生為空\n");
?? ??? ?return;?
?? ?}
?? ?else
?? ?{
?? ??? ?Link p=head->next;
?? ??? ?while(p)
?? ??? ?{
?? ??? ??? ?cout<<"姓名:"<<p->data.studentName<<" ? ?學號"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ??? ?
?? ?}
? ?// 填寫代碼,根據(jù)傳入的鏈表head頭指針,掃描鏈表顯示所有節(jié)點的信息
? ?system("pause");
? ?system("cls");
}

5.增加學生記錄

/* 增加學生記錄 */
bool addNode(Link head){
?? ? Link p,q; ? //p,q兩個節(jié)點一前一后
?? ? Link node; ?//node指針指向新創(chuàng)建的節(jié)點
?? ? node=(Link)malloc(sizeof(Node));
?? ? inputStudent(node);

?? ? q = head;
?? ? p = head->next; ?//q指向head后面的第一個有效節(jié)點
?? ? if(head->next==NULL)
?? ??? ? //鏈表為空時
?? ??? ?head->next = node;
?? ? else {
?? ??? ? //循環(huán)訪問鏈表中的所有節(jié)點
?? ??? ?while(p != NULL){
?? ??? ??? ?if (node->data.studentNo < p->data.studentNo){
?? ??? ??? ??? ?//如果node節(jié)點的學號比p節(jié)點的學號小,則插在p的前面,完成插入后,提前退出子程序
?? ??? ??? ??? ?q->next = node;
?? ??? ??? ??? ?node->next = p;
?? ??? ??? ??? ?return true;
?? ??? ??? ?}
?? ??? ??? ?else{
?? ??? ??? ??? ?//如果node節(jié)點的學號比p節(jié)點的學號大,繼續(xù)向后移動指針(依然保持pq一前一后)
?? ??? ??? ??? ?q = p;
?? ??? ??? ??? ?p = p->next;

?? ??? ??? ?}
?? ??? ?}
?? ??? ?//如果沒能提前退出循環(huán),則說明之前沒有插入,那么當前node節(jié)點的學號是最大值,此時插在鏈表的最后面
?? ??? ?q->next = node;

?? ?}
?? ? return true;
?? ? system("pause");
? ?system("cls");
}

6.刪除學生信息

//刪除學生信息
bool deleteNode(Link head){
? ? // 按照給定的學號刪除學生記錄,如果刪除成功返回true,如果沒找到學號返回false

? ? //輸入要處理的學號
? ? ?? ?char no[NO_LENGTH];
?? ?inputStudentNo("刪除",no);
?? ??? ?Link p=head->next;
?? ?Link q=head;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?cout<<"成功刪除該學生"<<endl;?
?? ??? ??? ?q->next=p->next;
?? ??? ??? ?free(p);
?? ??? ??? ?system("pause");
? ??? ??? ??? ?system("cls");
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?q=p;
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生"<<endl;?
?? ??? ?system("pause");
? ??? ??? ?system("cls");
?? ?return false;
}

7.查找學生信息

//查找學生信息?
bool queryNode(Link head){
? ? // 按照給定的學號查詢學生記錄,如果查找成功返回true,如果沒找到學號返回false

? ? //輸入要處理的學號
?? ?char no[NO_LENGTH];
?? ?inputStudentNo("查找",no);
?? ??? ?Link p=head->next;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?
? ??? ??? ??? ?system("cls");
? ??? ??? ??? ?cout<<"姓名:"<<p->data.studentName<<" ? ?學號:"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生"<<endl;?
? ?system("cls");

?? ?return false;
}

8.修改學生信息

//修改學生信息?
bool modifyNode(Link head){
? ? // 按照給定的學號找到學生記錄節(jié)點,如果修改成功返回true,如果沒找到學號返回false
?? ?
? ? //輸入要處理的學號
?? ?char no[NO_LENGTH];
?? ?inputStudentNo("修改",no);
?? ?Link p=head->next;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?cout<<"請輸入修改后的姓名"<<endl;?
?? ??? ??? ?cin>>p->data.studentName;
?? ??? ??? ?cout<<"請輸入修改后的學號"<<endl;?
?? ??? ??? ?cin>>p->data.studentNo;
?? ??? ??? ?cout<<"請輸入修改后的成績"<<endl;?
?? ??? ??? ?cin>>p->data.score;
?? ??? ??? ?system("cls");
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生,請重新輸入學號"<<endl;?
?? ?system("cls");
?? ?return false;
}

9.統(tǒng)計學生人數(shù)

//統(tǒng)計學生人數(shù)
int countNode(Link head){
?? ?//統(tǒng)計學生人數(shù),掃描鏈表統(tǒng)計節(jié)點個數(shù),返回節(jié)點數(shù)
?? ?Link p;
?? ?int count = 0;
?? ?p = head->next;
?? ?while(p)
?? ?{
?? ??? ?p=p->next;
?? ??? ?count++;
?? ?}
?? ?//填充代碼
?? ?system("cls");
?? ?return count;
}

10.清空鏈表

//清空鏈表?
void clearLink(Link head){
?? ?Link q,p;
?? ?p=head->next;
?? ?q=head;
?? ?while(p)
?? ?{
?? ??? ?q->next=p->next;
?? ??? ?free(p);
?? ??? ?p=q->next;
?? ?}
? ? ? ? //遍歷鏈表,用free語句刪除鏈表中用malloc建立起的所有的節(jié)點
}

11.文件操作

//學生數(shù)據(jù)文件儲存?
//儲存任意時期的學生數(shù)據(jù)?
void Store_List(Link head)
{
?? ?//文件操作?
?? ?ofstream ofs;
?? ?ofs.open("Std_Information.txt",ios::out);
?? ?
?? ?if(head==NULL)
?? ?{
?? ??? ?printf("學生為空\n");
?? ??? ?return;?
?? ?}
?? ?else
?? ?{
?? ??? ?Link p=head->next;
?? ??? ?while(p)
?? ??? ?{
?? ??? ??? ?ofs<< "姓名:"<<p->data.studentName<<" ? ?學號:"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ??? ?
?? ?}
}

5.main函數(shù)

int main() {
?? ?int select;
? ? ?? ?int count;
?? ?Link head; ?// 定義鏈表

?? ?//建立head頭結(jié)點,在這個程序中head指向頭結(jié)點,頭結(jié)點data部分沒有內(nèi)容,其后續(xù)節(jié)點才有真正的數(shù)據(jù)
?? ?head = (Link)malloc(sizeof(Node));
?? ?head->next = NULL;

?? ?while(1)
?? ?{
?? ??? ?myMenu();
?? ??? ?printf("\n請輸入你的選擇(0-7):"); ?//顯示提示信息
?? ??? ?scanf("%d",&select);
?? ??? ?switch(select)
?? ??? ?{
?? ??? ?case 1:
?? ??? ??? ?//增加學生記錄
?? ??? ??? ?if(addNode(head))
?? ??? ??? ??? ?printf("成功插入一個學生記錄。\n\n");
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?//刪除學生記錄
?? ??? ??? ?if(deleteNode(head))
?? ??? ??? ??? ?printf("成功刪除一個學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要刪除的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 3:
?? ??? ??? ?//查詢學生記錄
?? ??? ??? ?if(queryNode(head))
?? ??? ??? ??? ?printf("成功找到學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要查詢的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 4:
?? ??? ??? ?//修改學生記錄
?? ??? ??? ?if(modifyNode(head))
?? ??? ??? ??? ?printf("成功修改一個學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要修改的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 5:
?? ??? ??? ?//統(tǒng)計學生人數(shù)
?? ??? ??? ?count = countNode(head);
?? ??? ??? ?printf("學生人數(shù)為:%d\n\n",count);
?? ??? ??? ?break;
?? ??? ?case 6:
?? ??? ??? ?//顯示學生記錄
?? ??? ??? ?displayNode(head);
?? ??? ??? ?break;
?? ??? ?case 7:
?? ??? ??? ?//退出前清除鏈表中的所有結(jié)點
? ? ? ? ? ? clearLink(head);
?? ??? ??? ?return 0;
?? ??? ?default:
?? ??? ??? ?printf("輸入不正確,應(yīng)該輸入0-7之間的數(shù)。\n\n");
?? ??? ??? ?system("cls");?
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?return 0;
}

6.學生信息管理系統(tǒng)總源碼(可直接復(fù)制運行)

#include <stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<stdbool.h>
#include<iostream>
#include<fstream>//文件操作所需頭文件?
using namespace std;
#define NO_LENGTH ?20
#define NAME_LENGTH 11

/* 定義學生結(jié)構(gòu)體的數(shù)據(jù)結(jié)構(gòu) */
typedef struct Student{
?? ?char studentNo[NO_LENGTH];
?? ?char studentName[NAME_LENGTH];
?? ?int score;
}st;

/* 定義每條記錄或節(jié)點的數(shù)據(jù)結(jié)構(gòu) */
typedef struct node
{
?? ?struct Student data; //數(shù)據(jù)域
?? ?struct node *next; //指針域
}Node,*Link; ?//Node為node類型的別名,Link為node類型的指針別名

//定義提示菜單
void myMenu(){

?? ?printf("*****************************菜單*****************************\n");?
?? ?printf("***********************1 增加學生記錄*************************\n");?
?? ?printf("***********************2 刪除學生記錄*************************\n");?
?? ?printf("***********************3 查找學生記錄*************************\n");?
?? ?printf("***********************4 修改學生記錄*************************\n");?
?? ?printf("***********************5 統(tǒng)計學生人數(shù) ************************\n");?
?? ?printf("***********************6 顯示學生記錄*************************\n");?
?? ?printf("***********************7 信息文件打印*************************\n");
?? ?printf("***********************8 退出系統(tǒng) ****************************\n");?
?? ?
}

void inputStudent(Link l){
?? ? printf("請輸入學生學號:");
?? ? scanf("%s",l->data.studentNo);
?? ? printf("請輸入學生的姓名:");
?? ? scanf("%s",l->data.studentName);
?? ?printf("請輸入學生的成績:");
?? ? scanf("%d",&(l->data.score));
?? ? //每個新創(chuàng)建的節(jié)點的next域都初始化為NULL
?? ? l->next = NULL;
?? ? system("cls");
}

void inputStudentNo(char s[],char no[]){
?? ?printf("請輸入要%s的學生學號:",s);
?? ?scanf("%s",no);
}
//遍歷表中學生?
void displayNode(Link head){
?? ?if(head==NULL)
?? ?{
?? ??? ?printf("學生為空\n");
?? ??? ?return;?
?? ?}
?? ?else
?? ?{
?? ??? ?Link p=head->next;
?? ??? ?while(p)
?? ??? ?{
?? ??? ??? ?cout<<"姓名:"<<p->data.studentName<<" ? ?學號"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?//ofs<< "姓名:"<<p->data.studentName<<" ? ?學號"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ??? ?
?? ?}
? ?// 填寫代碼,根據(jù)傳入的鏈表head頭指針,掃描鏈表顯示所有節(jié)點的信息
? ?system("pause");
? ?system("cls");
}

/* 增加學生記錄 */
bool addNode(Link head){
?? ? Link p,q; ? //p,q兩個節(jié)點一前一后
?? ? Link node; ?//node指針指向新創(chuàng)建的節(jié)點
?? ? node=(Link)malloc(sizeof(Node));
?? ? inputStudent(node);

?? ? q = head;
?? ? p = head->next; ?//q指向head后面的第一個有效節(jié)點
?? ? if(head->next==NULL)
?? ??? ? //鏈表為空時
?? ??? ?head->next = node;
?? ? else {
?? ??? ? //循環(huán)訪問鏈表中的所有節(jié)點
?? ??? ?while(p != NULL){
?? ??? ??? ?if (node->data.studentNo < p->data.studentNo){
?? ??? ??? ??? ?//如果node節(jié)點的學號比p節(jié)點的學號小,則插在p的前面,完成插入后,提前退出子程序
?? ??? ??? ??? ?q->next = node;
?? ??? ??? ??? ?node->next = p;
?? ??? ??? ??? ?return true;
?? ??? ??? ?}
?? ??? ??? ?else{
?? ??? ??? ??? ?//如果node節(jié)點的學號比p節(jié)點的學號大,繼續(xù)向后移動指針(依然保持pq一前一后)
?? ??? ??? ??? ?q = p;
?? ??? ??? ??? ?p = p->next;

?? ??? ??? ?}
?? ??? ?}
?? ??? ?//如果沒能提前退出循環(huán),則說明之前沒有插入,那么當前node節(jié)點的學號是最大值,此時插在鏈表的最后面
?? ??? ?q->next = node;

?? ?}
?? ? return true;
?? ? system("pause");
? ?system("cls");
}

bool deleteNode(Link head){
? ? // 按照給定的學號刪除學生記錄,如果刪除成功返回true,如果沒找到學號返回false

? ? //輸入要處理的學號
? ? ?? ?char no[NO_LENGTH];
?? ?inputStudentNo("刪除",no);
?? ??? ?Link p=head->next;
?? ?Link q=head;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?cout<<"成功刪除該學生"<<endl;?
?? ??? ??? ?q->next=p->next;
?? ??? ??? ?free(p);
?? ??? ??? ?system("pause");
? ??? ??? ??? ?system("cls");
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?q=p;
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生"<<endl;?
system("pause");
? ?system("cls");
?? ?return false;
}

//查找學生信息?
bool queryNode(Link head){
? ? // 按照給定的學號查詢學生記錄,如果查找成功返回true,如果沒找到學號返回false

? ? //輸入要處理的學號
?? ?char no[NO_LENGTH];
?? ?inputStudentNo("查找",no);
?? ??? ?Link p=head->next;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?
? ??? ??? ??? ?system("cls");
? ??? ??? ??? ?cout<<"姓名:"<<p->data.studentName<<" ? ?學號:"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生"<<endl;?
? ?system("cls");

?? ?return false;
}

//修改學生信息?
bool modifyNode(Link head){
? ? // 按照給定的學號找到學生記錄節(jié)點,如果修改成功返回true,如果沒找到學號返回false
?? ?
? ? //輸入要處理的學號
?? ?char no[NO_LENGTH];
?? ?inputStudentNo("修改",no);
?? ?Link p=head->next;
?? ?while(p)
?? ?{
?? ??? ?if(strcmp(p->data.studentNo,no)==0)
?? ??? ?{
?? ??? ??? ?cout<<"請輸入修改后的姓名"<<endl;?
?? ??? ??? ?cin>>p->data.studentName;
?? ??? ??? ?cout<<"請輸入修改后的學號"<<endl;?
?? ??? ??? ?cin>>p->data.studentNo;
?? ??? ??? ?cout<<"請輸入修改后的成績"<<endl;?
?? ??? ??? ?cin>>p->data.score;
?? ??? ??? ?system("cls");
?? ??? ??? ?return true;
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ?}
?? ?cout<<"未找到該學生,請重新輸入學號"<<endl;?
?? ?system("cls");
?? ?return false;
}

//統(tǒng)計學生人數(shù)
int countNode(Link head){
?? ?//統(tǒng)計學生人數(shù),掃描鏈表統(tǒng)計節(jié)點個數(shù),返回節(jié)點數(shù)
?? ?Link p;
?? ?int count = 0;
?? ?p = head->next;
?? ?while(p)
?? ?{
?? ??? ?p=p->next;
?? ??? ?count++;
?? ?}
?? ?//填充代碼
?? ?system("cls");
?? ?return count;
}

//清空鏈表?
void clearLink(Link head){
?? ?Link q,p;
?? ?p=head->next;
?? ?q=head;
?? ?while(p)
?? ?{
?? ??? ?q->next=p->next;
?? ??? ?free(p);
?? ??? ?p=q->next;
?? ?}
? ? ? ? //遍歷鏈表,用free語句刪除鏈表中用malloc建立起的所有的節(jié)點
}

//學生數(shù)據(jù)文件儲存?
//儲存任意時期的學生數(shù)據(jù)?
void Store_List(Link head)
{
?? ?//文件操作?
?? ?ofstream ofs;
?? ?ofs.open("Std_Information.txt",ios::out);
?? ?
?? ?if(head==NULL)
?? ?{
?? ??? ?printf("學生為空\n");
?? ??? ?return;?
?? ?}
?? ?else
?? ?{
?? ??? ?Link p=head->next;
?? ??? ?while(p)
?? ??? ?{
?? ??? ??? ?ofs<< "姓名:"<<p->data.studentName<<" ? ?學號:"<<p->data.studentNo<<" ?成績:"<<p->data.score<<endl;?
?? ??? ??? ?p=p->next;
?? ??? ?}
?? ??? ?
?? ?}
}
int main() {
?? ?int select;
? ? ?? ?int count;
?? ?Link head; ?// 定義鏈表
?? ?
?? ?
?? ?//建立head頭結(jié)點,在這個程序中head指向頭結(jié)點,頭結(jié)點data部分沒有內(nèi)容,其后續(xù)節(jié)點才有真正的數(shù)據(jù)
?? ?head = (Link)malloc(sizeof(Node));
?? ?head->next = NULL;

?? ?while(1)
?? ?{
?? ??? ?myMenu();
?? ??? ?printf("\n請輸入你的選擇(0-8):"); ?//顯示提示信息
?? ??? ?scanf("%d",&select);
?? ??? ?switch(select)
?? ??? ?{
?? ??? ?case 1:
?? ??? ??? ?//增加學生記錄
?? ??? ??? ?if(addNode(head))
?? ??? ??? ??? ?printf("成功插入一個學生記錄。\n\n");
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?//刪除學生記錄
?? ??? ??? ?if(deleteNode(head))
?? ??? ??? ??? ?printf("成功刪除一個學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要刪除的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 3:
?? ??? ??? ?//查詢學生記錄
?? ??? ??? ?if(queryNode(head))
?? ??? ??? ??? ?printf("成功找到學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要查詢的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 4:
?? ??? ??? ?//修改學生記錄
?? ??? ??? ?if(modifyNode(head))
?? ??? ??? ??? ?printf("成功修改一個學生記錄。\n\n");
?? ??? ??? ?else
?? ??? ??? ??? ?printf("沒有找到要修改的學生節(jié)點。\n\n");
?? ??? ??? ?break;
?? ??? ?case 5:
?? ??? ??? ?//統(tǒng)計學生人數(shù)
?? ??? ??? ?count = countNode(head);
?? ??? ??? ?printf("學生人數(shù)為:%d\n\n",count);
?? ??? ??? ?break;
?? ??? ?case 6:
?? ??? ??? ?//顯示學生記錄
?? ??? ??? ?displayNode(head);
?? ??? ??? ?break;
?? ??? ?case 7:Store_List(head);
?? ??? ??? ??? ?cout<<"打印成功"<<endl;?
?? ??? ??? ??? ?system("pause");
? ??? ??? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?case 8:
?? ??? ??? ?//退出前清除鏈表中的所有結(jié)點
? ? ? ? ? ? clearLink(head);
?? ??? ??? ?return 0;
?? ??? ?default:
?? ??? ??? ?printf("輸入不正確,應(yīng)該輸入0-8之間的數(shù)。\n\n");
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");?
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?return 0;
}

7.測試結(jié)果

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解VS2019使用scanf()函數(shù)報錯的解決方法

    詳解VS2019使用scanf()函數(shù)報錯的解決方法

    本文主要介紹了詳解VS2019使用scanf()函數(shù)報錯的解決方法,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • C語言用數(shù)組實現(xiàn)反彈球消磚塊

    C語言用數(shù)組實現(xiàn)反彈球消磚塊

    這篇文章主要為大家詳細介紹了C語言用數(shù)組實現(xiàn)反彈球消磚塊,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 詳解C++中mutable的用法

    詳解C++中mutable的用法

    這篇文章主要介紹了詳解C++中mutable的用法,幫助大家更好的理解和學習C++,感興趣的朋友可以了解下
    2020-08-08
  • C語言鏈表實現(xiàn)貪吃蛇游戲

    C語言鏈表實現(xiàn)貪吃蛇游戲

    這篇文章主要為大家詳細介紹了C語言鏈表實現(xiàn)貪吃蛇游戲源碼,適合C語言入門者學習閱讀,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • C++中的Lambda表達式及表達式語句

    C++中的Lambda表達式及表達式語句

    這篇文章主要介紹了C++中的Lambda表達式及表達式語句,表達式這個概念在C++中屬于比較細節(jié)的知識了,很多時候我們只用知道怎么用,對于編譯器內(nèi)部怎么處理我們并不關(guān)心;并且關(guān)于左值和右值這個概念,也是C++比較深的一個小知識點,需要的朋友可以參考一下
    2021-12-12
  • C語言關(guān)于二叉樹中堆的創(chuàng)建和使用整理

    C語言關(guān)于二叉樹中堆的創(chuàng)建和使用整理

    大家好,這里是針對二叉樹中堆結(jié)構(gòu)的順序儲存,整理出來一篇博客供我們一起復(fù)習和學習,如果文章中有理解不當?shù)牡胤?還希望朋友們在評論區(qū)指出,我們相互學習,共同進步
    2022-08-08
  • C++?ffmpeg實現(xiàn)將視頻幀轉(zhuǎn)換成jpg或png等圖片

    C++?ffmpeg實現(xiàn)將視頻幀轉(zhuǎn)換成jpg或png等圖片

    有時播放實時流的時候有截圖的需求,需要將解碼出來的圖片保存本地或上傳服務(wù)器,這時就需要將avframe中的數(shù)據(jù)編碼成png、jpg等格式的圖片,我們使用ffmpeg的相關(guān)編碼器就可以實現(xiàn)功能,下面就來講講具體實現(xiàn)方法吧
    2023-03-03
  • 解析四則表達式的編譯過程及生成匯編代碼

    解析四則表達式的編譯過程及生成匯編代碼

    本篇文章是對四則表達式的編譯過程及生成匯編代碼進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • 淺析C++中static的一些用法

    淺析C++中static的一些用法

    static是靜止的,靜態(tài)的意思,那它有什么用呢,今天通過實例代碼講解下C++中static的一些用法,感興趣的朋友跟隨小編一起看看吧
    2022-12-12
  • C++實現(xiàn)二叉樹及堆的示例代碼

    C++實現(xiàn)二叉樹及堆的示例代碼

    這篇文章主要介紹了C++實現(xiàn)二叉樹及堆的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-04-04

最新評論

论坛| 东方市| 黄大仙区| 射阳县| 玛曲县| 辰溪县| 咸阳市| 双流县| 海宁市| 淮滨县| 泸定县| 邵武市| 连州市| 镇宁| 五常市| 黑水县| 武鸣县| 微山县| 钟祥市| 邵武市| 姚安县| 个旧市| 阿勒泰市| 玛沁县| 河西区| 广宁县| 申扎县| 井研县| 和硕县| 社会| 顺昌县| 临海市| 隆安县| 齐河县| 尚志市| 九龙县| 义马市| 莱芜市| 阜新| 靖远县| 桃江县|