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