1 實驗的目的
創(chuàng)新互聯(lián)公司企業(yè)建站,10余年網(wǎng)站建設經(jīng)驗,專注于網(wǎng)站建設技術(shù),精于網(wǎng)頁設計,有多年建站和網(wǎng)站代運營經(jīng)驗,設計師為客戶打造網(wǎng)絡企業(yè)風格,提供周到的建站售前咨詢和貼心的售后服務。對于成都做網(wǎng)站、網(wǎng)站設計中不同領(lǐng)域進行深入了解和探索,創(chuàng)新互聯(lián)在網(wǎng)站建設中充分了解客戶行業(yè)的需求,以靈動的思維在網(wǎng)頁中充分展現(xiàn),通過對客戶行業(yè)精準市場調(diào)研,為客戶提供的解決方案。通過用C++編寫一個信息管理系統(tǒng),強化模塊化程序設計思想,能夠?qū)++程序設計中的結(jié)構(gòu)體、鏈表、數(shù)組、函數(shù)及函數(shù)重載、文件等各種概念,靈活的運用到實際的程序設計中去。
2 實驗要求
具體要求如下:
綜合實驗具體完成以下功能:
3)設計增加函數(shù):實現(xiàn)增加信息功能;
4)設計刪除函數(shù):實現(xiàn)刪除某條信息功能;
5)設計輸出函數(shù)能夠按照要求將信息寫入輸出文件中。
6)菜單選項。
3 實驗原理
實驗使用模塊化的程序設計思想,使用數(shù)據(jù)、結(jié)構(gòu)體、鏈表、文件進行數(shù)據(jù)組織,分模塊完成各功能。
4 實驗說明
志愿者信息可用結(jié)構(gòu)體存儲:
struct person{
int ID;
char Name[20];
int? Age;
char Sex;
char Lanuage[10];
double score;
person *next;
};
函數(shù)說明:
person * input(const char *fileName);//讀取input文件并并創(chuàng)建鏈表
void input(const char *fileName,person *q);//讀取input1文件
void input(const char *fileName,int &num);//讀取menu文件或find文件
void output(person *head,const char *fileName);//將鏈表內(nèi)容寫入文件
person * find(person *head,int no);//查找Id為no的人員,并返回改結(jié)點前一結(jié)點便于刪除函數(shù)調(diào)用
person* del(person *head,int no);//從鏈表中刪除Id為no的人員,返回鏈首
person *append(person *head ,person *s);//插入一名人員至鏈尾,返回鏈首
主函數(shù)中設置菜單選項,1? 查找? ?2? 插入? ? 3 刪除
不同選項調(diào)用各功能函數(shù),所有功能測試結(jié)果均需寫入文件。
可根據(jù)實際情況自定義其他函數(shù)。
注意事項:
1 輸入文件包括四個:input.txt?-----存放所有人員信息
menu.txt------存放菜單選項,數(shù)字1--3選一 ?
find.txt------?查找人員ID
input1.txt-----插入人員信息
2輸出文件一個:out.txt-----調(diào)用各函數(shù)后的結(jié)果均寫入該文件
所有文件的內(nèi)容如需分隔,用單個空格分隔。
讀取寫入文件需包含
#include
using namespace std;
//創(chuàng)建文件流對象
ifstream file;
ofstream file1
file.open("input.txt",ios::in);//讀方式打開文件inout.txt
file1.open("out.txt",ios::out);//寫方式打開文件out.txt
person *q = new person;
//讀取文件內(nèi)容至q指向的人員結(jié)點
while(!file.eof())
{
file>>q->ID>>q->Name>>q->Age>>q->Sex>>q->Lanuage>>q->score;
}
//將q指向的結(jié)點信息寫入file1文件
{
file1<
file1<
file1<
file1<
file1<
file1< } 廢話不多說,下面直接上代碼: project.h(頭文件): main.cpp(主函數(shù)): input.cpp(創(chuàng)建鏈表): find.cpp(實現(xiàn)查找功能): append.cpp(實現(xiàn)插入功能): del.cpp(實現(xiàn)刪除功能): 值得注意的是,本程序在實現(xiàn)插入功能時只能將數(shù)據(jù)插入到末尾,不能插入中間,感興趣的同學可以嘗試修改或增加新的功能。 另外還需建立五個文本文件:menu.txt(輸入菜單選項)、input.txt(存放人員信息)、find.txt(輸入要查找或刪除的人員ID)、input1.txt(輸入要插入的人員信息)、out.txt(輸出結(jié)果)。 你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
名稱欄目:C++信息管理系統(tǒng)(鏈表、文件、模塊化程序設計)-創(chuàng)新互聯(lián)
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、定制網(wǎng)站、網(wǎng)站設計公司、虛擬主機、移動網(wǎng)站建設、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)
#pragma once
#include
#include"project.h"
using namespace std;
void input(const char* fileName, person* per)
{
ifstream file;
file.open(fileName, ios::in);
file >>per->ID >>per ->Name >>per->Age >>per->Sex >>per->Language >>per->score;
}
void input(const char* fileName, int& num)
{
ifstream file;
file.open(fileName, ios::in);
file >>num;
}
void output(person* head, const char* fileName)
{
ofstream file1;
file1.open(fileName, ios::out);
person* per = head;
while (per->next != NULL) {
per = per->next;
file1<< per->ID<< " "<< per->Name<< " "<< per->Age<< " "<< per->Sex<< " "<< per->Language<< " "<< per->score<< endl;
}
}
int main()
{
person* head = new person;
head = input("input.txt");
int num = 0;
input("menu.txt", num);
switch (num) {
case 1 : {
int ID = 0;
input("find.txt", ID);
head = find(head, ID);
output(head, "out.txt");
break;
}
case 2 : {
person* per = new person;
input("input1.txt", per);
head = append(head, per);
output(head, "out.txt");
break;
}
case 3 : {
int ID = 0;
input("find.txt", ID);
head = del(head, ID);
output(head, "out.txt");
break;
}
}
return 0;
}
#include"project.h"
using namespace std;
person* input(const char* fileName)
{
ifstream file;
file.open(fileName, ios::in);
person* head = new person;
person* per = new person;
head->next = per;
file >>per->ID >>per->Name >>per->Age >>per->Sex >>per->Language >>per->score;
while (!file.eof()) {
person* q = new person;
file >>q->ID >>q->Name >>q->Age >>q->Sex >>q->Language >>q->score;
per->next = q;
per = per->next;
}
per->next = NULL;
return head;
}
#include"project.h"
using namespace std;
person* find(person* head, int no)
{
person* per = head->next;
while (per->next != NULL) {
if (per->ID == no) {
head->next = per;
per->next = NULL;
return head;
}
per = per->next;
}
}
#include"project.h"
using namespace std;
person* append(person* head, person* s)
{
person* per = head->next;
while (per->next != NULL) {
per = per->next;
}
per->next = s;
per = per->next;
per->next = NULL;
return head;
}
#include"project.h"
using namespace std;
person* del(person* head, int no)
{
person* per = head->next;
person* stu = new person;
stu->next = per;
while (per->next != NULL) {
if (per->ID == no) {
stu->next = per->next;
return head;
}
stu = stu->next;
per = per->next;
}
}
網(wǎng)址分享:http://bm7419.com/article44/igjhe.html