學生信息管理系統(tǒng)
創(chuàng)新互聯(lián)專注于友誼企業(yè)網(wǎng)站建設,響應式網(wǎng)站開發(fā),成都商城網(wǎng)站開發(fā)。友誼網(wǎng)站建設公司,為友誼等地區(qū)提供建站服務。全流程按需定制,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務?學生信息管理系統(tǒng),主要為了實現(xiàn)學生信息的增加、刪除、修改、查找等功能,以下是實現(xiàn)這一功能的相關代碼。
#include#include#includeusing namespace std;
struct node //創(chuàng)建一個結構體,學生的相關信息
{
string name; //學生姓名
int number; //學生學號
string sex; //學生性別
node* next;
};
node* creatList()//不帶頭結點創(chuàng)建鏈表
{
node* p, * head;
int c; //判斷是否繼續(xù)此操作
head = NULL;
while(1)
{
//創(chuàng)建結點
p = new node;
cout<< "輸入學生信息:姓名 學號 性別"<< endl;
cin >>p->name >>p->number >>p->sex;
p->next = head;
head = p;
cout<< "是否繼續(xù)輸入學生信息?[1/0]";
cin >>c;
if (tolower(c) == 0)
break;
}
return head;
}
void print_List(node* head) //打印全體學生的信息
{
node* p;
p = head;
while (p != NULL)
{
cout<< p->name<< " "<< p->number<< " "<< p->sex<< endl;
p = p->next;
}
}
node* Add_stu(node* head) //添加學生
{
node* p;
p = new node;
cout<< "請輸入增添學生的信息:姓名 學號 性別"<< endl;
cin >>p->name >>p->number >>p->sex;
p->next = head;
head = p;
return head;
}
node* Delete_stu(node* head, int dnumber) //刪除學生
{
node* p, * q, * t;
t = head;
if (head->number == dnumber)//如果刪除的為第一個結點
{
p = head;
head = head->next;
delete p;
cout<< "刪除成功!"<< endl;
return head;
}
p = head;
q = head->next;
while (q != NULL && q->number != dnumber)
{
q = q->next;
p = p->next;
}
if (p != NULL&&q!=NULL)
{
p->next = q->next;
delete q;
cout<< "刪除成功!"<< endl;
return t;
}
cout<< "未找到所需刪除的學生信息!"<< endl;
}
void Find_stu(node* head, int dnumber) //查找學生
{
node* p;
p = head;
while (p != NULL)
{
if (p->number == dnumber)
{
cout<< "所要查找學生的相關信息:"<< endl;
cout<< p->name<< " "<< p->number<< " "<< p->sex<< endl;
break;
}
else
p = p->next;
}
}
void Modify_stu(node* head, int dnumber) //修改學生的相關信息
{
node* p;
string aname; int anumber; string asex;
p = head;
while (p != NULL)
{
if (p->number == dnumber)
{
cout<< "輸入修改后的學生信息"<< endl;
cin >>aname >>anumber >>asex;
p->name = aname;
p->number = anumber;
p->sex = asex;
cout<< "所要修改學生的相關信息:"<< endl;
cout<< p->name<< " "<< p->number<< " "<< p->sex<< endl;
break;
}
else
p = p->next;
}
}
void main()
{
int i;int f = 1;
node *head;
head = creatList();
print_List(head);
cout<< endl;
cout<< "0、增加新的學生!"<< endl;
cout<< "1、刪除學生信息!"<< endl;
cout<< "2、查找學生信息!"<< endl;
cout<< "3、修改學生信息!"<< endl;
cout<< "4、打印學生信息!"<< endl;
cout<< "5、退出相關操作!"<< endl;
while (f)
{
cout<< "請輸入要進行的操作序號:";
cin >>i;
switch (i)
{
case 0:head=Add_stu(head);
cout<< "添加成功!"<< endl;
break;
case 1:
{
cout<< "請輸入要刪除學生的相關信息:姓名 學號 性別"<< endl;
string dname; int dnumber; string dsex;
cin >>dname >>dnumber >>dsex;
head=Delete_stu(head, dnumber);
break;
}
case 2:
{
cout<< "請輸入要查找學生的學號:"<< endl;
int dnumber;
cin >>dnumber;
Find_stu(head, dnumber);
break;
}
case 3:
{
cout<< "請輸入要修改學生的學號:"<< endl;
int dnumber;
cin >>dnumber;
Find_stu(head, dnumber);
cout<< "所要修改學生的相關信息:"<< endl;
Modify_stu(head, dnumber);
cout<< "修改成功!"<< endl;
break;
}
case 4:
cout<< "打印學生信息!"<< endl;
print_List(head);
break;
case 5:
f = 0;
break;
default:
break;
}
}
cout<< "退出!";
exit(0);
}
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
文章名稱:學生信息管理系統(tǒng)(c++)-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://muchs.cn/article14/dhehde.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供域名注冊、網(wǎng)站收錄、關鍵詞優(yōu)化、網(wǎng)站策劃、小程序開發(fā)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容