Visual C++数据库编程技术与实例.rar
包含数据库编程的实例代码若干。是学习数据库编程的好资料
C++谭浩强(课件源码正文图片)
C++ 谭浩强版的课件源码正文图片 包括各个章节的。
c++ 控制台实现学生管理
(改进版)使用windows控制台实现的学生管理系统,具有一些实用的功能,主要用来联系和学习编程。
比以前的技术上好一点。
简单的加密程序(采用简单的固定密钥)
设置密码+加密+保存密码
装载密码+解密。
电话簿(c++编写的,初学者可以看一下)
/*************************************************
Copyright (C), 2008- , mekinglong of cumtcs
File name:面向对象8(面向对象8.cpp)
Author: 计07-2 秦杰 Version: 1.00 Date: 08.11.12
Description:编写程序实现一个简单的电话记录簿,要求记录的个人信息包括:
姓名,单位,家庭电话,移动电话。具体功能如下:
1.创建信息链表并以磁盘文件保存。
2.读取磁盘文件并显示输出所有人的移动电话。
3.按姓名或单位查询家庭电话。
4.通过姓名和单位确定个人,修改其电话信息并存盘.
Others: ....
Function List: // 主要函数列表,每条记录应包括函数名及功能简要说明
1.main() 完成各种提示与主操作输入输出
History:
<author> <time> <version > <desc>
*****************************************************/
#include <iostream>
#include <assert.h>
#include <string>
#include <cstring>
#include <fstream>
#include <iomanip>
using namespace std;
class telist;
class Node
{
private:
char name[30];
char workplace[50];
char hometel[50];
char mobiletel[50];
Node *next;
public:
friend class telist;
friend void load(telist&);
};
class telist
{
private:
Node *head;
Node *tail;
public:
telist()
{
head=tail=NULL;
}
telist(Node* h,Node *t):tail(t),head(h){}
void add();
void del();
void show();
Node* search();
void change();
void store();
Node* find1();
Node* find2();
friend void load(telist&);
};
void operate(string ,telist &);
void load(telist &);
int main()
{
system("cls");
cout<<"欢迎使用电话簿管理系统:\n";
telist tele;
load(tele);
string strord;
do
{
cout<<"输入你的操作:\n";
cout<<"1.加入新的电话记录。\n";
cout<<"2.显示输出所有人的移动电话\n";
cout<<"3.按姓名或单位查询家庭电话\n";
cout<<"4.通过姓名和单位确定个人,修改其电话信息并存盘.\n";
cout<<"5.删除一个人信息并存盘。\n";
cout<<"0.退出程序。\n";
cin>>strord;
operate(strord,tele);
system("cls");
}while(strord!="0") ;
system("pause");
system("cls");
return 0;
}
void operate(string str,telist &t)
{
if(str=="1")
t.add();
else if(str=="2")
t.show();
else if(str=="3")
t.search();
else if(str=="4")
t.change();
else if(str=="5")
t.del();
else if(str=="0")
t.store();
else cout<<"输入错误!\n";
system("pause");
}
void load(telist &t)
{
ifstream infile("电话簿.dat",ios::in|ios::binary);
if(infile == NULL)
{
cerr<<"打开电话簿失败!!\n";
t.head=t.tail=NULL;
return;
}
if(!infile.eof())
{
cout<<"没有数据\n";
t.head=t.tail=NULL;
return ;
}
Node *temp=new Node;
t.head=temp;
Node *temp2;
infile.read ((char*)temp,sizeof(Node));
while(!infile.eof()||temp->next==NULL) //
{
temp->next=new Node;
temp2=temp;
temp=temp->next;
infile.read ((char*)temp,sizeof(*temp));
t.tail=temp;
}
temp->next=NULL;
delete(temp);
t.tail=temp2;
t.tail->next=NULL;
// delete temp;
assert(t.tail->next==NULL);
infile.close();
// delete infile;
}
void telist::add()
{
if(head==tail&&tail==NULL)
{
Node * newnode;
newnode=head=tail=new Node;
if(!newnode)
{
cout<<"警告:内存分配失败!\n";
return;
}//if
cout<<"姓名:\n";
cin>>newnode->name;
cout<<"工作单位:\n";
cin>>newnode->workplace;
cout<<"家庭电话:\n";
cin>>newnode->hometel;
cout<<"移动电话:\n";
cin>>newnode->mobiletel;
newnode->next=NULL;
}//if
else{
Node *temp;
temp=new Node;
tail->next = temp;
if(!temp)
{
cout<<"警告:内存分配失败!\n";
return;
}
cout<<"姓名:\n";
cin>>temp->name;
cout<<"工作单位:\n";
cin>>temp->workplace;
cout<<"家庭电话:\n";
cin>>temp->hometel;
cout<<"移动电话:\n";
cin>>temp->mobiletel;
temp->next=NULL;
tail=temp;
}//else
}
void telist::del()
{
cout<<"先确定你要删除的人:\n";
Node *temp=search();
Node *p=head;
if(temp==NULL)
{
cout<<"没找到要找的人!\n";
return ;
}
if(p==temp)
{
cout<<"确定删除?(y或n)";
char ord1;
cin>>ord1;
if(ord1=='N'||ord1=='n') return;
if(ord1=='Y'||ord1=='y')
{
head=head->next;
if(p==tail)
tail=NULL;//wenti zaizheli
}
}
else
{
for(;(p->next)!=temp;)
{
p=p->next;
}
cout<<"确定删除?(y或n)";
char ord;
cin>>ord;
if(ord=='N'||ord=='n')return;
if(ord=='Y'||ord=='y')//if1
{
if(temp==tail)//if2
{
delete temp;
tail=p;
}//if2
else
{
p->next=temp->next;
delete temp;
}//else
}//if1
}//else
store();
}//del
void telist::show()
{
Node *temp=head;
for(;temp!=NULL;)
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
temp=temp->next;
}
return;
}
Node* telist::search()
{
// char sname[30];
// char sworkplace[50];
int ord;
cout<<"按照什么查询?\n";
cout<<"1.名字。\n";
cout<<"2.工作单位。\n";
cin>>ord;
for(;!cin;)
{
cout<<"error!";
cin>>ord;
}
switch(ord)
{
case 1:return(find1());break;
case 2:return(find2());break;
default:cout<<"警告:操作错误!\n";return 0;
}
}
Node* telist::find1()
{
char sn[30];
cout<<"请输入姓名:\n";
cin>>sn;
cout<<endl;
Node *temp=head;
for(;temp;temp=temp->next)
{
if(!strcmp(sn,temp->name))
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
return temp;
}
if(temp->next==NULL)
{
cout<<"NO FIND!\n";
return NULL;
}
else return NULL;
}
}
Node* telist::find2()
{
char sw[50];
cout<<"请输入工作单位:\n";
cin>>sw;
cout<<endl;
Node *temp=head;
for(;temp;temp=temp->next)
{
if(!strcmp(sw,temp->workplace))
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
return temp;
break;
}
if(temp->next==NULL)
{
cout<<"NO FIND!\n";
return NULL;
}
else return NULL;
}
}
void telist::store()
{
Node * temp=head;
ofstream outfile("电话簿.dat",ios::out|ios::binary);
if(!outfile)
{
cout<<"打开文件失败!\n";
return ;
}
for(;temp;)
{
outfile.write ((char *)temp,sizeof(*temp));
temp=temp->next ;
}
outfile.close();
}
void telist::change()
{
Node *temp=search();
cout<<"请输入新的记录:\n";
cout<<"姓名:\n";
cin>>temp->name;
cout<<"工作单位:\n";
cin>>temp->workplace;
cout<<"家庭电话:\n";
cin>>temp->hometel;
cout<<"移动电话:\n";
cin>>temp->mobiletel;
store();
}
电话簿管理(c++编的,适用于初学者)
适用于C++初学者
/*************************************************
Copyright (C), 2008- , mekinglong of cumtcs
File name:面向对象8(面向对象8.cpp)
Author: 计07-2 秦杰 Version: 1.00 Date: 08.11.12
Description:编写程序实现一个简单的电话记录簿,要求记录的个人信息包括:
姓名,单位,家庭电话,移动电话。具体功能如下:
1.创建信息链表并以磁盘文件保存。
2.读取磁盘文件并显示输出所有人的移动电话。
3.按姓名或单位查询家庭电话。
4.通过姓名和单位确定个人,修改其电话信息并存盘.
Others: ....
Function List: // 主要函数列表,每条记录应包括函数名及功能简要说明
1.main() 完成各种提示与主操作输入输出
History:
<author> <time> <version > <desc>
*****************************************************/
#include <iostream>
#include <assert.h>
#include <string>
#include <cstring>
#include <fstream>
#include <iomanip>
using namespace std;
class telist;
class Node
{
private:
char name[30];
char workplace[50];
char hometel[50];
char mobiletel[50];
Node *next;
public:
friend class telist;
friend void load(telist&);
};
class telist
{
private:
Node *head;
Node *tail;
public:
telist()
{
head=tail=NULL;
}
telist(Node* h,Node *t):tail(t),head(h){}
void add();
void del();
void show();
Node* search();
void change();
void store();
Node* find1();
Node* find2();
friend void load(telist&);
};
void operate(string ,telist &);
void load(telist &);
int main()
{
system("cls");
cout<<"欢迎使用电话簿管理系统:\n";
telist tele;
load(tele);
string strord;
do
{
cout<<"输入你的操作:\n";
cout<<"1.加入新的电话记录。\n";
cout<<"2.显示输出所有人的移动电话\n";
cout<<"3.按姓名或单位查询家庭电话\n";
cout<<"4.通过姓名和单位确定个人,修改其电话信息并存盘.\n";
cout<<"5.删除一个人信息并存盘。\n";
cout<<"0.退出程序。\n";
cin>>strord;
operate(strord,tele);
system("cls");
}while(strord!="0") ;
system("pause");
system("cls");
return 0;
}
void operate(string str,telist &t)
{
if(str=="1")
t.add();
else if(str=="2")
t.show();
else if(str=="3")
t.search();
else if(str=="4")
t.change();
else if(str=="5")
t.del();
else if(str=="0")
t.store();
else cout<<"输入错误!\n";
system("pause");
}
void load(telist &t)
{
ifstream infile("电话簿.dat",ios::in|ios::binary);
if(infile == NULL)
{
cerr<<"打开电话簿失败!!\n";
t.head=t.tail=NULL;
return;
}
if(!infile.eof())
{
cout<<"没有数据\n";
t.head=t.tail=NULL;
return ;
}
Node *temp=new Node;
t.head=temp;
Node *temp2;
infile.read ((char*)temp,sizeof(Node));
while(!infile.eof()||temp->next==NULL) //
{
temp->next=new Node;
temp2=temp;
temp=temp->next;
infile.read ((char*)temp,sizeof(*temp));
t.tail=temp;
}
temp->next=NULL;
delete(temp);
t.tail=temp2;
t.tail->next=NULL;
// delete temp;
assert(t.tail->next==NULL);
infile.close();
// delete infile;
}
void telist::add()
{
if(head==tail&&tail==NULL)
{
Node * newnode;
newnode=head=tail=new Node;
if(!newnode)
{
cout<<"警告:内存分配失败!\n";
return;
}//if
cout<<"姓名:\n";
cin>>newnode->name;
cout<<"工作单位:\n";
cin>>newnode->workplace;
cout<<"家庭电话:\n";
cin>>newnode->hometel;
cout<<"移动电话:\n";
cin>>newnode->mobiletel;
newnode->next=NULL;
}//if
else{
Node *temp;
temp=new Node;
tail->next = temp;
if(!temp)
{
cout<<"警告:内存分配失败!\n";
return;
}
cout<<"姓名:\n";
cin>>temp->name;
cout<<"工作单位:\n";
cin>>temp->workplace;
cout<<"家庭电话:\n";
cin>>temp->hometel;
cout<<"移动电话:\n";
cin>>temp->mobiletel;
temp->next=NULL;
tail=temp;
}//else
}
void telist::del()
{
cout<<"先确定你要删除的人:\n";
Node *temp=search();
Node *p=head;
if(temp==NULL)
{
cout<<"没找到要找的人!\n";
return ;
}
if(p==temp)
{
cout<<"确定删除?(y或n)";
char ord1;
cin>>ord1;
if(ord1=='N'||ord1=='n') return;
if(ord1=='Y'||ord1=='y')
{
head=head->next;
if(p==tail)
tail=NULL;//wenti zaizheli
}
}
else
{
for(;(p->next)!=temp;)
{
p=p->next;
}
cout<<"确定删除?(y或n)";
char ord;
cin>>ord;
if(ord=='N'||ord=='n')return;
if(ord=='Y'||ord=='y')//if1
{
if(temp==tail)//if2
{
delete temp;
tail=p;
}//if2
else
{
p->next=temp->next;
delete temp;
}//else
}//if1
}//else
store();
}//del
void telist::show()
{
Node *temp=head;
for(;temp!=NULL;)
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
temp=temp->next;
}
return;
}
Node* telist::search()
{
// char sname[30];
// char sworkplace[50];
int ord;
cout<<"按照什么查询?\n";
cout<<"1.名字。\n";
cout<<"2.工作单位。\n";
cin>>ord;
for(;!cin;)
{
cout<<"error!";
cin>>ord;
}
switch(ord)
{
case 1:return(find1());break;
case 2:return(find2());break;
default:cout<<"警告:操作错误!\n";return 0;
}
}
Node* telist::find1()
{
char sn[30];
cout<<"请输入姓名:\n";
cin>>sn;
cout<<endl;
Node *temp=head;
for(;temp;temp=temp->next)
{
if(!strcmp(sn,temp->name))
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
return temp;
}
if(temp->next==NULL)
{
cout<<"NO FIND!\n";
return NULL;
}
else return NULL;
}
}
Node* telist::find2()
{
char sw[50];
cout<<"请输入工作单位:\n";
cin>>sw;
cout<<endl;
Node *temp=head;
for(;temp;temp=temp->next)
{
if(!strcmp(sw,temp->workplace))
{
cout<<setw(15)<<temp->name<<setw(15)<<temp->workplace;
cout<<setw(15)<<temp->hometel<<setw(15)<<temp->mobiletel<<endl;
return temp;
break;
}
if(temp->next==NULL)
{
cout<<"NO FIND!\n";
return NULL;
}
else return NULL;
}
}
void telist::store()
{
Node * temp=head;
ofstream outfile("电话簿.dat",ios::out|ios::binary);
if(!outfile)
{
cout<<"打开文件失败!\n";
return ;
}
for(;temp;)
{
outfile.write ((char *)temp,sizeof(*temp));
temp=temp->next ;
}
outfile.close();
}
void telist::change()
{
Node *temp=search();
cout<<"请输入新的记录:\n";
cout<<"姓名:\n";
cin>>temp->name;
cout<<"工作单位:\n";
cin>>temp->workplace;
cout<<"家庭电话:\n";
cin>>temp->hometel;
cout<<"移动电话:\n";
cin>>temp->mobiletel;
store();
}