#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct student{
char name[20];
char address[40];
char phonenum[30];
char postcode[20];
student *next;
};
//定義資料結構體
void mainscreen(student *p);
void title();
void save(student *head)
{
FILE *fp;
student *point;
point=head;
if((fp=fopen("data.dat","wb"))==NULL)
{
cout<<"can not open file"<<endl;
exit(0);
}
while (point)
{
fwrite(point,1, sizeof(struct student),fp);
point=point->next;
}
fclose(fp);
}
void read_(student *head) //檔案資料讀取函式
{
FILE *p=fopen("data.dat","rb");
fread(head,sizeof(struct student),1,p);
/*while(head)
{
cout<<"%s\n",head->name);
cout<<"%s\n",head->address);
cout<<"%s\n",head->phonenum);
head=head->next;
}
*/
}
void assert_student(student *head)
{
system("cls");
title();
static student *p,*q;
if(head==NULL)
{
head=q=(struct student *)malloc(sizeof(student));
p=(struct student *)malloc(sizeof(student));
head->next=p;
cout<<"當前通訊錄未初始化,請輸入首物件的姓名:";
cin>>p->name;
cout<<"請輸入物件的家庭住址:";
cin>>p->address;
cout<<"請輸入物件的電話號碼:";
cin>>p->phonenum;
cout<<"請輸入物件的郵政編碼:";
cin>>p->postcode;
q->next=p;
q=p;
q->next=NULL;
system("cls");
title();
}
else if(head!=NULL)
{
p=(struct student *)malloc(sizeof(student));
cout<<"請輸入物件的姓名:";
cin>>p->name;
cout<<"請輸入物件的家庭住址:";
cin>>p->address;
cout<<"請輸入物件的電話號碼:";
cin>>p->phonenum;
cout<<"請輸入物件的郵政編碼:";
cin>>p->postcode;
q->next=p;
q=p;
q->next=NULL;
system("cls");
title();
}
mainscreen(head);
}
void delete_student(student *head)
{
int flag=1;
system("cls");
char de_stu[20];
cout<<"請輸入要注銷資訊的姓名:";
cin>>de_stu;
student *q,*front;
front=(struct student *)malloc(sizeof(student));
q=head->next;
while(q!=NULL)
{
if(strcmp(q->name,de_stu)==0)
{
cout<<"已找到需要注銷的資訊,正在注銷中…………"<<endl;
q=front->next;
front->next=q->next;
cout<<"該資料已注銷成功,回傳主頁面…………"<<endl;
flag=0;
break;
}
q=q->next;
}
if(flag==1)
cout<<"查找的資訊不存在"<<endl;
mainscreen(head);
}
void change_student(student *head)
{
system("cls");
title();
int flag=1;
student *q;
char name_stu[20];
cout<<"請輸入你要修改資訊的姓名:";
cin>>name_stu;
q=head->next;
while(q!=NULL)
{
if(strcmp(q->name,name_stu)==0)
{
cout<<"請開始個人資訊的修改:"<<endl;
cout<<"姓名:";
cin>>q->name;
cout<<"家庭住址:";
cin>>q->address;
cout<<"電話號碼:";
cin>>q->phonenum;
cout<<"郵政編碼:";
cin>>q->postcode;
cout<<"個人資訊修改完成!"<<endl;
flag=0;
break;
}
q=q->next;
}
if(flag==1)
cout<<"查找的資訊不存在"<<endl;
mainscreen(head);
}
void search_student(student *head)
{
system("cls");
title();
int flag=1;
char name_stu[20];
cout<<"請輸入你要查找的姓名:";
cin>>name_stu;
student *q;
q=head->next;
while(q!=NULL)
{
if(strcmp(q->name,name_stu)==0)
{
cout<<"姓名:"<<" ";
cout<<"家庭住址:"<<" ";
cout<<"電話號碼:"<<" "<<endl;
cout<<"郵政編碼:"<<" "<<endl;
cout<<q->name<<" ";
cout<<q->address<<" ";
cout<<q->phonenum<<" "<<endl;
cout<<q->postcode<<" "<<endl;
flag=0;
break;
}
q=q->next;
}
if(flag==1)
cout<<"查找的資訊不存在"<<endl;
mainscreen(head);
}
void show_student(student *head)
{
system("cls");
title();
student *q;
q=head->next;
while(q!=NULL)
{
cout<<"姓名:"<<" ";
cout<<"家庭住址:"<<" ";
cout<<"電話號碼:"<<" "<<endl;
cout<<"郵政編碼:"<<" "<<endl;
cout<<q->name<<" ";
cout<<q->address<<" ";
cout<<q->phonenum<<" "<<endl;
cout<<q->postcode<<" "<<endl;
q=q->next;
}
mainscreen(head);
}
void title()
{
char a=3;
for(int i=0;i<90;i++)
cout<<a;
cout<<endl;
cout<<" ********通訊管理系統******** "<<endl;
a=5;
for(i=0;i<90;i++)
cout<<a;
cout<<endl;
}
void mainscreen(student *head)
{
int choice;
char a=14;
cout<<a<<"請按照要求選擇要進行的操作:"<<endl;
cout<<a<<"按照資訊后的數字提示選擇相應的操作:"<<endl<<endl;
for(int i=0;i<68;i++)
cout<<a;
cout<<endl;
cout<<" "<<a<<" 插入新的人物通訊錄**************************************** 1 "<<a<<endl;
cout<<" "<<a<<" 根據姓名查找相應的人物資訊******************************** 2 "<<a<<endl;
cout<<" "<<a<<" 根據姓名洗掉相應的人物資訊******************************** 3 "<<a<<endl;
cout<<" "<<a<<" 根據姓名修改相應的人物資訊******************************** 4 "<<a<<endl;
cout<<" "<<a<<" 退出通訊錄登錄系統****************************************** 5 "<<a<<endl;
cout<<" "<<a<<" 顯示當前資料庫中所有的通訊錄資訊************************* 6 "<<a<<endl;
cout<<" "<<a<<" 讀取當前資料庫中所有的通訊錄資訊************************* 7 "<<a<<endl;
cout<<" "<<a<<" 保存當前資料庫中所有的通訊錄資訊************************* 8 "<<a<<endl;
for(i=0;i<68;i++)
cout<<a;
cout<<endl;
cout<<"請輸入你的選擇:";
cin>>choice;
switch(choice)
{
case 1:assert_student(head);break;
case 2:search_student(head);break;
case 3:delete_student(head);break;
case 4:change_student(head);break;
case 5:save(head);exit(0);
case 6:show_student(head);break;
case 7:read_student(head);break;
case 8:save_student(head);break;
}
}
int main()
{
char a;
student *head;
head=NULL;
title();
a=2;
cout<<a<<"歡迎進入通訊錄管理系統"<<endl;
int selectNum;
cout<<"\n請選擇你接下來的操作"<<endl; //輸出一個選擇選單
cout<<"1 進入通訊錄管理系統"<<endl;
cout<<"2 退出通訊錄管理系統"<<endl;
cin>>selectNum; //接收輸入的選擇數字
switch (selectNum) //按照輸入的選擇數呼叫函式
{
case 1:mainscreen(head);//進入選單界面
break;
case 2:system("cls");exit(0); //呼叫退出函式
break;
}
return 0;
}
uj5u.com熱心網友回復:
具體要怎么修改啊?那個大神幫幫我uj5u.com熱心網友回復:
c++builder,讀寫ini檔案
//包含檔案
#include <inifiles.hpp>
//寫檔案
TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));
ini->WriteInteger("Form","Top",Top);
ini->WriteInteger("Form","Left",Left);
ini->WriteString("Form","Caption",Caption);
ini->WriteBool("Form","InitMax",WindowState==wsMaximized);
delete ini;
//讀檔案
if(FileExists(ExtractFilePath(Application->ExeName)+"config.cfg"))//檢測檔案是否存在
{
TIniFile *ini;
ini=new TIniFile(ChangeFileExt(ExtractFilePath(Application->ExeName),"config.cfg"));
Top=ini->ReadInteger("Form","Top",100);
Left=ini->ReadInteger("Form","Left",100);
Caption =ini->ReadString("Form","Caption","Default Caption");
ini->ReadBool("Form","InitMax",false)?WindowState=wsMaximized:WindowState=wsNormal;
delete ini;
}
else
{
ShowMessage("檔案存在");
}
uj5u.com熱心網友回復:
參考:http://blog.csdn.net/m_buddy/article/details/54097131
http://blog.csdn.net/gsnet/article/details/8614179
uj5u.com熱心網友回復:
同意樓上的,創建一個ini檔案,讀寫ini檔案就可以了uj5u.com熱心網友回復:
經典的用ini,好的串口工具都能講最后一次的設定保存下來供下次初始化uj5u.com熱心網友回復:
有檔案嗎發給我下大哥uj5u.com熱心網友回復:
大哥我也需要這個但是我復制過去的不可以用
uj5u.com熱心網友回復:
大神我也要這個交作業但是不會搞可以幫下嗎
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/34120.html
標籤:茶館
上一篇:C語言程式設計
下一篇:c++開發工具
