课程设计题目:
李刚是一爱折腾的人,当然爱折腾的人均有梦想,他想当中国的盖次呢。可不,现在个人好友信息多了,复杂了,他想制作一个个人通讯录的制作管理软件。 刚好这个学期学了数据结构课,所以他准备使用数据结构知识来实现了。并考虑使用双向链表作数据结构。
课程设计要求:
(1)每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。
(2)作为一个完整的系统,应具有友好的界面和较强的容错能力。
课程设计代码:
//SystemHead.h
#include <stdio.h>
#include <malloc.h>
#include <Windows.h>
#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>
using namespace std;
//SqString.h
//顺序串 头文件
#include "SystemHead.h"//系统头文件
class SqString
{
private:
int Length;
public:
char Data[50];
SqString();//默认初始化
SqString(char ch[]);//用数组ch初始化串s
SqString(SqString &t);//用字符串t初始化串s
~SqString();//释放字符串
void Copy(char* ch);//复制串,将字符数组的每个元素复制到串s中
void Copy(SqString t);//复制串
int GetLength();//长度,获取串s的长度
bool Empty();//判断串s是否为空
void GetString();//从键盘上读取字符串
void Delete(int &i);//删除第i个元素
int Compare(SqString t);//比较大小,串s大返回1,串s小返回-1,相等返回0
bool Equal(SqString s);//相等与否,与字符数组比较
};
/
//默认初始化
SqString::SqString()
{ Length=0;}
//用数组ch初始化串s
SqString::SqString(char *ch)
{ Length=0;
Copy(ch);
}
//拷贝构造函数
SqString::SqString(SqString &t)//用字符串t初始化串s
{
int i;
for(i=0;i<t.Length;i++)
Data[i]=t.Data[i];
Data[i]='\0';
Length=t.Length;
}
//析构
SqString::~SqString()//销毁字符串
{// cout<<"SqString析构"<<endl;
}
//复制串,将字符数组的每个元素复制到串s中
void SqString::Copy(char* ch)
{
int i;
for(i=0;ch[i]!='\0';i++)
Data[i]=ch[i];
Data[i]='\0';
Length=i;
}
void SqString::Copy(SqString t)
{
int i;
for(i=0;i<t.Length;i++)
Data[i]=t.Data[i];
Data[i]='\0';
Length=t.Length;
}
//长度,获取串s的长度
int SqString::GetLength()
{ return Length;}
//判断空
bool SqString::Empty()//判断串s是否为空
{
return Length==0;
}
//读取
void SqString::GetString()//从键盘上读取字符串
{
char ch;
int i;
for(i=0;(ch=getchar())!='\n'&&i<50;i++)
Data[i]=ch;
Data[i]='\0';
Length=i;
}
//判断相等
bool SqString::Equal(SqString s)
{
int i;
if(Length!=s.Length)
return false;//长度不等,则两个串一定不相等
for(i=0;i<Length;i++)
if(Data[i]!=s.Data[i])
return false;
return true;//如果他们对应元素和长度都相等,则这两个串相等
}
//删除
void SqString::Delete(int &i)//删除下标为i个元素,i从0开始计算,i为引用
{//将第i个后面的依次向前移动
int j;
for(j=i;j<Length;j++)
Data[j]=Data[j+1];
//将字符串结束符向前移动移动一个位置
Data[j-1]='\0';
i--;//将传来的参数i也自减一
Length--;//个数减一
}
//SqString.h结束
//AddressBook.h
//通讯录类
#include "SqString.h"//自定义字符串类型
class AddressBook
{
private:
public:
//基本资料
SqString Name;//姓名
SqString Sex;//性别
SqString Age;//年龄
SqString Bir;//生日
SqString Add;//住址
SqString Code;//邮政编码
//联系方式
SqString Cellphone;//移动电话
SqString QQ; //QQ号码
SqString WeChat; //微信号码
//方法
void Display();//输出每一个项目
bool Getin();//输入信息
void Copy(AddressBook temp);//复制
void Format(int n);//格式化输入的信息
};
//复制
void AddressBook::Copy(AddressBook t)
{
Name.Copy(t.Name);
Sex.Copy(t.Sex);
Age.Copy(t.Age);
Bir.Copy(t.Bir);
Add.Copy(t.Add);
Code.Copy(t.Code);
Cellphone.Copy(t.Cellphone);
QQ.Copy(t.QQ);
WeChat.Copy(t.WeChat);
}
//显示
void AddressBook::Display()//AddressBook输出函数
{
//实现如下:
printf("\t●━━━━━━┯━━━━━━┯━━━━━━┯━━━━━━┯━━━━━━●\n");
printf("\t┃ 姓名 ︱ 性别 ︱ 年龄 ︱ 生日 ︱ 住址 ┃\n");
printf("\t┠┄┄┄┄┄┄┼┄┄┄┄┄┄┼┄┄┄┄┄┄┼┄┄┄┄┄┄┼┄┄┄┄┄┄┨\n");
printf("\t┃%-10s ︱%-10s ︱%-10s ︱%-10s ︱%-10s ┃\n",Name.Data,Sex.Data,Age.Data,Bir.Data,Add.Data);
printf("\t┠──────┴──────┴───⊙──┴──────┴──────┨\n");
printf("\t┃ 移动电话:%-10s ︱ 邮政编码:%-10s ┃\n",Cellphone.Data,Code.Data);
printf("\t┠─────────────────⊙────────────────┨\n");
printf("\t┃ QQ号码:%-10s ︱ 微信号码:%-10s ┃\n",QQ.Data,WeChat.Data);
printf("\t●━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━●\n");
}
//输入
bool AddressBook::Getin()
{
cout<<"输入姓名:";
Name.GetString();
cout<<"输入性别:";
Sex.GetString();
cout<<"输入年龄:";
Age.GetString();
cout<<"输入生日:";
Bir.GetString();
cout<<"输入住址:";
Add.GetString();
cout<<"输入邮编:";
Code.GetString();
cout<<"输入手机:";
Cellphone.GetStr